Fixed a bug when buying items from shops with a full inventory

This commit is contained in:
Ceikry
2022-12-20 08:40:59 +00:00
committed by Ryan
parent 7750471015
commit b387e993bb
2 changed files with 25 additions and 0 deletions
@@ -290,6 +290,9 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
{
if(removeItem(player, cost))
{
if (item.amount == 0 && amountInInventory(player, cost.id) == 0) {
item.amount = 1
}
if(!hasSpaceFor(player, item)) {
addItem(player, cost.id, cost.amount)
sendMessage(player, "You don't have enough inventory space to buy that many.")
+22
View File
@@ -340,4 +340,26 @@ class ShopTests {
Assertions.assertEquals(remainingGP, testPlayer.inventory.getAmount(995), "Coins were deducted for buying 0-stock item!")
Assertions.assertNull(testPlayer.inventory.get(1), "Player received purchased item despite being 0-stock!")
}
@Test fun buyingItemWithOtherwiseFullInventoryStillBuysTheItemAndTakesTheCoins() {
testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer))
testPlayer.setAttribute("shop-main", false)
testPlayer.inventory.clear()
testPlayer.inventory.add(Item(Items.ABYSSAL_WHIP_4151, 27)) //fill 27 slots
general.playerStock.add(Item(992, 1))
var slot = general.getStockSlot(992).second
var price = general.getBuyPrice(testPlayer, slot)
testPlayer.inventory.add(price)
//Buy out existing stock
var status: Shop.TransactionStatus = Shop.TransactionStatus.Success()
Assertions.assertDoesNotThrow {
status = general.buy(testPlayer, slot, 1)
}
Assertions.assertEquals(true, status is Shop.TransactionStatus.Success)
Assertions.assertEquals(0, testPlayer.inventory.getAmount(995))
Assertions.assertEquals(1, testPlayer.inventory.getAmount(992))
}
}