use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class OpenSidebarMessageEncoder method encode.
@Override
public GamePacket encode(OpenSidebarMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(142);
builder.put(DataType.SHORT, DataOrder.LITTLE, message.getSidebarId());
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method putAppearanceBlock.
/**
* Puts an appearance block into the specified builder.
*
* @param block The block.
* @param builder The builder.
*/
private static void putAppearanceBlock(AppearanceBlock block, GamePacketBuilder builder) {
Appearance appearance = block.getAppearance();
GamePacketBuilder playerProperties = new GamePacketBuilder();
playerProperties.put(DataType.BYTE, appearance.getGender().toInteger());
playerProperties.put(DataType.BYTE, 0);
if (block.appearingAsNpc()) {
playerProperties.put(DataType.BYTE, 255);
playerProperties.put(DataType.BYTE, 255);
playerProperties.put(DataType.SHORT, block.getNpcId());
} else {
Inventory equipment = block.getEquipment();
int[] style = appearance.getStyle();
Item item, chest, helm;
for (int slot = 0; slot < 4; slot++) {
if ((item = equipment.get(slot)) != null) {
playerProperties.put(DataType.SHORT, 0x200 + item.getId());
} else {
playerProperties.put(DataType.BYTE, 0);
}
}
if ((chest = equipment.get(EquipmentConstants.CHEST)) != null) {
playerProperties.put(DataType.SHORT, 0x200 + chest.getId());
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[2]);
}
if ((item = equipment.get(EquipmentConstants.SHIELD)) != null) {
playerProperties.put(DataType.SHORT, 0x200 + item.getId());
} else {
playerProperties.put(DataType.BYTE, 0);
}
if (chest != null) {
EquipmentDefinition def = EquipmentDefinition.lookup(chest.getId());
if (def != null && !def.isFullBody()) {
playerProperties.put(DataType.SHORT, 0x100 + style[3]);
} else {
playerProperties.put(DataType.BYTE, 0);
}
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[3]);
}
if ((item = equipment.get(EquipmentConstants.LEGS)) != null) {
playerProperties.put(DataType.SHORT, 0x200 + item.getId());
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[5]);
}
if ((helm = equipment.get(EquipmentConstants.HAT)) != null) {
EquipmentDefinition def = EquipmentDefinition.lookup(helm.getId());
if (def != null && !def.isFullHat() && !def.isFullMask()) {
playerProperties.put(DataType.SHORT, 0x100 + style[0]);
} else {
playerProperties.put(DataType.BYTE, 0);
}
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[0]);
}
if ((item = equipment.get(EquipmentConstants.HANDS)) != null) {
playerProperties.put(DataType.SHORT, 0x200 + item.getId());
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[4]);
}
if ((item = equipment.get(EquipmentConstants.FEET)) != null) {
playerProperties.put(DataType.SHORT, 0x200 + item.getId());
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[6]);
}
EquipmentDefinition def = null;
if (helm != null) {
def = EquipmentDefinition.lookup(helm.getId());
}
if (def != null && (def.isFullMask()) || appearance.getGender() == Gender.FEMALE) {
playerProperties.put(DataType.BYTE, 0);
} else {
playerProperties.put(DataType.SHORT, 0x100 + style[1]);
}
}
int[] colors = appearance.getColors();
for (int color : colors) {
playerProperties.put(DataType.BYTE, color);
}
// stand
playerProperties.put(DataType.SHORT, 0x328);
// stand turn
playerProperties.put(DataType.SHORT, 0x337);
// walk
playerProperties.put(DataType.SHORT, 0x333);
// turn 180
playerProperties.put(DataType.SHORT, 0x334);
// turn 90 cw
playerProperties.put(DataType.SHORT, 0x335);
// turn 90 ccw
playerProperties.put(DataType.SHORT, 0x336);
// run
playerProperties.put(DataType.SHORT, 0x338);
playerProperties.put(DataType.LONG, block.getName());
playerProperties.put(DataType.BYTE, block.getCombatLevel());
playerProperties.put(DataType.SHORT, block.getSkillLevel());
builder.put(DataType.BYTE, DataTransformation.NEGATE, playerProperties.getLength());
builder.putRawBuilder(playerProperties);
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class PlayerSynchronizationMessageEncoder method encode.
@Override
public GamePacket encode(PlayerSynchronizationMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(81, PacketType.VARIABLE_SHORT);
builder.switchToBitAccess();
GamePacketBuilder blockBuilder = new GamePacketBuilder();
putMovementUpdate(message.getSegment(), message, builder);
putBlocks(message.getSegment(), blockBuilder);
builder.putBits(8, message.getLocalPlayers());
for (SynchronizationSegment segment : message.getSegments()) {
SegmentType type = segment.getType();
if (type == SegmentType.REMOVE_MOB) {
putRemovePlayerUpdate(builder);
} else if (type == SegmentType.ADD_MOB) {
putAddPlayerUpdate((AddPlayerSegment) segment, message, builder);
putBlocks(segment, blockBuilder);
} else {
putMovementUpdate(segment, message, builder);
putBlocks(segment, blockBuilder);
}
}
if (blockBuilder.getLength() > 0) {
builder.putBits(11, 2047);
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 OpenDialogueInterfaceMessageEncoder method encode.
@Override
public GamePacket encode(OpenDialogueInterfaceMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(164);
builder.put(DataType.SHORT, DataOrder.LITTLE, message.getInterfaceId());
return builder.toGamePacket();
}
use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.
the class OpenInterfaceMessageEncoder method encode.
@Override
public GamePacket encode(OpenInterfaceMessage message) {
GamePacketBuilder builder = new GamePacketBuilder(97);
builder.put(DataType.SHORT, message.getId());
return builder.toGamePacket();
}
Aggregations