Completely rewrote the shop system.

Shop restocking now works properly, with per-item-in-shop granularity as well. (Thanos tool update released that allows defining this)
Shops properly restrict ironmen from buying from player stock/overstocked items
Fully functioning individualized player stock support (need to set a server config variable to enable, disabled by default. Specifically, set personalized_shops = true in the world section of the config.)
The shop pricing formula now scales up/down with the authentic ratios based on stock quantity.
Buying or selling, for example, 1000 of an item, now does the proper calculation for each individual item in the purchase/sale rather than exchanging the full 1000 for the initial price at the time. (For example, in the old shops, feather price at full stock was, say, 6gp. You could buy 1000 feathers at once for 6000gp. Authentically, the pricing for each feather should scale as the stock goes down. Now 1000 feathers at once costs a bit over 7k gp, despite the initial price remaining 6gp.)
General store player stock is now shared between all general stores
This commit is contained in:
Ceikry
2022-04-12 08:46:21 +00:00
committed by Ryan
parent f9aea18497
commit e958b8d255
202 changed files with 1910 additions and 2385 deletions
@@ -1,6 +1,5 @@
package rs09.game.system.config
import core.game.content.global.shop.Shop
import core.game.node.entity.player.Player
import core.game.node.item.Item
import org.json.simple.JSONArray
@@ -14,12 +13,12 @@ class ShopParser{
val parser = JSONParser()
var reader: FileReader? = null
companion object{
val SHOPS = HashMap<Int, Shop>()
val UID_SHOPS = HashMap<Int,Shop>()
companion object {
/* val SHOPS = HashMap<Int, Shop>()
val UID_SHOPS = HashMap<Int,Shop>()*/
fun openUid(player: Player,uid: Int): Boolean {
val shop = UID_SHOPS[uid] ?: return false;
shop.open(player);
/* val shop = UID_SHOPS[uid] ?: return false;
shop.open(player);*/
return true;
}
}
@@ -29,42 +28,9 @@ class ShopParser{
reader = FileReader(ServerConstants.CONFIG_PATH + "shops.json")
val configlist = parser.parse(reader) as JSONArray
for(config in configlist){
var shop: Shop?
val e = config as JSONObject
val id = e["id"].toString().toInt()
val title = e["title"].toString()
val general = e["general_store"].toString().toBoolean()
val stock = parseStock(e["stock"].toString()).toTypedArray()
val npcs = if(e["npcs"].toString().isNotBlank()) e["npcs"].toString().split(",").map { it.toInt() }.toIntArray() else intArrayOf()
val currency = e["currency"].toString().toInt()
val highAlch = e["high_alch"].toString() == "1"
if(general && stock.isEmpty()){
shop = Shop(title,true,currency,highAlch)
} else {
shop = Shop(title, stock, general, currency, highAlch)
}
if(npcs.isNotEmpty()){
npcs.map { SHOPS[it] = shop }
} else {
UID_SHOPS[id] = shop
}
count++
}
SystemLogger.logInfo("Parsed $count shops.")
}
fun parseStock(stock: String): ArrayList<Item>{
val items = ArrayList<Item>()
if(stock.isEmpty()){
return items
}
stock.split('-').map {
val tokens = it.replace("{", "").replace("}", "").split(",".toRegex()).toTypedArray()
var amount = tokens[1].trim()
if(amount == "inf")
amount = "-1"
items.add(Item(tokens[0].trim().toInt(),amount.toInt()))
}
return items
}
}