Implemented blast furnace ore shop

This commit is contained in:
Ceikry
2023-02-12 01:08:34 +00:00
committed by Ryan
parent 69f950eb57
commit 39251fc75f
4 changed files with 43 additions and 35 deletions
@@ -2,52 +2,57 @@ package content.minigame.blastfurnace
import core.api.*
import core.game.node.entity.Entity
import core.game.world.map.zone.MapZone
import core.game.node.item.Item
import core.game.shops.Shops
import core.game.world.map.zone.ZoneBorders
import core.game.world.map.zone.ZoneBuilder
import core.plugin.Initializable
import core.plugin.Plugin
import core.tools.secondsToTicks
import org.rs09.consts.NPCs
import kotlin.math.min
/**Code for defining the Blast Furnace zone, Blast Furnace will only
* operate and run its logic if there are actual players in this zone
* @author phil lips*/
//Remove this once the funny dupe gets fixed
@Initializable
class BlastFurnaceZone : MapZone("Blast Furnace Zone",true), Plugin<Any> {
* @author phil lips, ceikry*/
class BlastFurnaceZone : MapArea, TickListener {
var pulseStarted = false
var lastShopRestock = 0
override fun newInstance(arg: Any?): Plugin<Any> {
ZoneBuilder.configure(this)
return this
override fun defineAreaBorders(): Array<ZoneBorders> {
return arrayOf(ZoneBorders(1935,4956,1956,4974))
}
override fun fireEvent(identifier: String?, vararg args: Any?): Any {
return Unit
}
override fun configure() {
super.register(ZoneBorders(1935,4956,1956,4974))
}
override fun enter(e: Entity?): Boolean {
override fun areaEnter(entity: Entity) {
if (!pulseStarted){
submitWorldPulse(BlastFurnace.blastPulse)
pulseStarted = true
}
if (e != null && e.isPlayer) {
BlastFurnace.blastFurnacePlayerList.add(e.asPlayer())
if (entity.isPlayer) {
BlastFurnace.blastFurnacePlayerList.add(entity.asPlayer())
}
return super.enter(e)
}
override fun leave(e: Entity?, logout: Boolean): Boolean {
if (e != null && e.isPlayer) {
BlastFurnace.blastFurnacePlayerList.remove(e.asPlayer())
override fun areaLeave(entity: Entity, logout: Boolean) {
if (entity.isPlayer) {
BlastFurnace.blastFurnacePlayerList.remove(entity.asPlayer())
}
return super.leave(e, logout)
}
override fun tick() {
if (getWorldTicks() - lastShopRestock > secondsToTicks(600)) {
lastShopRestock = getWorldTicks()
restockRandomOre()
}
}
private fun restockRandomOre() {
val shop = Shops.shopsByNpc[NPCs.ORDAN_2564] ?: return
val stockContainer = shop.stockInstances.values.firstOrNull() ?: return
val restockThisTick = shop.stock.random()
stockContainer.add(
Item(
restockThisTick.itemId,
min(30, 100 - stockContainer.getAmount(restockThisTick.itemId))
)
)
}
}