Merge pull request #202 from ryleykimmel/issue179

Rebase HintIconMessage
This commit is contained in:
Ryley Kimmel
2016-02-11 11:36:05 -05:00
10 changed files with 279 additions and 95 deletions
@@ -1,7 +1,11 @@
require 'java'
java_import 'org.apollo.game.message.impl.HintIconMessage'
java_import 'org.apollo.game.message.impl.MobHintIconMessage'
java_import 'org.apollo.game.message.impl.PositionHintIconMessage'
java_import 'org.apollo.game.message.impl.SwitchTabInterfaceMessage'
java_import 'org.apollo.game.model.entity.EntityType'
java_import 'org.apollo.game.model.Position'
private
@@ -92,7 +96,8 @@ conversation :tutorial_runescape_guide do
close do |player|
if player.tutorial_island_progress < :runescape_guide_finished
reset_hint_icon(player)
# TODO: door hint icon
# TODO: Maybe move this, define a constant for the Position and height
player.send(PositionHintIconMessage.new(HintIconMessage::Type::SOUTH, Position.new(3097, 3107), 120))
player.tutorial_island_progress = :runescape_guide_finished
end
@@ -103,10 +108,10 @@ end
# Enables the hint icon above the Runescape guide.
def show_hint_icon(player)
player.send(HintIconMessage.for_npc(@runescape_guide.index))
player.send(MobHintIconMessage.create(@runescape_guide))
end
# Resets the hint icon.
def reset_hint_icon(player)
player.send(HintIconMessage.reset_npc)
player.send(MobHintIconMessage.reset(EntityType::NPC))
end
@@ -1,10 +1,5 @@
package org.apollo.game.message.impl;
import java.util.NoSuchElementException;
import java.util.Optional;
import java.util.OptionalInt;
import org.apollo.game.model.Position;
import org.apollo.net.message.Message;
/**
@@ -12,9 +7,7 @@ import org.apollo.net.message.Message;
*
* @author Major
*/
public final class HintIconMessage extends Message {
// TODO identify the other types.
public abstract class HintIconMessage extends Message {
/**
* The type of a HintIcon.
@@ -26,6 +19,31 @@ public final class HintIconMessage extends Message {
*/
NPC(1),
/**
* A HintIcon that hovers directly over a Position.
*/
CENTER(2),
/**
* A HintIcon that hovers north over a Position.
*/
NORTH(3),
/**
* A HintIcon that hovers south over a Position.
*/
SOUTH(4),
/**
* A HintIcon that hovers east over a Position.
*/
EAST(5),
/**
* A HintIcon that hovers west over a Position.
*/
WEST(6),
/**
* A HintIcon that hovers over a Player.
*/
@@ -56,54 +74,6 @@ public final class HintIconMessage extends Message {
}
/**
* Creates a HintIconMessage for the Npc with the specified index.
*
* @param index The index of the Npc.
* @return The HintIconMessage.
*/
public static HintIconMessage forNpc(int index) {
return new HintIconMessage(Type.NPC, OptionalInt.of(index), Optional.empty());
}
/**
* Creates a HintIconMessage for the Player with the specified index.
*
* @param index The index of the Player.
* @return The HintIconMessage.
*/
public static HintIconMessage forPlayer(int index) {
return new HintIconMessage(Type.PLAYER, OptionalInt.of(index), Optional.empty());
}
/**
* Creates a HintIconMessage that removes the current Npc hint icon.
*
* @return The HintIconMessage.
*/
public static HintIconMessage resetNpc() {
return forNpc(-1);
}
/**
* Creates a HintIconMessage that removes the current Player hint icon.
*
* @return The HintIconMessage.
*/
public static HintIconMessage resetPlayer() {
return forPlayer(-1);
}
/**
* The index of the Mob, if applicable.
*/
private final OptionalInt index;
/**
* The Position of the tile, if applicable.
*/
private final Optional<Position> position;
/**
* The Type of entity this HintIconMessage is directed at.
*/
@@ -113,33 +83,9 @@ public final class HintIconMessage extends Message {
* Creates the HintIconMessage.
*
* @param type The {@link Type} of this HintIconMessage.
* @param index The index of the Mob, if applicable.
* @param position The Position of the tile, if applicable.
*/
private HintIconMessage(Type type, OptionalInt index, Optional<Position> position) {
protected HintIconMessage(Type type) {
this.type = type;
this.index = index;
this.position = position;
}
/**
* Gets the index of the entity, if applicable.
*
* @return The index.
* @throws NoSuchElementException If no index is available for this HintIcon.
*/
public int getIndex() {
return index.getAsInt();
}
/**
* Gets the {@link Position} of the tile, if applicable.
*
* @return The Position.
* @throws NoSuchElementException If no Position is available for this HintIcon.
*/
public Position getPosition() {
return position.get();
}
/**
@@ -147,7 +93,7 @@ public final class HintIconMessage extends Message {
*
* @return The type.
*/
public Type getType() {
public final Type getType() {
return type;
}
@@ -0,0 +1,73 @@
package org.apollo.game.message.impl;
import org.apollo.game.model.entity.EntityType;
import org.apollo.game.model.entity.Mob;
/**
* A {@link HintIconMessage} which displays a hint over an Npc or Player.
*/
public final class MobHintIconMessage extends HintIconMessage {
/**
* Gets the Type of HintIcon for the specified EntityType.
*
* @param entityType The EntityType.
* @return The HintIcon Type for the EntityType.
*/
private static Type fromEntityType(EntityType entityType) {
switch (entityType) {
case NPC:
return Type.NPC;
case PLAYER:
return Type.PLAYER;
default:
throw new UnsupportedOperationException("Only Mob entities are supported.");
}
}
/**
* Creates a new {@link MobHintIconMessage} for the specified Mob.
*
* @param mob The Mob who will have the HintIcon.
* @return The new {@link MobHintIconMessage}, never {@code null}.
*/
public static MobHintIconMessage create(Mob mob) {
return new MobHintIconMessage(fromEntityType(mob.getEntityType()), mob.getIndex());
}
/**
* Resets the HintIcon for the specified EntityType.
*
* @param type The EntityType to reset the HintIcon for.
* @return The new {@link MobHintIconMessage}, never {@code null}.
*/
public static MobHintIconMessage reset(EntityType type) {
return new MobHintIconMessage(fromEntityType(type), -1);
}
/**
* The index of the Mob.
*/
private final int index;
/**
* Constructs a new {@link MobHintIconMessage} with the specified type.
*
* @param type The type of HintIcon.
* @param index The index of the Mob.
*/
private MobHintIconMessage(Type type, int index) {
super(type);
this.index = index;
}
/**
* Gets the index of the Mob.
*
* @return The index of the Mob.
*/
public int getIndex() {
return index;
}
}
@@ -0,0 +1,80 @@
package org.apollo.game.message.impl;
import org.apollo.game.model.Position;
import com.google.common.base.Preconditions;
/**
* A {@link HintIconMessage} which displays a hint over a Position.
*/
public final class PositionHintIconMessage extends HintIconMessage {
/**
* Represents the default Position a HintIcon is reset to.
*/
private static final Position DEFAULT_POSITION = new Position(0, 0);
/**
* Tests if the specified Type if valid for a Position HintIcon.
*
* @param type The Type to test.
* @return The Type if it was valid.
*/
private static Type testType(Type type) {
Preconditions.checkArgument(type != Type.NPC && type != Type.PLAYER,
"Hint icons over a Position may not have a type of Player or Npc.");
return type;
}
/**
* Creates a new {@link PositionHintIconMessage} which resets the current
* HintIcon.
*
* @return The new {@link PositionHintIconMessage}, never {@code null}.
*/
public static PositionHintIconMessage reset() {
return new PositionHintIconMessage(Type.CENTER, DEFAULT_POSITION, 0);
}
/**
* The Position of the HintIcon.
*/
private final Position position;
/**
* The display height of the HintIcon.
*/
private final int height;
/**
* Constructs a new {@link PositionHintIconMessage}.
*
* @param type The Type of the HintIcon.
* @param position The Position of the hint icon.
* @param height The display height of the hint icon.
*/
public PositionHintIconMessage(Type type, Position position, int height) {
super(testType(type));
this.position = position;
this.height = height;
}
/**
* Gets the Position of the HintIcon.
*
* @return The Position of the HintIcon.
*/
public Position getPosition() {
return position;
}
/**
* Gets the display height of the HintIcon.
*
* @return The display height of the HintIcon.
*/
public int getHeight() {
return height;
}
}
@@ -1,20 +1,21 @@
package org.apollo.game.release.r317;
import org.apollo.game.message.impl.HintIconMessage;
import org.apollo.game.message.impl.MobHintIconMessage;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.release.MessageEncoder;
/**
* A {@link MessageEncoder} for the {@link HintIconMessage}.
* A {@link MessageEncoder} for the {@link MobHintIconMessage}.
*
* @author Major
*/
public final class HintIconMessageEncoder extends MessageEncoder<HintIconMessage> {
public final class MobHintIconMessageEncoder extends MessageEncoder<MobHintIconMessage> {
@Override
public GamePacket encode(HintIconMessage message) {
public GamePacket encode(MobHintIconMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(254);
HintIconMessage.Type type = message.getType();
builder.put(DataType.BYTE, type.getValue());
@@ -0,0 +1,36 @@
package org.apollo.game.release.r317;
import org.apollo.game.message.impl.HintIconMessage;
import org.apollo.game.message.impl.PositionHintIconMessage;
import org.apollo.game.message.impl.HintIconMessage.Type;
import org.apollo.game.model.Position;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.release.MessageEncoder;
/**
* A {@link MessageEncoder} for the {@link PositionHintIconMessage}.
*/
public final class PositionHintIconMessageEncoder extends MessageEncoder<PositionHintIconMessage> {
@Override
public GamePacket encode(PositionHintIconMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(254);
HintIconMessage.Type type = message.getType();
if (type == Type.PLAYER || type == Type.NPC) {
throw new IllegalStateException("Unsupported hint icon type " + type + ".");
}
builder.put(DataType.BYTE, type.getValue());
Position position = message.getPosition();
builder.put(DataType.SHORT, position.getX());
builder.put(DataType.SHORT, position.getY());
builder.put(DataType.BYTE, message.getHeight());
return builder.toGamePacket();
}
}
@@ -10,10 +10,10 @@ import org.apollo.game.message.impl.FlashTabInterfaceMessage;
import org.apollo.game.message.impl.ForwardPrivateChatMessage;
import org.apollo.game.message.impl.FriendServerStatusMessage;
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
import org.apollo.game.message.impl.HintIconMessage;
import org.apollo.game.message.impl.IdAssignmentMessage;
import org.apollo.game.message.impl.IgnoreListMessage;
import org.apollo.game.message.impl.LogoutMessage;
import org.apollo.game.message.impl.MobHintIconMessage;
import org.apollo.game.message.impl.NpcSynchronizationMessage;
import org.apollo.game.message.impl.OpenDialogueInterfaceMessage;
import org.apollo.game.message.impl.OpenDialogueOverlayMessage;
@@ -22,6 +22,7 @@ import org.apollo.game.message.impl.OpenInterfaceSidebarMessage;
import org.apollo.game.message.impl.OpenOverlayMessage;
import org.apollo.game.message.impl.OpenSidebarMessage;
import org.apollo.game.message.impl.PlayerSynchronizationMessage;
import org.apollo.game.message.impl.PositionHintIconMessage;
import org.apollo.game.message.impl.PrivacyOptionMessage;
import org.apollo.game.message.impl.RegionChangeMessage;
import org.apollo.game.message.impl.RemoveObjectMessage;
@@ -222,7 +223,8 @@ public final class Release317 extends Release {
register(FriendServerStatusMessage.class, new FriendServerStatusMessageEncoder());
register(IgnoreListMessage.class, new IgnoreListMessageEncoder());
register(SendFriendMessage.class, new SendFriendMessageEncoder());
register(HintIconMessage.class, new HintIconMessageEncoder());
register(MobHintIconMessage.class, new MobHintIconMessageEncoder());
register(PositionHintIconMessage.class, new PositionHintIconMessageEncoder());
register(FlashTabInterfaceMessage.class, new FlashTabInterfaceMessageEncoder());
register(OpenSidebarMessage.class, new OpenSidebarMessageEncoder());
register(OpenOverlayMessage.class, new OpenOverlayMessageEncoder());
@@ -1,20 +1,21 @@
package org.apollo.game.release.r377;
import org.apollo.game.message.impl.HintIconMessage;
import org.apollo.game.message.impl.MobHintIconMessage;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.release.MessageEncoder;
/**
* A {@link MessageEncoder} for the {@link HintIconMessage}.
* A {@link MessageEncoder} for the {@link MobHintIconMessage}.
*
* @author Major
*/
public final class HintIconMessageEncoder extends MessageEncoder<HintIconMessage> {
public final class MobHintIconMessageEncoder extends MessageEncoder<MobHintIconMessage> {
@Override
public GamePacket encode(HintIconMessage message) {
public GamePacket encode(MobHintIconMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(199);
HintIconMessage.Type type = message.getType();
builder.put(DataType.BYTE, type.getValue());
@@ -0,0 +1,38 @@
package org.apollo.game.release.r377;
import org.apollo.game.message.impl.HintIconMessage;
import org.apollo.game.message.impl.PositionHintIconMessage;
import org.apollo.game.message.impl.HintIconMessage.Type;
import org.apollo.game.model.Position;
import org.apollo.net.codec.game.DataType;
import org.apollo.net.codec.game.GamePacket;
import org.apollo.net.codec.game.GamePacketBuilder;
import org.apollo.net.release.MessageEncoder;
/**
* A {@link MessageEncoder} for the {@link PositionHintIconMessage}.
*
* @author Major
*/
public final class PositionHintIconMessageEncoder extends MessageEncoder<PositionHintIconMessage> {
@Override
public GamePacket encode(PositionHintIconMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(199);
HintIconMessage.Type type = message.getType();
if (type == Type.PLAYER || type == Type.NPC) {
throw new IllegalStateException("Unsupported hint icon type " + type + ".");
}
builder.put(DataType.BYTE, type.getValue());
Position position = message.getPosition();
builder.put(DataType.SHORT, position.getX());
builder.put(DataType.SHORT, position.getY());
builder.put(DataType.BYTE, message.getHeight());
return builder.toGamePacket();
}
}
@@ -10,10 +10,10 @@ import org.apollo.game.message.impl.FlashTabInterfaceMessage;
import org.apollo.game.message.impl.ForwardPrivateChatMessage;
import org.apollo.game.message.impl.FriendServerStatusMessage;
import org.apollo.game.message.impl.GroupedRegionUpdateMessage;
import org.apollo.game.message.impl.HintIconMessage;
import org.apollo.game.message.impl.IdAssignmentMessage;
import org.apollo.game.message.impl.IgnoreListMessage;
import org.apollo.game.message.impl.LogoutMessage;
import org.apollo.game.message.impl.MobHintIconMessage;
import org.apollo.game.message.impl.NpcSynchronizationMessage;
import org.apollo.game.message.impl.OpenDialogueInterfaceMessage;
import org.apollo.game.message.impl.OpenDialogueOverlayMessage;
@@ -22,6 +22,7 @@ import org.apollo.game.message.impl.OpenInterfaceSidebarMessage;
import org.apollo.game.message.impl.OpenOverlayMessage;
import org.apollo.game.message.impl.OpenSidebarMessage;
import org.apollo.game.message.impl.PlayerSynchronizationMessage;
import org.apollo.game.message.impl.PositionHintIconMessage;
import org.apollo.game.message.impl.PrivacyOptionMessage;
import org.apollo.game.message.impl.RegionChangeMessage;
import org.apollo.game.message.impl.RemoveObjectMessage;
@@ -214,7 +215,8 @@ public final class Release377 extends Release {
register(FriendServerStatusMessage.class, new FriendServerStatusMessageEncoder());
register(IgnoreListMessage.class, new IgnoreListMessageEncoder());
register(SendFriendMessage.class, new SendFriendMessageEncoder());
register(HintIconMessage.class, new HintIconMessageEncoder());
register(MobHintIconMessage.class, new MobHintIconMessageEncoder());
register(PositionHintIconMessage.class, new PositionHintIconMessageEncoder());
register(FlashTabInterfaceMessage.class, new FlashTabInterfaceMessageEncoder());
register(OpenSidebarMessage.class, new OpenSidebarMessageEncoder());
register(OpenOverlayMessage.class, new OpenOverlayMessageEncoder());