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(183, PacketType.VARIABLE_SHORT);
Position base = message.getLastKnownRegion(), region = message.getRegionPosition();
builder.put(DataType.BYTE, region.getLocalX(base));
builder.put(DataType.BYTE, DataTransformation.ADD, region.getLocalY(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 IgnoreListMessageEncoder method encode.
@Override
public GamePacket encode(IgnoreListMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(226);
List<String> usernames = message.getUsernames();
for (String username : usernames) {
builder.put(DataType.LONG, NameUtil.encodeBase37(username));
}
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class MobHintIconMessageEncoder method encode.
@Override
public GamePacket encode(MobHintIconMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(199);
HintIconMessage.Type type = message.getType();
builder.put(DataType.BYTE, type.getValue());
switch(type) {
case NPC:
case PLAYER:
builder.put(DataType.SHORT, message.getIndex());
// Dummy bytes
builder.put(DataType.TRI_BYTE, 0);
break;
default:
throw new IllegalStateException("Unsupported hint icon type " + type + ".");
}
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class UpdateItemsMessageEncoder method encode.
@Override
public GamePacket encode(UpdateItemsMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(53, PacketType.VARIABLE_SHORT);
Item[] items = message.getItems();
builder.put(DataType.SHORT, message.getInterfaceId());
builder.put(DataType.SHORT, items.length);
for (Item item : items) {
int id = item == null ? -1 : item.getId();
int amount = item == null ? 0 : item.getAmount();
if (amount > 254) {
builder.put(DataType.BYTE, 255);
builder.put(DataType.INT, DataOrder.INVERSED_MIDDLE, amount);
} else {
builder.put(DataType.BYTE, amount);
}
builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, id + 1);
}
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class UpdateTileItemMessageEncoder method encode.
@Override
public GamePacket encode(UpdateTileItemMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(84);
builder.put(DataType.BYTE, message.getPositionOffset());
builder.put(DataType.SHORT, message.getId());
builder.put(DataType.SHORT, message.getPreviousAmount());
builder.put(DataType.SHORT, message.getAmount());
return builder.toGamePacket();
}
Aggregations