RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
SendEntityFeed.java
1package com.osroyale.net.packet.out;
2
3import com.osroyale.game.world.entity.mob.Mob;
4import com.osroyale.game.world.entity.mob.player.Player;
5import com.osroyale.net.packet.OutgoingPacket;
6import com.osroyale.net.packet.PacketType;
7
41
42public final class SendEntityFeed extends OutgoingPacket {
43
44 private static final int OPCODE = 175;
45
46 public static final int NO_OPPONENT = -1;
47 public static final int OPPONENT_OFFSET_NPC = 2048;
48
49 public static int getOpponent(final Mob mob) {
50 return mob.getIndex()
51 + (!mob.isPlayer()
52 ? SendEntityFeed.OPPONENT_OFFSET_NPC : 0);
53 }
54
55 private final int opponentId;
56
57 private final int hp;
58 private final int maxHp;
59
60 public SendEntityFeed(final int opponentId,
61 final int hp, final int maxHp) {
62 super(OPCODE, PacketType.FIXED, 6);
63 this.opponentId = opponentId;
64 this.hp = hp;
65 this.maxHp = maxHp;
66 }
67
68 public SendEntityFeed(final Mob mob) {
69 this(
70 getOpponent(mob),
71 mob.getCurrentHealth(),
72 mob.getMaximumHealth()
73 );
74 }
75
76 public SendEntityFeed(final int hp, final int maxHp) {
77 this(NO_OPPONENT, hp, maxHp);
78 }
79
80 public SendEntityFeed() {
81 this(0, 0);
82 }
83
84 @Override
85 public boolean encode(final Player player) {
86 builder.writeShort(opponentId)
87 .writeShort(hp)
88 .writeShort(maxHp);
89 return true;
90 }
91
92}