mirror of
https://gitlab.com/2009scape/2009scape.git
synced 2026-08-01 14:39:13 -06:00
Item sets now appear and can be unpacked at the GE
Added a proper mock session that gets used for mock players in unit tests. Allows verifying that certain packets made it to the IoSession (the stage right before sending it to the client)
This commit is contained in:
parent
6f092d17d8
commit
90060fde21
2 changed files with 58 additions and 12 deletions
|
|
@ -15,12 +15,6 @@ import rs09.game.interaction.InterfaceListener
|
|||
|
||||
class ExchangeItemSets : InterfaceListener {
|
||||
override fun defineInterfaceListeners() {
|
||||
onOpen(Components.EXCHANGE_ITEMSETS_645) { player, _ ->
|
||||
val listener: InventoryListener
|
||||
setAttribute(player, "ge-listener", InventoryListener(player).also { listener = it })
|
||||
player.inventory.listeners.add(listener)
|
||||
}
|
||||
|
||||
onClose(Components.EXCHANGE_ITEMSETS_645){player, _ ->
|
||||
val listener = getAttribute<InventoryListener?>(player, "ge-listener", null)
|
||||
player.inventory.listeners.remove(listener)
|
||||
|
|
@ -37,6 +31,9 @@ class ExchangeItemSets : InterfaceListener {
|
|||
{
|
||||
openInterface(player, Components.EXCHANGE_ITEMSETS_645)
|
||||
player.interfaceManager.openSingleTab(Component(Components.EXCHANGE_SETS_SIDE_644))
|
||||
val listener: InventoryListener
|
||||
setAttribute(player, "ge-listener", InventoryListener(player).also { listener = it })
|
||||
player.inventory.listeners.add(listener)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -62,9 +59,9 @@ class ExchangeItemSets : InterfaceListener {
|
|||
player.inventory.toArray(),
|
||||
arrayOf("Examine", "Exchange", "Components"),
|
||||
Components.EXCHANGE_SETS_SIDE_644,
|
||||
16,
|
||||
15,
|
||||
10
|
||||
0,
|
||||
7,
|
||||
4
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
|||
|
|
@ -1,22 +1,27 @@
|
|||
import core.cache.Cache
|
||||
import core.cache.crypto.ISAACCipher
|
||||
import core.cache.crypto.ISAACPair
|
||||
import core.game.node.entity.player.Player
|
||||
import core.game.node.entity.player.info.PlayerDetails
|
||||
import core.game.node.entity.player.link.IronmanMode
|
||||
import core.game.node.item.Item
|
||||
import core.net.IoSession
|
||||
import core.net.packet.IoBuffer
|
||||
import rs09.ServerConstants
|
||||
import rs09.game.ai.ArtificialSession
|
||||
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.system.config.XteaParser
|
||||
import rs09.game.world.GameWorld
|
||||
import rs09.game.world.repository.Repository
|
||||
import rs09.plugin.ClassScanner
|
||||
import java.nio.ByteBuffer
|
||||
|
||||
object TestUtils {
|
||||
fun getMockPlayer(name: String, ironman: IronmanMode = IronmanMode.NONE): Player {
|
||||
val p = Player(PlayerDetails(name, name))
|
||||
p.details.session = ArtificialSession.getSingleton()
|
||||
p.details.session = MockSession()
|
||||
p.ironmanManager.mode = ironman
|
||||
Repository.addPlayer(p)
|
||||
return p
|
||||
|
|
@ -45,4 +50,48 @@ object TestUtils {
|
|||
GameWorld.majorUpdateWorker.handleTickActions()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class MockSession : IoSession(null, null) {
|
||||
val receivedPackets = ArrayList<Packet>()
|
||||
var disconnected = false
|
||||
|
||||
@Suppress("ArrayInDataClass")
|
||||
data class Packet(val opcode: Int, val payload: ByteArray)
|
||||
|
||||
override fun getRemoteAddress(): String? {
|
||||
return "127.0.0.1"
|
||||
}
|
||||
|
||||
override fun write(context: Any, instant: Boolean) {
|
||||
if(context is IoBuffer) {
|
||||
receivedPackets.add(Packet(context.opcode(), context.array()))
|
||||
}
|
||||
}
|
||||
|
||||
fun hasPacketReady(opcode: Int) : Boolean {
|
||||
for(pkt in receivedPackets) if(pkt.opcode == opcode) return true
|
||||
return false
|
||||
}
|
||||
|
||||
fun getPacketsWithOpcode(opcode: Int) : ArrayList<ByteArray> {
|
||||
val list = ArrayList<ByteArray>()
|
||||
for(pkt in receivedPackets) if(pkt.opcode == opcode) list.add(pkt.payload)
|
||||
return list
|
||||
}
|
||||
|
||||
override fun getIsaacPair(): ISAACPair {
|
||||
return ISAACPair(ISAACCipher(intArrayOf(0)), ISAACCipher(intArrayOf(0)))
|
||||
}
|
||||
|
||||
override fun queue(buffer: ByteBuffer?) {}
|
||||
|
||||
override fun write() {}
|
||||
|
||||
override fun disconnect() {disconnected = true}
|
||||
|
||||
fun clear() {
|
||||
receivedPackets.clear()
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue