use of org.apollo.net.codec.game.GamePacketBuilder 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.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class RegionChangeMessageEncoder method encode.
@Override
public GamePacket encode(RegionChangeMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(73);
builder.put(DataType.SHORT, DataTransformation.ADD, message.getPosition().getCentralRegionX());
builder.put(DataType.SHORT, message.getPosition().getCentralRegionY());
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class ForwardPrivateChatMessageEncoder method encode.
@Override
public GamePacket encode(ForwardPrivateChatMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(196, PacketType.VARIABLE_BYTE);
builder.put(DataType.LONG, NameUtil.encodeBase37(message.getSenderUsername()));
builder.put(DataType.INT, messageCounter.incrementAndGet());
builder.put(DataType.BYTE, message.getSenderPrivilege().toInteger());
builder.putBytes(message.getCompressedMessage());
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder 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.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class IdAssignmentMessageEncoder method encode.
@Override
public GamePacket encode(IdAssignmentMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(249);
builder.put(DataType.BYTE, DataTransformation.ADD, message.isMembers() ? 1 : 0);
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getId());
return builder.toGamePacket();
}
Aggregations