Implemented blast furnace ore shop
This commit is contained in:
@@ -1891,12 +1891,13 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"npcs": "2564",
|
"npcs": "2564",
|
||||||
|
"force_shared": "true",
|
||||||
"high_alch": "0",
|
"high_alch": "0",
|
||||||
"currency": "995",
|
"currency": "995",
|
||||||
"general_store": "false",
|
"general_store": "false",
|
||||||
"id": "222",
|
"id": "222",
|
||||||
"title": "Ore Shop\b",
|
"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",
|
"npcs": "603",
|
||||||
|
|||||||
@@ -2,52 +2,57 @@ package content.minigame.blastfurnace
|
|||||||
|
|
||||||
import core.api.*
|
import core.api.*
|
||||||
import core.game.node.entity.Entity
|
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.ZoneBorders
|
||||||
import core.game.world.map.zone.ZoneBuilder
|
import core.tools.secondsToTicks
|
||||||
import core.plugin.Initializable
|
import org.rs09.consts.NPCs
|
||||||
import core.plugin.Plugin
|
import kotlin.math.min
|
||||||
|
|
||||||
/**Code for defining the Blast Furnace zone, Blast Furnace will only
|
/**Code for defining the Blast Furnace zone, Blast Furnace will only
|
||||||
* operate and run its logic if there are actual players in this zone
|
* operate and run its logic if there are actual players in this zone
|
||||||
* @author phil lips*/
|
* @author phil lips, ceikry*/
|
||||||
|
|
||||||
|
|
||||||
//Remove this once the funny dupe gets fixed
|
|
||||||
@Initializable
|
|
||||||
class BlastFurnaceZone : MapZone("Blast Furnace Zone",true), Plugin<Any> {
|
|
||||||
|
|
||||||
|
class BlastFurnaceZone : MapArea, TickListener {
|
||||||
var pulseStarted = false
|
var pulseStarted = false
|
||||||
|
var lastShopRestock = 0
|
||||||
|
|
||||||
override fun newInstance(arg: Any?): Plugin<Any> {
|
override fun defineAreaBorders(): Array<ZoneBorders> {
|
||||||
ZoneBuilder.configure(this)
|
return arrayOf(ZoneBorders(1935,4956,1956,4974))
|
||||||
return this
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fireEvent(identifier: String?, vararg args: Any?): Any {
|
override fun areaEnter(entity: Entity) {
|
||||||
return Unit
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun configure() {
|
|
||||||
super.register(ZoneBorders(1935,4956,1956,4974))
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun enter(e: Entity?): Boolean {
|
|
||||||
if (!pulseStarted){
|
if (!pulseStarted){
|
||||||
submitWorldPulse(BlastFurnace.blastPulse)
|
submitWorldPulse(BlastFurnace.blastPulse)
|
||||||
pulseStarted = true
|
pulseStarted = true
|
||||||
}
|
}
|
||||||
if (e != null && e.isPlayer) {
|
if (entity.isPlayer) {
|
||||||
BlastFurnace.blastFurnacePlayerList.add(e.asPlayer())
|
BlastFurnace.blastFurnacePlayerList.add(entity.asPlayer())
|
||||||
}
|
}
|
||||||
return super.enter(e)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun leave(e: Entity?, logout: Boolean): Boolean {
|
override fun areaLeave(entity: Entity, logout: Boolean) {
|
||||||
if (e != null && e.isPlayer) {
|
if (entity.isPlayer) {
|
||||||
BlastFurnace.blastFurnacePlayerList.remove(e.asPlayer())
|
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))
|
||||||
|
)
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -37,7 +37,7 @@ class ShopListener(val player: Player) : ContainerListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean = false, val currency: Int = Items.COINS_995, val highAlch: Boolean = false)
|
class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean = false, val currency: Int = Items.COINS_995, val highAlch: Boolean = false, val forceShared: Boolean = false)
|
||||||
{
|
{
|
||||||
val stockInstances = HashMap<Int, Container>()
|
val stockInstances = HashMap<Int, Container>()
|
||||||
val playerStock = if (general) generalPlayerStock else Container(40, ContainerType.SHOP)
|
val playerStock = if (general) generalPlayerStock else Container(40, ContainerType.SHOP)
|
||||||
@@ -45,7 +45,7 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
|||||||
val restockRates = HashMap<Int,Int>()
|
val restockRates = HashMap<Int,Int>()
|
||||||
|
|
||||||
init {
|
init {
|
||||||
if(!getServerConfig().getBoolean(Shops.personalizedShops, false))
|
if(!getServerConfig().getBoolean(Shops.personalizedShops, false) || forceShared)
|
||||||
stockInstances[ServerConstants.SERVER_NAME.hashCode()] = generateStockContainer()
|
stockInstances[ServerConstants.SERVER_NAME.hashCode()] = generateStockContainer()
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,10 +97,10 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
|||||||
|
|
||||||
public fun getContainer(player: Player) : Container
|
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 }
|
stockInstances[player.details.uid] ?: generateStockContainer().also { stockInstances[player.details.uid] = it }
|
||||||
else
|
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]
|
val listener = listenerInstances[player.details.uid]
|
||||||
|
|
||||||
@@ -135,6 +135,7 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
|||||||
{
|
{
|
||||||
if(cont[i] == null) continue
|
if(cont[i] == null) continue
|
||||||
if(stock.size < i + 1) break
|
if(stock.size < i + 1) break
|
||||||
|
if(stock[i].restockRate == 0) continue
|
||||||
if(GameWorld.ticks % stock[i].restockRate != 0) continue
|
if(GameWorld.ticks % stock[i].restockRate != 0) continue
|
||||||
|
|
||||||
if(cont[i].amount < stock[i].amount){
|
if(cont[i].amount < stock[i].amount){
|
||||||
|
|||||||
@@ -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 npcs = if(shopData["npcs"].toString().isNotBlank()) shopData["npcs"].toString().split(",").map { it.toInt() }.toIntArray() else intArrayOf()
|
||||||
val currency = shopData["currency"].toString().toInt()
|
val currency = shopData["currency"].toString().toInt()
|
||||||
val highAlch = shopData["high_alch"].toString() == "1"
|
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 }
|
npcs.map { shopsByNpc[it] = shop }
|
||||||
shopsById[id] = shop
|
shopsById[id] = shop
|
||||||
|
|||||||
Reference in New Issue
Block a user