-
-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpc1Decoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpc2Decoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpc3Decoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpc4Decoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpc5Decoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpc6Decoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...221-desktop/src/main/kotlin/net/rsprot/protocol/game/incoming/codec/npcs/OpNpcTDecoder.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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, | ||
) | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/incoming/npcs/OpNpc6Event.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)" | ||
} | ||
} |
61 changes: 61 additions & 0 deletions
61
protocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/incoming/npcs/OpNpcEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" + | ||
")" | ||
} | ||
} |
85 changes: 85 additions & 0 deletions
85
...ocol/osrs-221-model/src/main/kotlin/net/rsprot/protocol/game/incoming/npcs/OpNpcTEvent.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" + | ||
")" | ||
} | ||
} |