RuneHive-Game
Loading...
Searching...
No Matches
SendGroundItem.java
Go to the documentation of this file.
1package com.runehive.net.packet.out;
2
3import com.runehive.net.codec.ByteOrder;
4import com.runehive.net.codec.ByteModification;
5import com.runehive.game.world.entity.mob.player.Player;
6import com.runehive.game.world.items.ground.GroundItem;
7import com.runehive.net.packet.OutgoingPacket;
8
9public class SendGroundItem extends OutgoingPacket {
10
11 private final GroundItem groundItem;
13
15 super(44, 12);
16 this.groundItem = groundItem;
17 this.type = type;
18 }
19
23
24 @Override
25 public boolean encode(Player player) {
26 if (groundItem.instance != player.instance) {
27 return false;
28 }
29
30 if (!groundItem.isRegistered()) {
31 return false;
32 }
33
34 if (!groundItem.item.isTradeable()) {
35 this.type = GroundItemType.UNTRADEABLE;
36 } else if (groundItem.item.getValue() > 1_000_000) {
37 this.type = GroundItemType.RARE;
38 } else {
39 this.type = GroundItemType.NORMAL;
40 }
41
42 player.send(new SendCoordinate(groundItem.getPosition()));
43 builder.writeShort(groundItem.item.getId(), ByteModification.ADD, ByteOrder.LE)
44 .writeLong(groundItem.item.getAmount())
45 .writeByte(type.ordinal())
46 .writeByte(0);
47 return true;
48 }
49
55}
This class represents a character controlled by a player.
Definition Player.java:125
Represents a single Ground item on the world map.
OutgoingPacket(int opcode, int capacity)
SendGroundItem(GroundItem groundItem, GroundItemType type)
Represents RuneScape's custom value types.
ADD
Adds 128 to the value when written, subtracts 128 from the rarity when read.
Represents the order in which bytes are written.
Definition ByteOrder.java:8
LE
Represents Little-endian.