Skip to content

Commit

Permalink
feat: opnpc* packets
Browse files Browse the repository at this point in the history
  • Loading branch information
Z-Kris committed Apr 4, 2024
1 parent b616f83 commit 7c15524
Show file tree
Hide file tree
Showing 10 changed files with 323 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpcEvent
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder

public class OpNpc1Decoder : MessageDecoder<OpNpcEvent> {
override val prot: ClientProt = GameClientProt.OPNPC1

override fun decode(buffer: JagByteBuf): OpNpcEvent {
val index = buffer.g2Alt2()
val controlKey = buffer.g1Alt3() == 1
return OpNpcEvent(
index,
controlKey,
1,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpcEvent
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder

public class OpNpc2Decoder : MessageDecoder<OpNpcEvent> {
override val prot: ClientProt = GameClientProt.OPNPC2

override fun decode(buffer: JagByteBuf): OpNpcEvent {
val controlKey = buffer.g1() == 1
val index = buffer.g2Alt2()
return OpNpcEvent(
index,
controlKey,
2,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpcEvent
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder

public class OpNpc3Decoder : MessageDecoder<OpNpcEvent> {
override val prot: ClientProt = GameClientProt.OPNPC3

override fun decode(buffer: JagByteBuf): OpNpcEvent {
val index = buffer.g2Alt3()
val controlKey = buffer.g1() == 1
return OpNpcEvent(
index,
controlKey,
3,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpcEvent
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder

public class OpNpc4Decoder : MessageDecoder<OpNpcEvent> {
override val prot: ClientProt = GameClientProt.OPNPC4

override fun decode(buffer: JagByteBuf): OpNpcEvent {
val controlKey = buffer.g1Alt2() == 1
val index = buffer.g2Alt1()
return OpNpcEvent(
index,
controlKey,
4,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpcEvent
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder

public class OpNpc5Decoder : MessageDecoder<OpNpcEvent> {
override val prot: ClientProt = GameClientProt.OPNPC5

override fun decode(buffer: JagByteBuf): OpNpcEvent {
val index = buffer.g2Alt1()
val controlKey = buffer.g1Alt1() == 1
return OpNpcEvent(
index,
controlKey,
5,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpc6Event
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder

public class OpNpc6Decoder : MessageDecoder<OpNpc6Event> {
override val prot: ClientProt = GameClientProt.OPNPC6

override fun decode(buffer: JagByteBuf): OpNpc6Event {
val id = buffer.g2Alt2()
return OpNpc6Event(id)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package net.rsprot.protocol.game.incoming.codec.npcs

import net.rsprot.buffer.JagByteBuf
import net.rsprot.protocol.ClientProt
import net.rsprot.protocol.game.incoming.npcs.OpNpcTEvent
import net.rsprot.protocol.game.incoming.prot.GameClientProt
import net.rsprot.protocol.message.codec.MessageDecoder
import net.rsprot.protocol.util.gCombinedIdAlt2

public class OpNpcTDecoder : MessageDecoder<OpNpcTEvent> {
override val prot: ClientProt = GameClientProt.OPNPCT

override fun decode(buffer: JagByteBuf): OpNpcTEvent {
val selectedSub = buffer.g2Alt1()
val selectedCombinedId = buffer.gCombinedIdAlt2()
val selectedObj = buffer.g2Alt1()
val controlKey = buffer.g1() == 1
val index = buffer.g2()
return OpNpcTEvent(
index,
controlKey,
selectedCombinedId,
selectedSub,
selectedObj,
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package net.rsprot.protocol.game.incoming.npcs

import net.rsprot.protocol.message.IncomingMessage

/**
* OpNpc6 event is fired when a player clicks the 'Examine' option on a npc.
* @property id the config id of the npc clicked
*/
@Suppress("MemberVisibilityCanBePrivate")
public class OpNpc6Event(
public val id: Int,
) : IncomingMessage {
override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as OpNpc6Event

return id == other.id
}

override fun hashCode(): Int {
return id
}

override fun toString(): String {
return "OpNpc6Event(id=$id)"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
package net.rsprot.protocol.game.incoming.npcs

import net.rsprot.protocol.message.IncomingMessage

/**
* OpNpc events are sent when a player clicks one of the five primary options on a NPC.
* It should be noted that this event will not handle 'OPNPC6', as that event requires
* different arguments.
* @property index the index of the npc that was clicked
* @property controlKey whether the control key was held down, used to invert movement speed
* @property op the option clicked, ranging from 1 to 5(inclusive).
*/
@Suppress("MemberVisibilityCanBePrivate")
public class OpNpcEvent private constructor(
private val _index: UShort,
public val controlKey: Boolean,
private val _op: UByte,
) : IncomingMessage {
public constructor(
index: Int,
controlKey: Boolean,
op: Int,
) : this(
index.toUShort(),
controlKey,
op.toUByte(),
)

public val index: Int
get() = _index.toInt()
public val op: Int
get() = _op.toInt()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as OpNpcEvent

if (_index != other._index) return false
if (controlKey != other.controlKey) return false
if (_op != other._op) return false

return true
}

override fun hashCode(): Int {
var result = _index.hashCode()
result = 31 * result + controlKey.hashCode()
result = 31 * result + _op.hashCode()
return result
}

override fun toString(): String {
return "OpNpcEvent(" +
"index=$index, " +
"controlKey=$controlKey, " +
"op=$op" +
")"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package net.rsprot.protocol.game.incoming.npcs

import net.rsprot.protocol.message.IncomingMessage
import net.rsprot.protocol.message.toIntOrMinusOne
import net.rsprot.protocol.util.CombinedId

/**
* OpNpcT events are fired whenever an interface component is targeted
* on a NPC, which, as of revision 204, includes using items from
* the player's inventory on NPCs - the OpNpcU event was deprecated.
* @property index the index of the npc the component was used on
* @property controlKey whether the control key was held down, used to invert movement speed
* @property selectedInterfaceId the interface id of the selected component
* @property selectedComponentId the component id being used on the npc
* @property selectedSub the subcomponent of the selected component, or -1 of none exists
* @property selectedObj the obj on the selected subcomponent, or -1 if none exists
*/
@Suppress("DuplicatedCode", "MemberVisibilityCanBePrivate")
public class OpNpcTEvent private constructor(
private val _index: UShort,
public val controlKey: Boolean,
private val selectedCombinedId: CombinedId,
private val _selectedSub: UShort,
private val _selectedObj: UShort,
) : IncomingMessage {
public constructor(
index: Int,
controlKey: Boolean,
selectedCombinedId: CombinedId,
selectedSub: Int,
selectedObj: Int,
) : this(
index.toUShort(),
controlKey,
selectedCombinedId,
selectedSub.toUShort(),
selectedObj.toUShort(),
)

public val index: Int
get() = _index.toInt()
public val selectedInterfaceId: Int
get() = selectedCombinedId.interfaceId
public val selectedComponentId: Int
get() = selectedCombinedId.componentId
public val selectedSub: Int
get() = _selectedSub.toIntOrMinusOne()
public val selectedObj: Int
get() = _selectedObj.toIntOrMinusOne()

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as OpNpcTEvent

if (_index != other._index) return false
if (controlKey != other.controlKey) return false
if (selectedCombinedId != other.selectedCombinedId) return false
if (_selectedSub != other._selectedSub) return false
if (_selectedObj != other._selectedObj) return false

return true
}

override fun hashCode(): Int {
var result = _index.hashCode()
result = 31 * result + controlKey.hashCode()
result = 31 * result + selectedCombinedId.hashCode()
result = 31 * result + _selectedSub.hashCode()
result = 31 * result + _selectedObj.hashCode()
return result
}

override fun toString(): String {
return "OpNpcTEvent(" +
"index=$index, " +
"controlKey=$controlKey, " +
"selectedInterfaceId=$selectedInterfaceId, " +
"selectedComponentId=$selectedComponentId, " +
"selectedSub=$selectedSub, " +
"selectedObj=$selectedObj" +
")"
}
}

0 comments on commit 7c15524

Please sign in to comment.