selling items for tokkul now returns the correct amount of tokkul (10x less)

This commit is contained in:
Ryan
2022-05-14 13:23:27 +00:00
parent efbe754654
commit ebc540c7c7
3 changed files with 39 additions and 9 deletions
@@ -196,7 +196,7 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
val price = when(currency) val price = when(currency)
{ {
Items.TOKKUL_6529 -> item.definition.getConfiguration("tokkul_price", 1) Items.TOKKUL_6529 -> (item.definition.getConfiguration("tokkul_price", 1) / 10.0).toInt() // selling items authentically return 10x less tokkul (floored/truncated) than the item's shop price
Items.ARCHERY_TICKET_1464 -> item.definition.getConfiguration("archery_ticket_price", 1) Items.ARCHERY_TICKET_1464 -> item.definition.getConfiguration("archery_ticket_price", 1)
else -> getGPSell(Item(shopItemId, 1), stockAmt, currentAmt) else -> getGPSell(Item(shopItemId, 1), stockAmt, currentAmt)
} }
+26 -3
View File
@@ -16,9 +16,10 @@ class ShopTests {
private val testPlayer = TestUtils.getMockPlayer("test") private val testPlayer = TestUtils.getMockPlayer("test")
private val testIronman = TestUtils.getMockPlayer("test2", IronmanMode.STANDARD) private val testIronman = TestUtils.getMockPlayer("test2", IronmanMode.STANDARD)
var nonGeneral = TestUtils.getMockShop("Not General", false, false, Item(4151, 1)) private var nonGeneral = TestUtils.getMockShop("Not General", false, false, Item(4151, 1))
var general = TestUtils.getMockShop("General", true, false, Item(4151, 1)) private var general = TestUtils.getMockShop("General", true, false, Item(4151, 1))
var highAlch = TestUtils.getMockShop("High(af) Alch", true, true, Item(4151, 1)) private var highAlch = TestUtils.getMockShop("High(af) Alch", true, true, Item(4151, 1))
private var tokkulShop = TestUtils.getMockTokkulShop("Tokkul", Item(Items.DEATH_RUNE_560, 10))
@BeforeEach fun beforeEach() { @BeforeEach fun beforeEach() {
val testPlayers = arrayOf(testPlayer, testIronman) val testPlayers = arrayOf(testPlayer, testIronman)
@@ -29,6 +30,7 @@ class ShopTests {
nonGeneral.playerStock.clear() nonGeneral.playerStock.clear()
general.playerStock.clear() general.playerStock.clear()
highAlch.playerStock.clear() highAlch.playerStock.clear()
tokkulShop.playerStock.clear()
} }
private fun assertTransactionSuccess(status: Shop.TransactionStatus) { private fun assertTransactionSuccess(status: Shop.TransactionStatus) {
@@ -167,6 +169,27 @@ class ShopTests {
) )
} }
@Test fun tokkulShouldBe10xLessValuableWhenSellingAStockedItem() {
val startingTokkul = 5000
testPlayer.inventory.add(Item(Items.TOKKUL_6529, startingTokkul))
testPlayer.setAttribute("shop-cont", tokkulShop.getContainer(testPlayer))
testPlayer.setAttribute("shop-main", true)
var status = tokkulShop.buy(testPlayer, 0, 1) // 1 death rune
assertTransactionSuccess(status)
Assertions.assertEquals(Items.TOKKUL_6529, testPlayer.inventory[0].id, "Pre-assertion: First item should still be the currency used.")
val cost = startingTokkul - testPlayer.inventory[0].amount
status = tokkulShop.sell(testPlayer, 1, 1) // back to starting stock
assertTransactionSuccess(status)
testPlayer.inventory.clear()
testPlayer.inventory.add(Item(Items.DEATH_RUNE_560, 1))
status = tokkulShop.sell(testPlayer, 0, 1) // sell 1 death rune to fresh shop
assertTransactionSuccess(status)
Assertions.assertEquals(Items.TOKKUL_6529, testPlayer.inventory[0].id, "Expected same currency back.")
Assertions.assertEquals((cost / 10.0).toInt(), testPlayer.inventory[0].amount, "Expected 10 times less for selling than for cost of buying.")
}
@Test fun shouldSellUnstockedItemToGeneralStoreAsIronman() { @Test fun shouldSellUnstockedItemToGeneralStoreAsIronman() {
testIronman.inventory.add(Item(1, 1)) testIronman.inventory.add(Item(1, 1))
testIronman.setAttribute("shop-cont", general.getContainer(testIronman)) testIronman.setAttribute("shop-cont", general.getContainer(testIronman))
+9 -2
View File
@@ -7,15 +7,14 @@ import core.game.node.entity.player.link.IronmanMode
import core.game.node.item.Item import core.game.node.item.Item
import core.net.IoSession import core.net.IoSession
import core.net.packet.IoBuffer import core.net.packet.IoBuffer
import org.rs09.consts.Items
import rs09.ServerConstants import rs09.ServerConstants
import rs09.game.content.global.shops.Shop import rs09.game.content.global.shops.Shop
import rs09.game.content.global.shops.ShopItem import rs09.game.content.global.shops.ShopItem
import rs09.game.system.SystemLogger
import rs09.game.system.config.ConfigParser import rs09.game.system.config.ConfigParser
import rs09.game.system.config.ServerConfigParser import rs09.game.system.config.ServerConfigParser
import rs09.game.world.GameWorld import rs09.game.world.GameWorld
import rs09.game.world.repository.Repository import rs09.game.world.repository.Repository
import rs09.plugin.ClassScanner
import java.nio.ByteBuffer import java.nio.ByteBuffer
object TestUtils { object TestUtils {
@@ -36,6 +35,14 @@ object TestUtils {
) )
} }
fun getMockTokkulShop(name: String, vararg stock: Item) : Shop {
return Shop(
name,
stock.map { ShopItem(it.id, it.amount, 100) }.toTypedArray(),
currency = Items.TOKKUL_6529
)
}
fun preTestSetup() { fun preTestSetup() {
if(ServerConstants.DATA_PATH == null) { if(ServerConstants.DATA_PATH == null) {
ServerConfigParser.parse(this::class.java.getResource("test.conf")) ServerConfigParser.parse(this::class.java.getResource("test.conf"))