Fixed an exception thrown when buying from player stock
Fix issue where malformed stock could shift following shop items
This commit is contained in:
@@ -246,13 +246,13 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
||||
sendDialogue(player, "As an ironman, you cannot buy from player stock in shops.")
|
||||
return TransactionStatus.Failure("Ironman buying from player stock")
|
||||
}
|
||||
val cont = if (isMainStock) getAttribute<Container?>(player, "shop-cont", null) ?: return TransactionStatus.Failure("Invalid shop-cont attr") else playerStock
|
||||
val cont = if (isMainStock) (getAttribute<Container?>(player, "shop-cont", null) ?: return TransactionStatus.Failure("Invalid shop-cont attr")) else playerStock
|
||||
val inStock = cont[slot]
|
||||
val item = Item(inStock.id, amount)
|
||||
if(inStock.amount < amount)
|
||||
item.amount = inStock.amount
|
||||
|
||||
if(inStock.amount > stock[slot].amount && !getServerConfig().getBoolean(Shops.personalizedShops, false) && player.ironmanManager.isIronman)
|
||||
if(isMainStock && inStock.amount > stock[slot].amount && !getServerConfig().getBoolean(Shops.personalizedShops, false) && player.ironmanManager.isIronman)
|
||||
{
|
||||
sendDialogue(player, "As an ironman, you cannot buy overstocked items from shops.")
|
||||
return TransactionStatus.Failure("Ironman overstock purchase")
|
||||
|
||||
@@ -41,15 +41,6 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe
|
||||
{
|
||||
SystemLogger.logInfo("[SHOPS] $msg")
|
||||
}
|
||||
}
|
||||
|
||||
override fun startup() {
|
||||
val path = ServerConstants.CONFIG_PATH + "shops.json"
|
||||
var shopCount = 0
|
||||
logShop("Using JSON path: $path")
|
||||
|
||||
val reader = FileReader(path)
|
||||
val data = JSONParser().parse(reader) as JSONArray
|
||||
|
||||
fun parseStock(stock: String, id: Int): ArrayList<ShopItem>{
|
||||
val items = ArrayList<ShopItem>()
|
||||
@@ -63,13 +54,28 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe
|
||||
if(amount == "inf")
|
||||
amount = "-1"
|
||||
val item = tokens[0].toInt()
|
||||
if(idsInStock[item] != null)
|
||||
if(idsInStock[item] != null) {
|
||||
SystemLogger.logWarn("[SHOPS] MALFORMED STOCK IN SHOP ID $id FOR ITEM $item")
|
||||
else
|
||||
items.forEach { if(it.itemId == item) {
|
||||
it.amount += amount.toInt()
|
||||
return@map
|
||||
}}
|
||||
} else {
|
||||
items.add(ShopItem(item, amount.toInt(), tokens.getOrNull(2)?.toIntOrNull() ?: 100))
|
||||
idsInStock[item] = true
|
||||
}
|
||||
}
|
||||
return items
|
||||
}
|
||||
}
|
||||
|
||||
override fun startup() {
|
||||
val path = ServerConstants.CONFIG_PATH + "shops.json"
|
||||
var shopCount = 0
|
||||
logShop("Using JSON path: $path")
|
||||
|
||||
val reader = FileReader(path)
|
||||
val data = JSONParser().parse(reader) as JSONArray
|
||||
|
||||
for(rawShop in data)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user