use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putTurnToPositionBlock.
/**
* Puts a Turn To Position block into the specified builder.
*
* @param block The block.
* @param builder The builder.
*/
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position pos = block.getPosition();
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, pos.getX() * 2 + 1);
builder.put(DataType.SHORT, DataOrder.LITTLE, pos.getY() * 2 + 1);
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PositionHintIconMessageEncoder method encode.
@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();
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class GroupedRegionUpdateMessageEncoder method encode.
@Override
public GamePacket encode(GroupedRegionUpdateMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(60, PacketType.VARIABLE_SHORT);
Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
builder.put(DataType.BYTE, region.getLocalY(base));
builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(base));
for (RegionUpdateMessage update : message.getMessages()) {
@SuppressWarnings("unchecked") MessageEncoder<RegionUpdateMessage> encoder = (MessageEncoder<RegionUpdateMessage>) release.getMessageEncoder(update.getClass());
GamePacket packet = encoder.encode(update);
builder.put(DataType.BYTE, packet.getOpcode());
builder.putBytes(packet.getPayload());
}
return builder.toGamePacket();
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class ClearRegionMessageEncoder method encode.
@Override
public GamePacket encode(ClearRegionMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(64);
Position player = message.getPlayerPosition(), region = message.getRegionPosition();
builder.put(DataType.BYTE, DataTransformation.NEGATE, region.getLocalX(player));
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, region.getLocalY(player));
return builder.toGamePacket();
}
use of org.apollo.game.model.Position in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putTurnToPositionBlock.
/**
* Puts a turn to position block into the specified builder.
*
* @param block The block.
* @param builder The builder.
*/
private static void putTurnToPositionBlock(TurnToPositionBlock block, GamePacketBuilder builder) {
Position position = block.getPosition();
builder.put(DataType.SHORT, position.getX() * 2 + 1);
builder.put(DataType.SHORT, position.getY() * 2 + 1);
}
Aggregations