-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #98 from Jameskmonger/packet-impl-object-actions
refactor: convert object interaction packets to new system
- Loading branch information
Showing
6 changed files
with
190 additions
and
26 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
39 changes: 39 additions & 0 deletions
39
...ava/org/runejs/client/message/outbound/interactions/ObjectInteractionOutboundMessage.java
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,39 @@ | ||
package org.runejs.client.message.outbound.interactions; | ||
|
||
import org.runejs.client.message.OutboundMessage; | ||
|
||
/** | ||
* Represents a message sent to the server when a player interacts with an object. | ||
* | ||
* e.g. clicking on a tree to chop it down | ||
*/ | ||
public class ObjectInteractionOutboundMessage implements OutboundMessage { | ||
/** | ||
* Which option on the object was clicked | ||
* | ||
* i.e. 1 = first option, 2 = second option, etc. | ||
*/ | ||
public final int option; | ||
|
||
/** | ||
* The id of the object | ||
*/ | ||
public final int objectId; | ||
|
||
/** | ||
* The x coordinate of the object | ||
*/ | ||
public final int x; | ||
|
||
/** | ||
* The y coordinate of the object | ||
*/ | ||
public final int y; | ||
|
||
public ObjectInteractionOutboundMessage(int option, int objectId, int x, int y) { | ||
this.option = option; | ||
this.objectId = objectId; | ||
this.x = x; | ||
this.y = y; | ||
} | ||
} |
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
78 changes: 78 additions & 0 deletions
78
...nejs/client/net/codec/runejs435/encoder/interactions/ObjectInteractionMessageEncoder.java
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,78 @@ | ||
package org.runejs.client.net.codec.runejs435.encoder.interactions; | ||
|
||
import org.runejs.client.message.outbound.interactions.ObjectInteractionOutboundMessage; | ||
import org.runejs.client.net.OutgoingPackets; | ||
import org.runejs.client.net.PacketBuffer; | ||
import org.runejs.client.net.codec.MessageEncoder; | ||
|
||
public class ObjectInteractionMessageEncoder implements MessageEncoder<ObjectInteractionOutboundMessage> { | ||
|
||
@Override | ||
public PacketBuffer encode(ObjectInteractionOutboundMessage message) { | ||
switch (message.option) { | ||
case 1: | ||
return encodeOption1Interaction(message); | ||
case 2: | ||
return encodeOption2Interaction(message); | ||
case 3: | ||
return encodeOption3Interaction(message); | ||
case 4: | ||
return encodeOption4Interaction(message); | ||
case 5: | ||
return encodeOption5Interaction(message); | ||
default: | ||
throw new RuntimeException("Invalid option: " + message.option); | ||
} | ||
} | ||
|
||
private PacketBuffer encodeOption1Interaction(ObjectInteractionOutboundMessage message) { | ||
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(6, 30); | ||
|
||
buffer.putShortBE(message.objectId); | ||
buffer.putShortBE(message.y); | ||
buffer.putShortLE(message.x); | ||
|
||
return buffer; | ||
} | ||
|
||
private PacketBuffer encodeOption2Interaction(ObjectInteractionOutboundMessage message) { | ||
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(6, 164); | ||
|
||
buffer.putShortLE(message.x); | ||
buffer.putShortLE(message.y); | ||
buffer.putShortLE(message.objectId); | ||
|
||
return buffer; | ||
} | ||
|
||
private PacketBuffer encodeOption3Interaction(ObjectInteractionOutboundMessage message) { | ||
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(6, 183); | ||
|
||
buffer.putShortBE(message.y); | ||
buffer.putShortBE(message.objectId); | ||
buffer.putShortBE(message.x); | ||
|
||
return buffer; | ||
} | ||
|
||
private PacketBuffer encodeOption4Interaction(ObjectInteractionOutboundMessage message) { | ||
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(6, 229); | ||
|
||
buffer.putShortLE(message.x); | ||
buffer.putShortLE(message.objectId); | ||
buffer.putShortLE(message.y); | ||
|
||
return buffer; | ||
} | ||
|
||
private PacketBuffer encodeOption5Interaction(ObjectInteractionOutboundMessage message) { | ||
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(6, 62); | ||
|
||
buffer.putShortBE(message.objectId); | ||
buffer.putShortLE(message.y); | ||
buffer.putShortLE(message.x); | ||
|
||
return buffer; | ||
} | ||
|
||
} |