RuneHive-Game
Loading...
Searching...
No Matches
SendEntityFeed.java
Go to the documentation of this file.
1package com.runehive.net.packet.out;
2
3import com.runehive.game.world.entity.mob.Mob;
4import com.runehive.game.world.entity.mob.player.Player;
5import com.runehive.net.packet.OutgoingPacket;
6import com.runehive.net.packet.PacketType;
7
8/**
9 * Sends the entity feed.
10 *
11 * @author Daniel
12 */
13public final class SendEntityFeed extends OutgoingPacket {
14
15 private static final int OPCODE = 175;
16
17 public static final int NO_OPPONENT = -1;
18 public static final int OPPONENT_OFFSET_NPC = 2048;
19
20 public static int getOpponent(final Mob mob) {
21 return mob.getIndex()
22 + (!mob.isPlayer()
23 ? SendEntityFeed.OPPONENT_OFFSET_NPC : 0);
24 }
25
26 private final int opponentId;
27
28 private final int hp;
29 private final int maxHp;
30
31 public SendEntityFeed(final int opponentId,
32 final int hp, final int maxHp) {
33 super(OPCODE, PacketType.FIXED, 6);
34 this.opponentId = opponentId;
35 this.hp = hp;
36 this.maxHp = maxHp;
37 }
38
39 public SendEntityFeed(final Mob mob) {
40 this(
41 getOpponent(mob),
42 mob.getCurrentHealth(),
44 );
45 }
46
47 public SendEntityFeed(final int hp, final int maxHp) {
48 this(NO_OPPONENT, hp, maxHp);
49 }
50
51 public SendEntityFeed() {
52 this(0, 0);
53 }
54
55 @Override
56 public boolean encode(final Player player) {
57 builder.writeShort(opponentId)
58 .writeShort(hp)
59 .writeShort(maxHp);
60 return true;
61 }
62
63}
Handles the mob class.
Definition Mob.java:66
final boolean isPlayer()
Check if an entity is a player.
Definition Mob.java:564
This class represents a character controlled by a player.
Definition Player.java:125
OutgoingPacket(int opcode, int capacity)
SendEntityFeed(final int hp, final int maxHp)
SendEntityFeed(final int opponentId, final int hp, final int maxHp)
Represents a type of packet.
FIXED
A fixed size packet where the size never changes.