RuneHive-Game
Loading...
Searching...
No Matches
ExaminePacketListener.java
Go to the documentation of this file.
1package com.runehive.net.packet.in;
2
3import com.runehive.game.world.entity.mob.player.Player;
4import com.runehive.game.world.entity.mob.player.PlayerRight;
5import com.runehive.game.world.items.Item;
6import com.runehive.game.world.items.containers.inventory.Inventory;
7import com.runehive.game.world.items.containers.pricechecker.PriceType;
8import com.runehive.net.packet.GamePacket;
9import com.runehive.net.packet.PacketListener;
10import com.runehive.net.packet.PacketListenerMeta;
11import com.runehive.net.packet.out.SendMessage;
12import com.runehive.util.MessageColor;
13import com.runehive.util.Utility;
14import org.jire.runehiveps.defs.ItemDef;
15import org.jire.runehiveps.defs.ItemDefLoader;
16import org.jire.runehiveps.event.item.ItemExamineEvent;
17import org.jire.runehiveps.event.npc.NpcExamineEvent;
18import org.jire.runehiveps.event.object.ObjectExamineEvent;
19
20/**
21 * Handles the in examine packet.
22 *
23 * @author Daniel
24 */
26public class ExaminePacketListener implements PacketListener {
27
28 private static final int INTERFACE = 0;
29 private static final int NPC = 1;
30 private static final int ITEM = 2;
31 private static final int OBJECT = 3;
32
33 @Override
34 public void handlePacket(Player player, GamePacket packet) {
35 final int type = packet.readByte(false);
36 switch (type) {
37 case INTERFACE: {
39 break;
40 }
41 case NPC: {
42 int npcId = packet.readShort(false);
43 player.getEvents().interact(player, new NpcExamineEvent(npcId));
44 break;
45 }
46 case ITEM: {
47 int itemId = packet.readShort(false);
48 player.getEvents().interact(player, new ItemExamineEvent(itemId));
49 break;
50 }
51 case OBJECT: {
52 int objectId = packet.readShort(false);
53 player.getEvents().interact(player, new ObjectExamineEvent(objectId));
54 break;
55 }
56 }
57 }
58
59 private static void handleInterfaceExamine(Player player, GamePacket packet) {
60 int slot = packet.readShort();
61 int interfaceId = packet.readShort();
62 int itemId = packet.readShort();
63
64 if (PlayerRight.isDeveloper(player)) {
65 player.send(new SendMessage("[Examine] - slot: " + slot + " -- interfaceId: " + interfaceId + " -- itemId: " + itemId, MessageColor.DEVELOPER));
66 }
67
68 if (slot == -1) {
69 player.settings.clientWidth = interfaceId;
70 player.settings.clientHeight = itemId;
71 return;
72 }
73
74 switch (interfaceId) {
76 Item item = player.inventory.get(slot);
77 if (item == null || item.getId() != itemId) return;
78 final ItemDef itemDef = ItemDefLoader.map.get(itemId);
79 if (itemDef != null) {
80 String examine = itemDef.getExamine();
81 if (!"null".equals(examine))
82 player.send(new SendMessage(examine));
83 }
84 if (item.isTradeable()) {
85 String message = "";
86 message += "Item: <col=A52929>" + item.getName() + "</col> ";
87 message += "Value: <col=A52929>" + Utility.formatDigits(item.getValue(PriceType.VALUE)) + " (" + Utility.formatDigits(item.getValue(PriceType.VALUE) * item.getAmount()) + ")</col> ";
88 message += "High alch: <col=A52929>" + Utility.formatDigits(item.getValue(PriceType.HIGH_ALCH_VALUE)) + "</col> ";
89 player.send(new SendMessage(message));
90 }
91 break;
92 }
93 case 26816: {
94 if (!player.attributes.has("DROP_SIMULATOR_SORTED_LIST")) return;
95 Item[] items = player.attributes.get("DROP_SIMULATOR_SORTED_LIST");
96 if (slot < 0 || slot >= items.length) return;
97 Item item = items[slot];
98 if (item.isTradeable()) {
99 String message = "";
100 message += "Item: <col=A52929>" + item.getName() + "</col> ";
101 message += "Value: <col=A52929>" + Utility.formatDigits(item.getValue(PriceType.VALUE)) + " (" + Utility.formatDigits(item.getValue(PriceType.VALUE) * item.getAmount()) + ")</col> ";
102 message += "High alch: <col=A52929>" + Utility.formatDigits(item.getValue(PriceType.HIGH_ALCH_VALUE));
103 player.send(new SendMessage(message));
104 }
105 break;
106 }
107
108 }
109 }
110
111}
final GenericAttributes attributes
Definition Mob.java:95
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
final int getId()
Gets the identification of this item.
Definition Item.java:324
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
int getValue(PriceType type)
Gets the value for this item.
Definition Item.java:98
final Item get(int index)
Gets the Item located on index.
An ItemContainer implementation that manages the inventory for a Player.
static final int INVENTORY_DISPLAY_ID
The inventory item display widget identifier.
Represents a single game packet.
static void handleInterfaceExamine(Player player, GamePacket packet)
void handlePacket(Player player, GamePacket packet)
Handles the packet that has just been received.
The OutgoingPacket that sends a message to a Players chatbox in the client.
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
public< K, E > E get(K key)
Gets a generic attribute.
public< K > boolean has(K key)
Checks if a key is in the list of generic attribute.
static boolean isDeveloper(Player player)
Checks if the player has developer status.
Holds an enum of colors for ease.
An annotation that describes what client -> server packets a PacketListener can listen to.