Fixed a bug when buying items from shops with a full inventory
This commit is contained in:
@@ -290,6 +290,9 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
|||||||
{
|
{
|
||||||
if(removeItem(player, cost))
|
if(removeItem(player, cost))
|
||||||
{
|
{
|
||||||
|
if (item.amount == 0 && amountInInventory(player, cost.id) == 0) {
|
||||||
|
item.amount = 1
|
||||||
|
}
|
||||||
if(!hasSpaceFor(player, item)) {
|
if(!hasSpaceFor(player, item)) {
|
||||||
addItem(player, cost.id, cost.amount)
|
addItem(player, cost.id, cost.amount)
|
||||||
sendMessage(player, "You don't have enough inventory space to buy that many.")
|
sendMessage(player, "You don't have enough inventory space to buy that many.")
|
||||||
|
|||||||
@@ -340,4 +340,26 @@ class ShopTests {
|
|||||||
Assertions.assertEquals(remainingGP, testPlayer.inventory.getAmount(995), "Coins were deducted for buying 0-stock item!")
|
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!")
|
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))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user