Items with destroy option can no longer be sold to stores
Items that cannot be traded can no longer be sold to stores
This commit is contained in:
@@ -332,6 +332,18 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
|||||||
return TransactionStatus.Failure("Tried to sell currency - ${playerInventory.id}")
|
return TransactionStatus.Failure("Tried to sell currency - ${playerInventory.id}")
|
||||||
}
|
}
|
||||||
val item = Item(playerInventory.id, amount)
|
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)
|
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(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))
|
if(amount > player.inventory.getAmount(item.id))
|
||||||
|
|||||||
@@ -9,6 +9,7 @@ import org.json.simple.JSONArray
|
|||||||
import org.json.simple.JSONObject
|
import org.json.simple.JSONObject
|
||||||
import org.json.simple.parser.JSONParser
|
import org.json.simple.parser.JSONParser
|
||||||
import org.rs09.consts.Components
|
import org.rs09.consts.Components
|
||||||
|
import org.rs09.consts.Items
|
||||||
import org.rs09.consts.NPCs
|
import org.rs09.consts.NPCs
|
||||||
import rs09.ServerConstants
|
import rs09.ServerConstants
|
||||||
import rs09.game.interaction.InteractionListener
|
import rs09.game.interaction.InteractionListener
|
||||||
@@ -216,8 +217,15 @@ class Shops : StartupListener, TickListener, InteractionListener, InterfaceListe
|
|||||||
val shop = getAttribute<Shop?>(player, "shop", null) ?: return@on false
|
val shop = getAttribute<Shop?>(player, "shop", null) ?: return@on false
|
||||||
|
|
||||||
val (_,price) = shop.getSellPrice(player, slot)
|
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)
|
when(opcode)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -45,19 +45,33 @@ class ShopTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shouldNotSellUnstockedItemToStandardStore() {
|
@Test fun shouldNotSellUnstockedItemToStandardStore() {
|
||||||
testPlayer.inventory.add(Item(1, 1))
|
testPlayer.inventory.add(Item(1511, 1))
|
||||||
testPlayer.setAttribute("shop-cont", nonGeneral.getContainer(testPlayer))
|
testPlayer.setAttribute("shop-cont", nonGeneral.getContainer(testPlayer))
|
||||||
val status = nonGeneral.sell(testPlayer, 0, 1)
|
val status = nonGeneral.sell(testPlayer, 0, 1)
|
||||||
Assertions.assertEquals(true, status is Shop.TransactionStatus.Failure)
|
Assertions.assertEquals(true, status is Shop.TransactionStatus.Failure)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shouldSellUnstockedItemToGeneralStore() {
|
@Test fun shouldSellUnstockedItemToGeneralStore() {
|
||||||
testPlayer.inventory.add(Item(1, 1))
|
testPlayer.inventory.add(Item(1511, 1))
|
||||||
testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer))
|
testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer))
|
||||||
val status = general.sell(testPlayer, 0, 1)
|
val status = general.sell(testPlayer, 0, 1)
|
||||||
assertTransactionSuccess(status)
|
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() {
|
@Test fun shouldSellUnstockedItemToGeneralStoreUsingLowAlchBaseValue() {
|
||||||
//starts at 40% value - a.k.a. low alch price
|
//starts at 40% value - a.k.a. low alch price
|
||||||
//drops 3% value per item stocked
|
//drops 3% value per item stocked
|
||||||
@@ -191,14 +205,14 @@ class ShopTests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shouldSellUnstockedItemToGeneralStoreAsIronman() {
|
@Test fun shouldSellUnstockedItemToGeneralStoreAsIronman() {
|
||||||
testIronman.inventory.add(Item(1, 1))
|
testIronman.inventory.add(Item(1511, 1))
|
||||||
testIronman.setAttribute("shop-cont", general.getContainer(testIronman))
|
testIronman.setAttribute("shop-cont", general.getContainer(testIronman))
|
||||||
val status = general.sell(testIronman, 0, 1)
|
val status = general.sell(testIronman, 0, 1)
|
||||||
assertTransactionSuccess(status)
|
assertTransactionSuccess(status)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test fun shouldSellStackOfUnstockedItemsToPlayerStock() {
|
@Test fun shouldSellStackOfUnstockedItemsToPlayerStock() {
|
||||||
testPlayer.inventory.add(Item(1, 20))
|
testPlayer.inventory.add(Item(1512, 20))
|
||||||
testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer))
|
testPlayer.setAttribute("shop-cont", general.getContainer(testPlayer))
|
||||||
val status = general.sell(testPlayer, 0, 20)
|
val status = general.sell(testPlayer, 0, 20)
|
||||||
assertTransactionSuccess(status)
|
assertTransactionSuccess(status)
|
||||||
|
|||||||
Reference in New Issue
Block a user