use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class NpcSynchronizationMessageEncoder method encode.
@Override
public GamePacket encode(NpcSynchronizationMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(65, PacketType.VARIABLE_SHORT);
builder.switchToBitAccess();
GamePacketBuilder blockBuilder = new GamePacketBuilder();
builder.putBits(8, message.getLocalNpcCount());
for (SynchronizationSegment segment : message.getSegments()) {
SegmentType type = segment.getType();
if (type == SegmentType.REMOVE_MOB) {
putRemoveMobUpdate(builder);
} else if (type == SegmentType.ADD_MOB) {
putAddNpcUpdate((AddNpcSegment) segment, message, builder);
putBlocks(segment, blockBuilder);
} else {
putMovementUpdate(segment, message, builder);
putBlocks(segment, blockBuilder);
}
}
if (blockBuilder.getLength() > 0) {
builder.putBits(14, 16383);
builder.switchToByteAccess();
builder.putRawBuilder(blockBuilder);
} else {
builder.switchToByteAccess();
}
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class OpenDialogueOverlayMessageEncoder method encode.
@Override
public GamePacket encode(OpenDialogueOverlayMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(218);
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId());
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class FlashTabInterfaceMessageEncoder method encode.
@Override
public GamePacket encode(FlashTabInterfaceMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(24);
builder.put(DataType.BYTE, DataTransformation.SUBTRACT, message.getTab());
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class ConfigMessageEncoder method encode.
@Override
public GamePacket encode(ConfigMessage message) {
GamePacketBuilder builder;
int value = message.getValue();
if (value > Byte.MIN_VALUE && value < Byte.MAX_VALUE) {
builder = new GamePacketBuilder(36);
builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId());
builder.put(DataType.BYTE, value & 0xFF);
} else {
builder = new GamePacketBuilder(87);
builder.put(DataType.SHORT, DataOrder.LITTLE, message.getId());
builder.put(DataType.INT, DataOrder.MIDDLE, value);
}
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder 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();
}
Aggregations