Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: convert "examine" packets to message system #117

Merged
merged 3 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.runejs.client.media.renderable.actor.Player;
import org.runejs.client.media.renderable.actor.PlayerAppearance;
import org.runejs.client.message.outbound.chat.AcceptRequestOutboundMessage;
import org.runejs.client.message.outbound.examine.*;
import org.runejs.client.message.outbound.interactions.*;
import org.runejs.client.message.outbound.magic.*;
import org.runejs.client.message.outbound.useitem.*;
Expand Down Expand Up @@ -597,8 +598,10 @@ public static void processMenuActions(int arg1) {
ClientScriptRunner.crossX = Class57.clickX;
LinkedList.crossType = 2;
OverlayDefinition.crossIndex = 0;
SceneCluster.packetBuffer.putPacket(148);
SceneCluster.packetBuffer.putShortLE(npcIdx >> 14 & 0x7fff);

int objectId = npcIdx >> 14 & 0x7fff;

OutgoingPackets.sendMessage(new ExamineObjectOutboundMessage(objectId));
}
if(action == ActionRowType.INTERACT_WITH_OBJECT_OPTION_4.getId()) {
AnimationSequence.method596(i, npcIdx, (byte) -79, i_10_);
Expand Down Expand Up @@ -797,8 +800,7 @@ public static void processMenuActions(int arg1) {
class40_sub5_sub5 = class40_sub5_sub5.getChildDefinition();
}
if(class40_sub5_sub5 != null) {
SceneCluster.packetBuffer.putPacket(247);
SceneCluster.packetBuffer.putShortLE(class40_sub5_sub5.id);
OutgoingPackets.sendMessage(new ExamineNPCOutboundMessage(class40_sub5_sub5.id));
}
}
}
Expand Down Expand Up @@ -921,8 +923,8 @@ public static void processMenuActions(int arg1) {
LinkedList.crossType = 2;
MovedStatics.crossY = RSString.clickY;
ClientScriptRunner.crossX = Class57.clickX;
SceneCluster.packetBuffer.putPacket(151);
SceneCluster.packetBuffer.putShortLE(npcIdx);

OutgoingPackets.sendMessage(new ExamineItemOutboundMessage(npcIdx));
}
if(action == ActionRowType.INTERACT_WITH_OBJECT_OPTION_5.getId()) {
AnimationSequence.method596(i, npcIdx, (byte) -11, i_10_);
Expand Down Expand Up @@ -1071,8 +1073,7 @@ public static void processMenuActions(int arg1) {
gameInterface = gameInterface.children[i];
}
if(gameInterface == null || gameInterface.itemAmount < 100000) {
SceneCluster.packetBuffer.putPacket(151);
SceneCluster.packetBuffer.putShortLE(npcIdx);
OutgoingPackets.sendMessage(new ExamineItemOutboundMessage(npcIdx));
} else {
ChatBox.addChatMessage("", gameInterface.itemAmount + Native.amountSeparatorX + ItemDefinition.forId(npcIdx, 10).name, 0);
}
Expand Down Expand Up @@ -1221,8 +1222,7 @@ public static void processMenuActions(int arg1) {
if(action == ActionRowType.EXAMINE_ITEM_ON_V1_WIDGET.getId()) {
GameInterface gameInterface = getInterface(i_10_);
if(gameInterface == null || gameInterface.itemAmounts[i] < 100000) {
SceneCluster.packetBuffer.putPacket(151);
SceneCluster.packetBuffer.putShortLE(npcIdx);
OutgoingPackets.sendMessage(new ExamineItemOutboundMessage(npcIdx));
} else {
ChatBox.addChatMessage("", gameInterface.itemAmounts[i] + Native.amountSeparatorX + ItemDefinition.forId(npcIdx, 10).name, 0);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.runejs.client.message.outbound.examine;

import org.runejs.client.message.OutboundMessage;

/**
* An {@link OutboundMessage} sent to the server to examine an item.
*/
public class ExamineItemOutboundMessage implements OutboundMessage {
/**
* The id of the item to examine.
*/
public final int itemId;

/**
* Creates a new {@link ExamineItemOutboundMessage}.
* @param itemId The id of the item to examine.
*/
public ExamineItemOutboundMessage(int itemId) {
this.itemId = itemId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.runejs.client.message.outbound.examine;

import org.runejs.client.message.OutboundMessage;

/**
* An {@link OutboundMessage} sent to the server to examine an NPC.
*/
public class ExamineNPCOutboundMessage implements OutboundMessage {
/**
* The id of the NPC to examine.
*/
public final int npcId;

/**
* Creates a new {@link ExamineNPCOutboundMessage}.
* @param npcId The id of the NPC to examine.
*/
public ExamineNPCOutboundMessage(int npcId) {
this.npcId = npcId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.runejs.client.message.outbound.examine;

import org.runejs.client.message.OutboundMessage;

/**
* An {@link OutboundMessage} sent to the server to examine an object.
*/
public class ExamineObjectOutboundMessage implements OutboundMessage {
/**
* The id of the object to examine.
*/
public final int objectId;

/**
* Creates a new {@link ExamineObjectOutboundMessage}.
* @param objectId The id of the object to examine.
*/
public ExamineObjectOutboundMessage(int objectId) {
this.objectId = objectId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.runejs.client.net.codec.MessagePacketCodec;
import org.runejs.client.message.outbound.chat.*;
import org.runejs.client.message.outbound.console.*;
import org.runejs.client.message.outbound.examine.*;
import org.runejs.client.message.outbound.interactions.*;
import org.runejs.client.message.outbound.magic.*;
import org.runejs.client.message.outbound.useitem.*;
Expand All @@ -14,6 +15,7 @@
import org.runejs.client.net.codec.runejs435.decoder.misc.*;
import org.runejs.client.net.codec.runejs435.encoder.chat.*;
import org.runejs.client.net.codec.runejs435.encoder.console.*;
import org.runejs.client.net.codec.runejs435.encoder.examine.*;
import org.runejs.client.net.codec.runejs435.encoder.interactions.*;
import org.runejs.client.net.codec.runejs435.encoder.magic.*;
import org.runejs.client.net.codec.runejs435.encoder.useitem.*;
Expand Down Expand Up @@ -61,6 +63,11 @@ private void registerEncoders() {
register(UseItemOnObjectOutboundMessage.class, new UseItemOnObjectMessageEncoder());
register(UseItemOnWorldItemOutboundMessage.class, new UseItemOnWorldItemMessageEncoder());
register(UseItemOnWidgetItemOutboundMessage.class, new UseItemOnWidgetItemMessageEncoder());

// examine
register(ExamineItemOutboundMessage.class, new ExamineItemMessageEncoder());
register(ExamineNPCOutboundMessage.class, new ExamineNPCMessageEncoder());
register(ExamineObjectOutboundMessage.class, new ExamineObjectMessageEncoder());
}

private void registerDecoders() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.runejs.client.net.codec.runejs435.encoder.examine;

import org.runejs.client.message.outbound.examine.ExamineItemOutboundMessage;
import org.runejs.client.net.OutgoingPackets;
import org.runejs.client.net.PacketBuffer;
import org.runejs.client.net.codec.MessageEncoder;

/**
* Encodes a {@link ExamineItemOutboundMessage} into a {@link PacketBuffer}.
*/
public class ExamineItemMessageEncoder implements MessageEncoder<ExamineItemOutboundMessage> {
@Override
public PacketBuffer encode(ExamineItemOutboundMessage message) {
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(2, 151);

buffer.putShortLE(message.itemId);

return buffer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.runejs.client.net.codec.runejs435.encoder.examine;

import org.runejs.client.message.outbound.examine.ExamineNPCOutboundMessage;
import org.runejs.client.net.OutgoingPackets;
import org.runejs.client.net.PacketBuffer;
import org.runejs.client.net.codec.MessageEncoder;

/**
* Encodes a {@link ExamineNPCOutboundMessage} into a {@link PacketBuffer}.
*/
public class ExamineNPCMessageEncoder implements MessageEncoder<ExamineNPCOutboundMessage> {
@Override
public PacketBuffer encode(ExamineNPCOutboundMessage message) {
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(2, 247);

buffer.putShortLE(message.npcId);

return buffer;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package org.runejs.client.net.codec.runejs435.encoder.examine;

import org.runejs.client.message.outbound.examine.ExamineObjectOutboundMessage;
import org.runejs.client.net.OutgoingPackets;
import org.runejs.client.net.PacketBuffer;
import org.runejs.client.net.codec.MessageEncoder;

/**
* Encodes a {@link ExamineObjectOutboundMessage} into a {@link PacketBuffer}.
*/
public class ExamineObjectMessageEncoder implements MessageEncoder<ExamineObjectOutboundMessage> {
@Override
public PacketBuffer encode(ExamineObjectOutboundMessage message) {
PacketBuffer buffer = OutgoingPackets.openFixedSizePacket(2, 148);

buffer.putShortLE(message.objectId);

return buffer;
}
}