mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2025-12-10 10:20:41 -07:00
selling items for tokkul now returns the correct amount of tokkul (10x less)
This commit is contained in:
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)
|
||||
{
|
||||
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)
|
||||
else -> getGPSell(Item(shopItemId, 1), stockAmt, currentAmt)
|
||||
}
|
||||
|
|
@ -412,4 +412,4 @@ class Shop(val title: String, val stock: Array<ShopItem>, val general: Boolean =
|
|||
class Success : TransactionStatus()
|
||||
class Failure(val reason: String) : TransactionStatus()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,9 +16,10 @@ class ShopTests {
|
|||
|
||||
private val testPlayer = TestUtils.getMockPlayer("test")
|
||||
private val testIronman = TestUtils.getMockPlayer("test2", IronmanMode.STANDARD)
|
||||
var nonGeneral = TestUtils.getMockShop("Not General", false, false, Item(4151, 1))
|
||||
var general = TestUtils.getMockShop("General", true, false, Item(4151, 1))
|
||||
var highAlch = TestUtils.getMockShop("High(af) Alch", true, true, Item(4151, 1))
|
||||
private var nonGeneral = TestUtils.getMockShop("Not General", false, false, Item(4151, 1))
|
||||
private var general = TestUtils.getMockShop("General", true, false, 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() {
|
||||
val testPlayers = arrayOf(testPlayer, testIronman)
|
||||
|
|
@ -29,6 +30,7 @@ class ShopTests {
|
|||
nonGeneral.playerStock.clear()
|
||||
general.playerStock.clear()
|
||||
highAlch.playerStock.clear()
|
||||
tokkulShop.playerStock.clear()
|
||||
}
|
||||
|
||||
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() {
|
||||
testIronman.inventory.add(Item(1, 1))
|
||||
testIronman.setAttribute("shop-cont", general.getContainer(testIronman))
|
||||
|
|
@ -303,4 +326,4 @@ 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!")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,15 +7,14 @@ import core.game.node.entity.player.link.IronmanMode
|
|||
import core.game.node.item.Item
|
||||
import core.net.IoSession
|
||||
import core.net.packet.IoBuffer
|
||||
import org.rs09.consts.Items
|
||||
import rs09.ServerConstants
|
||||
import rs09.game.content.global.shops.Shop
|
||||
import rs09.game.content.global.shops.ShopItem
|
||||
import rs09.game.system.SystemLogger
|
||||
import rs09.game.system.config.ConfigParser
|
||||
import rs09.game.system.config.ServerConfigParser
|
||||
import rs09.game.world.GameWorld
|
||||
import rs09.game.world.repository.Repository
|
||||
import rs09.plugin.ClassScanner
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
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() {
|
||||
if(ServerConstants.DATA_PATH == null) {
|
||||
ServerConfigParser.parse(this::class.java.getResource("test.conf"))
|
||||
|
|
@ -94,4 +101,4 @@ class MockSession : IoSession(null, null) {
|
|||
receivedPackets.clear()
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue