-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add OPNPCU message and its implementation
Close issue #148
- Loading branch information
Showing
6 changed files
with
141 additions
and
9 deletions.
There are no files selected for viewing
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
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
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
19 changes: 19 additions & 0 deletions
19
game/src/main/kotlin/gg/rsmod/game/message/decoder/OpNpcUDecoder.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,19 @@ | ||
package gg.rsmod.game.message.decoder | ||
|
||
import gg.rsmod.game.message.MessageDecoder | ||
import gg.rsmod.game.message.impl.OpNpcUMessage | ||
|
||
/** | ||
* @author Tom <[email protected]> | ||
*/ | ||
class OpNpcUDecoder : MessageDecoder<OpNpcUMessage>() { | ||
|
||
override fun decode(opcode: Int, opcodeIndex: Int, values: HashMap<String, Number>, stringValues: HashMap<String, String>): OpNpcUMessage { | ||
val item = values["item"]!!.toInt() | ||
val slot = values["slot"]!!.toInt() | ||
val componentHash = values["component_hash"]!!.toInt() | ||
val npcIndex = values["npc_index"]!!.toInt() | ||
val movementType = values["movement_type"]!!.toInt() | ||
return OpNpcUMessage(componentHash, npcIndex, item, slot, movementType) | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
game/src/main/kotlin/gg/rsmod/game/message/handler/OpNpcUHandler.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,54 @@ | ||
package gg.rsmod.game.message.handler | ||
|
||
import gg.rsmod.game.action.PawnPathAction | ||
import gg.rsmod.game.message.MessageHandler | ||
import gg.rsmod.game.message.impl.OpNpcUMessage | ||
import gg.rsmod.game.model.World | ||
import gg.rsmod.game.model.attr.INTERACTING_ITEM | ||
import gg.rsmod.game.model.attr.INTERACTING_ITEM_ID | ||
import gg.rsmod.game.model.attr.INTERACTING_ITEM_SLOT | ||
import gg.rsmod.game.model.attr.INTERACTING_NPC_ATTR | ||
import gg.rsmod.game.model.entity.Client | ||
import gg.rsmod.game.model.priv.Privilege | ||
import java.lang.ref.WeakReference | ||
|
||
/** | ||
* @author Tom <[email protected]> | ||
*/ | ||
class OpNpcUHandler : MessageHandler<OpNpcUMessage> { | ||
|
||
override fun handle(client: Client, world: World, message: OpNpcUMessage) { | ||
val index = message.npcIndex | ||
val npc = world.npcs[index] ?: return | ||
|
||
if (!client.lock.canNpcInteract() || !client.lock.canItemInteract()) { | ||
return | ||
} | ||
|
||
val movementType = message.movementType | ||
val itemId = message.item | ||
val itemSlot = message.slot | ||
|
||
val item = client.inventory[itemSlot] ?: return | ||
|
||
if (item.id != itemId) { | ||
return | ||
} | ||
|
||
log(client, "Item on npc: movement=%d, item=%s, slot=%d, npc=%s, index=%d", movementType, item, itemSlot, npc, index) | ||
|
||
if (movementType == 1 && world.privileges.isEligible(client.privilege, Privilege.ADMIN_POWER)) { | ||
client.moveTo(world.findRandomTileAround(npc.tile, 1) ?: npc.tile) | ||
} | ||
|
||
client.closeInterfaceModal() | ||
client.interruptQueues() | ||
client.resetInteractions() | ||
|
||
client.attr[INTERACTING_NPC_ATTR] = WeakReference(npc) | ||
client.attr[INTERACTING_ITEM] = WeakReference(item) | ||
client.attr[INTERACTING_ITEM_ID] = item.id | ||
client.attr[INTERACTING_ITEM_SLOT] = itemSlot | ||
client.executePlugin(PawnPathAction.itemUsePlugin) | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
game/src/main/kotlin/gg/rsmod/game/message/impl/OpNpcUMessage.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,8 @@ | ||
package gg.rsmod.game.message.impl | ||
|
||
import gg.rsmod.game.message.Message | ||
|
||
/** | ||
* @author Tom <[email protected]> | ||
*/ | ||
data class OpNpcUMessage(val componentHash: Int, val npcIndex: Int, val item: Int, val slot: Int, val movementType: Int) : Message |