From 374d6ec478c41d944a531d479ae217fb8d4c0d07 Mon Sep 17 00:00:00 2001 From: vddcore <573729-vddcore@users.noreply.gitlab.com> Date: Sat, 9 Jul 2022 08:51:48 +0000 Subject: [PATCH] Items with destroy option can no longer be sold to stores Items that cannot be traded can no longer be sold to stores --- .../rs09/game/content/global/shops/Shop.kt | 12 ++++++++++ .../rs09/game/content/global/shops/Shops.kt | 10 ++++++++- Server/src/test/kotlin/ShopTests.kt | 22 +++++++++++++++---- 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/Server/src/main/kotlin/rs09/game/content/global/shops/Shop.kt b/Server/src/main/kotlin/rs09/game/content/global/shops/Shop.kt index b17e7ca78..760be0907 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/shops/Shop.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/shops/Shop.kt @@ -332,6 +332,18 @@ class Shop(val title: String, val stock: Array, val general: Boolean = return TransactionStatus.Failure("Tried to sell currency - ${playerInventory.id}") } val item = Item(playerInventory.id, amount) + val def = itemDefinition(item.id) + + if (def.hasDestroyAction()) { + sendMessage(player, "You can't sell this item.") + return TransactionStatus.Failure("Attempt to sell a destroyable - ${playerInventory.id}.") + } + + if (!def.isTradeable) { + sendMessage(player, "You can't sell this item.") + return TransactionStatus.Failure("Attempt to sell an untradeable - ${playerInventory.id}.") + } + val (container,profit) = getSellPrice(player, slot) if(profit.amount == -1) sendMessage(player, "This item can't be sold to this shop.").also { return TransactionStatus.Failure("Can't sell this item to this shop - ${playerInventory.id}, general: $general, price: $profit") } if(amount > player.inventory.getAmount(item.id)) diff --git a/Server/src/main/kotlin/rs09/game/content/global/shops/Shops.kt b/Server/src/main/kotlin/rs09/game/content/global/shops/Shops.kt index 337198163..4fee8fc9a 100644 --- a/Server/src/main/kotlin/rs09/game/content/global/shops/Shops.kt +++ b/Server/src/main/kotlin/rs09/game/content/global/shops/Shops.kt @@ -9,6 +9,7 @@ import org.json.simple.JSONArray import org.json.simple.JSONObject import org.json.simple.parser.JSONParser import org.rs09.consts.Components +import org.rs09.consts.Items import org.rs09.consts.NPCs import rs09.ServerConstants import rs09.game.interaction.InteractionListener @@ -216,8 +217,15 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe val shop = getAttribute(player, "shop", null) ?: return@on false val (_,price) = shop.getSellPrice(player, slot) + val def = itemDefinition(player.inventory[slot].id) - val valueMsg = if(price.amount == -1) "This shop will not buy that item." else "${player.inventory[slot].name}: This shop will buy this item for ${price.amount} ${price.name.toLowerCase()}." + val valueMsg = when { + (price.amount == -1) + || !def.isTradeable + || def.id in intArrayOf(Items.COINS_995, Items.TOKKUL_6529, Items.ARCHERY_TICKET_1464) + || def.hasDestroyAction() -> "This shop will not buy that item." + else -> "${player.inventory[slot].name}: This shop will buy this item for ${price.amount} ${price.name.lowercase()}." + } when(opcode) { diff --git a/Server/src/test/kotlin/ShopTests.kt b/Server/src/test/kotlin/ShopTests.kt index 4e6470f7b..7ce228f22 100644 --- a/Server/src/test/kotlin/ShopTests.kt +++ b/Server/src/test/kotlin/ShopTests.kt @@ -45,19 +45,33 @@ class ShopTests { } @Test fun shouldNotSellUnstockedItemToStandardStore() { - testPlayer.inventory.add(Item(1, 1)) + testPlayer.inventory.add(Item(1511, 1)) testPlayer.setAttribute("shop-cont", nonGeneral.getContainer(testPlayer)) val status = nonGeneral.sell(testPlayer, 0, 1) Assertions.assertEquals(true, status is Shop.TransactionStatus.Failure) } @Test fun shouldSellUnstockedItemToGeneralStore() { - testPlayer.inventory.add(Item(1, 1)) + testPlayer.inventory.add(Item(1511, 1)) testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer)) val status = general.sell(testPlayer, 0, 1) assertTransactionSuccess(status) } + @Test fun shouldNotSellDestroyable() { + testPlayer.inventory.add(Item(1, 795)) + testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer)) + val status = general.sell(testPlayer, 0, 1) + Assertions.assertEquals(true, status is Shop.TransactionStatus.Failure) + } + + @Test fun shouldNotSellUntradeable() { + testPlayer.inventory.add(Item(1, 1799)) + testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer)) + val status = general.sell(testPlayer, 0, 1) + Assertions.assertEquals(true, status is Shop.TransactionStatus.Failure) + } + @Test fun shouldSellUnstockedItemToGeneralStoreUsingLowAlchBaseValue() { //starts at 40% value - a.k.a. low alch price //drops 3% value per item stocked @@ -191,14 +205,14 @@ class ShopTests { } @Test fun shouldSellUnstockedItemToGeneralStoreAsIronman() { - testIronman.inventory.add(Item(1, 1)) + testIronman.inventory.add(Item(1511, 1)) testIronman.setAttribute("shop-cont", general.getContainer(testIronman)) val status = general.sell(testIronman, 0, 1) assertTransactionSuccess(status) } @Test fun shouldSellStackOfUnstockedItemsToPlayerStock() { - testPlayer.inventory.add(Item(1, 20)) + testPlayer.inventory.add(Item(1512, 20)) testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer)) val status = general.sell(testPlayer, 0, 20) assertTransactionSuccess(status)