From 39251fc75f8ea7f9b1ef9c8a077585ecfdea7bc5 Mon Sep 17 00:00:00 2001 From: Ceikry Date: Sun, 12 Feb 2023 01:08:34 +0000 Subject: [PATCH] Implemented blast furnace ore shop --- Server/data/configs/shops.json | 3 +- .../minigame/blastfurnace/BlastFurnaceZone.kt | 63 ++++++++++--------- Server/src/main/core/game/shops/Shop.kt | 9 +-- Server/src/main/core/game/shops/Shops.kt | 3 +- 4 files changed, 43 insertions(+), 35 deletions(-) diff --git a/Server/data/configs/shops.json b/Server/data/configs/shops.json index 39f14cafa..884d0d281 100644 --- a/Server/data/configs/shops.json +++ b/Server/data/configs/shops.json @@ -1891,12 +1891,13 @@ }, { "npcs": "2564", + "force_shared": "true", "high_alch": "0", "currency": "995", "general_store": "false", "id": "222", "title": "Ore Shop\b", - "stock": "{436,1500,100}-{438,1500,100}-{440,1500,100}-{442,1500,100}-{444,1500,100}-{447,1500,100}-{453,1500,100}" + "stock": "{436,0,0}-{438,0,0}-{440,0,0}-{442,0,0}-{444,0,0}-{447,0,0}-{453,0,0}" }, { "npcs": "603", diff --git a/Server/src/main/content/minigame/blastfurnace/BlastFurnaceZone.kt b/Server/src/main/content/minigame/blastfurnace/BlastFurnaceZone.kt index 52e8b512d..2a2c75b0a 100644 --- a/Server/src/main/content/minigame/blastfurnace/BlastFurnaceZone.kt +++ b/Server/src/main/content/minigame/blastfurnace/BlastFurnaceZone.kt @@ -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 { + * @author phil lips, ceikry*/ +class BlastFurnaceZone : MapArea, TickListener { var pulseStarted = false + var lastShopRestock = 0 - override fun newInstance(arg: Any?): Plugin { - ZoneBuilder.configure(this) - return this + override fun defineAreaBorders(): Array { + 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)) + ) + ) + } } \ No newline at end of file diff --git a/Server/src/main/core/game/shops/Shop.kt b/Server/src/main/core/game/shops/Shop.kt index 01ef3f6f3..f5eb7f710 100644 --- a/Server/src/main/core/game/shops/Shop.kt +++ b/Server/src/main/core/game/shops/Shop.kt @@ -37,7 +37,7 @@ class ShopListener(val player: Player) : ContainerListener } } -class Shop(val title: String, val stock: Array, val general: Boolean = false, val currency: Int = Items.COINS_995, val highAlch: Boolean = false) +class Shop(val title: String, val stock: Array, val general: Boolean = false, val currency: Int = Items.COINS_995, val highAlch: Boolean = false, val forceShared: Boolean = false) { val stockInstances = HashMap() val playerStock = if (general) generalPlayerStock else Container(40, ContainerType.SHOP) @@ -45,7 +45,7 @@ class Shop(val title: String, val stock: Array, val general: Boolean = val restockRates = HashMap() init { - if(!getServerConfig().getBoolean(Shops.personalizedShops, false)) + if(!getServerConfig().getBoolean(Shops.personalizedShops, false) || forceShared) stockInstances[ServerConstants.SERVER_NAME.hashCode()] = generateStockContainer() } @@ -97,10 +97,10 @@ class Shop(val title: String, val stock: Array, val general: Boolean = public fun getContainer(player: Player) : Container { - val container = if(getServerConfig().getBoolean(Shops.personalizedShops, false)) + val container = if(getServerConfig().getBoolean(Shops.personalizedShops, false) && !forceShared) stockInstances[player.details.uid] ?: generateStockContainer().also { stockInstances[player.details.uid] = it } else - stockInstances[ServerConstants.SERVER_NAME.hashCode()]!! + stockInstances[ServerConstants.SERVER_NAME.hashCode()] ?: generateStockContainer().also { stockInstances[ServerConstants.SERVER_NAME.hashCode()] = it } val listener = listenerInstances[player.details.uid] @@ -135,6 +135,7 @@ class Shop(val title: String, val stock: Array, val general: Boolean = { if(cont[i] == null) continue if(stock.size < i + 1) break + if(stock[i].restockRate == 0) continue if(GameWorld.ticks % stock[i].restockRate != 0) continue if(cont[i].amount < stock[i].amount){ diff --git a/Server/src/main/core/game/shops/Shops.kt b/Server/src/main/core/game/shops/Shops.kt index 0bf521d2a..1e2e3af62 100644 --- a/Server/src/main/core/game/shops/Shops.kt +++ b/Server/src/main/core/game/shops/Shops.kt @@ -90,7 +90,8 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe val npcs = if(shopData["npcs"].toString().isNotBlank()) shopData["npcs"].toString().split(",").map { it.toInt() }.toIntArray() else intArrayOf() val currency = shopData["currency"].toString().toInt() val highAlch = shopData["high_alch"].toString() == "1" - shop = Shop(title, stock, general, currency, highAlch) + val forceShared = shopData.getOrDefault("force_shared", "false").toString().toBoolean() + shop = Shop(title, stock, general, currency, highAlch, forceShared) npcs.map { shopsByNpc[it] = shop } shopsById[id] = shop