mirror of
https://github.com/2006-Scape/apollo.git
synced 2026-07-06 08:40:03 +00:00
Improve HintIconMessage.
This commit is contained in:
@@ -1,5 +1,6 @@
|
|||||||
package org.apollo.game.message.impl;
|
package org.apollo.game.message.impl;
|
||||||
|
|
||||||
|
import java.util.NoSuchElementException;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
import org.apollo.game.message.Message;
|
import org.apollo.game.message.Message;
|
||||||
@@ -15,14 +16,44 @@ public final class HintIconMessage extends Message {
|
|||||||
// TODO identify the other types and use an enum.
|
// TODO identify the other types and use an enum.
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hint icon type for Npcs.
|
* The type of a HintIcon.
|
||||||
*/
|
*/
|
||||||
public static final int NPC_TYPE = 1;
|
public enum Type {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The hint icon type for Players.
|
* A HintIcon that hovers over an Npc.
|
||||||
*/
|
*/
|
||||||
public static final int PLAYER_TYPE = 10;
|
NPC(1),
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A HintIcon that hovers over a Player.
|
||||||
|
*/
|
||||||
|
PLAYER(10);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The integer value of this type.
|
||||||
|
*/
|
||||||
|
private final int value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates the Type.
|
||||||
|
*
|
||||||
|
* @param value The value.
|
||||||
|
*/
|
||||||
|
private Type(int value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the value of this type.
|
||||||
|
*
|
||||||
|
* @return The value.
|
||||||
|
*/
|
||||||
|
public int getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a HintIconMessage for the Npc with the specified index.
|
* Creates a HintIconMessage for the Npc with the specified index.
|
||||||
@@ -31,7 +62,7 @@ public final class HintIconMessage extends Message {
|
|||||||
* @return The HintIconMessage.
|
* @return The HintIconMessage.
|
||||||
*/
|
*/
|
||||||
public static HintIconMessage forNpc(int index) {
|
public static HintIconMessage forNpc(int index) {
|
||||||
return new HintIconMessage(NPC_TYPE, Optional.of(index), Optional.empty());
|
return new HintIconMessage(Type.NPC, Optional.of(index), Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -41,11 +72,11 @@ public final class HintIconMessage extends Message {
|
|||||||
* @return The HintIconMessage.
|
* @return The HintIconMessage.
|
||||||
*/
|
*/
|
||||||
public static HintIconMessage forPlayer(int index) {
|
public static HintIconMessage forPlayer(int index) {
|
||||||
return new HintIconMessage(PLAYER_TYPE, Optional.of(index), Optional.empty());
|
return new HintIconMessage(Type.PLAYER, Optional.of(index), Optional.empty());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The index of the entity, if applicable.
|
* The index of the Mob, if applicable.
|
||||||
*/
|
*/
|
||||||
private final Optional<Integer> index;
|
private final Optional<Integer> index;
|
||||||
|
|
||||||
@@ -55,18 +86,18 @@ public final class HintIconMessage extends Message {
|
|||||||
private final Optional<Position> position;
|
private final Optional<Position> position;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The type of entity this HintIconMessage is directed at.
|
* The Type of entity this HintIconMessage is directed at.
|
||||||
*/
|
*/
|
||||||
private final int type;
|
private final Type type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates the HintIconMessage.
|
* Creates the HintIconMessage.
|
||||||
*
|
*
|
||||||
* @param type The type of entity this HintIconMessage is directed at.
|
* @param type The {@link Type} of this HintIconMessage.
|
||||||
* @param index The index of the entity, if applicable.
|
* @param index The index of the Mob, if applicable.
|
||||||
* @param position The Position of the tile, if applicable.
|
* @param position The Position of the tile, if applicable.
|
||||||
*/
|
*/
|
||||||
private HintIconMessage(int type, Optional<Integer> index, Optional<Position> position) {
|
private HintIconMessage(Type type, Optional<Integer> index, Optional<Position> position) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.position = position;
|
this.position = position;
|
||||||
@@ -76,18 +107,20 @@ public final class HintIconMessage extends Message {
|
|||||||
* Gets the index of the entity, if applicable.
|
* Gets the index of the entity, if applicable.
|
||||||
*
|
*
|
||||||
* @return The index.
|
* @return The index.
|
||||||
|
* @throws NoSuchElementException If no index is available for this HintIcon.
|
||||||
*/
|
*/
|
||||||
public Optional<Integer> getIndex() {
|
public int getIndex() {
|
||||||
return index;
|
return index.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gets the {@link Position} of the tile, if applicable.
|
* Gets the {@link Position} of the tile, if applicable.
|
||||||
*
|
*
|
||||||
* @return The Position.
|
* @return The Position.
|
||||||
|
* @throws NoSuchElementException If no Position is available for this HintIcon.
|
||||||
*/
|
*/
|
||||||
public Optional<Position> getPosition() {
|
public Position getPosition() {
|
||||||
return position;
|
return position.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -95,7 +128,7 @@ public final class HintIconMessage extends Message {
|
|||||||
*
|
*
|
||||||
* @return The type.
|
* @return The type.
|
||||||
*/
|
*/
|
||||||
public int getType() {
|
public Type getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ public final class HintIconMessageEncoder extends MessageEncoder<HintIconMessage
|
|||||||
@Override
|
@Override
|
||||||
public GamePacket encode(HintIconMessage message) {
|
public GamePacket encode(HintIconMessage message) {
|
||||||
GamePacketBuilder builder = new GamePacketBuilder(254);
|
GamePacketBuilder builder = new GamePacketBuilder(254);
|
||||||
int type = message.getType();
|
HintIconMessage.Type type = message.getType();
|
||||||
builder.put(DataType.BYTE, type);
|
builder.put(DataType.BYTE, type.getValue());
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case HintIconMessage.NPC_TYPE:
|
case NPC:
|
||||||
case HintIconMessage.PLAYER_TYPE:
|
case PLAYER:
|
||||||
builder.put(DataType.SHORT, message.getIndex().get());
|
builder.put(DataType.SHORT, message.getIndex());
|
||||||
builder.put(DataType.TRI_BYTE, 0); // Dummy bytes
|
builder.put(DataType.TRI_BYTE, 0); // Dummy bytes
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -16,13 +16,13 @@ public final class HintIconMessageEncoder extends MessageEncoder<HintIconMessage
|
|||||||
@Override
|
@Override
|
||||||
public GamePacket encode(HintIconMessage message) {
|
public GamePacket encode(HintIconMessage message) {
|
||||||
GamePacketBuilder builder = new GamePacketBuilder(199);
|
GamePacketBuilder builder = new GamePacketBuilder(199);
|
||||||
int type = message.getType();
|
HintIconMessage.Type type = message.getType();
|
||||||
builder.put(DataType.BYTE, type);
|
builder.put(DataType.BYTE, type.getValue());
|
||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case HintIconMessage.NPC_TYPE:
|
case NPC:
|
||||||
case HintIconMessage.PLAYER_TYPE:
|
case PLAYER:
|
||||||
builder.put(DataType.SHORT, message.getIndex().get());
|
builder.put(DataType.SHORT, message.getIndex());
|
||||||
builder.put(DataType.TRI_BYTE, 0); // Dummy bytes
|
builder.put(DataType.TRI_BYTE, 0); // Dummy bytes
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -41,7 +41,6 @@ import org.apollo.game.message.impl.UpdateTileItemMessage;
|
|||||||
import org.apollo.game.message.impl.UpdateWeightMessage;
|
import org.apollo.game.message.impl.UpdateWeightMessage;
|
||||||
import org.apollo.net.meta.PacketMetaDataGroup;
|
import org.apollo.net.meta.PacketMetaDataGroup;
|
||||||
import org.apollo.net.release.Release;
|
import org.apollo.net.release.Release;
|
||||||
import org.apollo.net.release.r317.HintIconMessageEncoder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A {@link Release} implementation for the 377 protocol.
|
* A {@link Release} implementation for the 377 protocol.
|
||||||
@@ -128,8 +127,8 @@ public final class Release377 extends Release {
|
|||||||
|
|
||||||
register(1, new ItemOnItemMessageDecoder());
|
register(1, new ItemOnItemMessageDecoder());
|
||||||
register(36, new MagicOnItemMessageDecoder());
|
register(36, new MagicOnItemMessageDecoder());
|
||||||
register(31, new MagicOnPlayerMessageDecoder());
|
register(31, new MagicOnPlayerMessageDecoder());
|
||||||
register(104, new MagicOnNpcMessageDecoder());
|
register(104, new MagicOnNpcMessageDecoder());
|
||||||
|
|
||||||
register(187, new FocusUpdateMessageDecoder());
|
register(187, new FocusUpdateMessageDecoder());
|
||||||
register(19, new MouseClickedMessageDecoder());
|
register(19, new MouseClickedMessageDecoder());
|
||||||
@@ -144,8 +143,8 @@ public final class Release377 extends Release {
|
|||||||
register(112, new FirstNpcActionMessageDecoder());
|
register(112, new FirstNpcActionMessageDecoder());
|
||||||
register(67, new SecondNpcActionMessageDecoder());
|
register(67, new SecondNpcActionMessageDecoder());
|
||||||
register(13, new ThirdNpcActionMessageDecoder());
|
register(13, new ThirdNpcActionMessageDecoder());
|
||||||
register(42, new FourthNpcActionMessageDecoder());
|
register(42, new FourthNpcActionMessageDecoder());
|
||||||
register(8, new FifthNpcActionMessageDecoder());
|
register(8, new FifthNpcActionMessageDecoder());
|
||||||
|
|
||||||
register(71, new TakeTileItemMessageDecoder());
|
register(71, new TakeTileItemMessageDecoder());
|
||||||
register(152, new ItemOnObjectMessageDecoder());
|
register(152, new ItemOnObjectMessageDecoder());
|
||||||
|
|||||||
Reference in New Issue
Block a user