public void encode( PlayerUpdateMessage message, GameFrameBuilder builder, GameFrameBuilder blockBuilder) { encodeDescriptor(message, builder, blockBuilder); if (isBlockUpdatedRequired()) { int flags = 0; for (PlayerBlock block : blocks.values()) flags |= block.getFlag(); if (flags > 0xFF) { flags |= 0x10; blockBuilder.put(DataType.SHORT, DataOrder.LITTLE, flags); } else { blockBuilder.put(DataType.BYTE, flags); } encodeBlock(message, blockBuilder, ChatPlayerBlock.class); encodeBlock(message, blockBuilder, HitOnePlayerBlock.class); encodeBlock(message, blockBuilder, AnimationPlayerBlock.class); encodeBlock(message, blockBuilder, AppearancePlayerBlock.class); encodeBlock(message, blockBuilder, TurnToMobPlayerBlock.class); encodeBlock(message, blockBuilder, ForceMovementPlayerBlock.class); encodeBlock(message, blockBuilder, ForceChatPlayerBlock.class); encodeBlock(message, blockBuilder, HitTwoPlayerBlock.class); // encodeBlock(message, blockBuilder, ???.class); //0x800 encodeBlock(message, blockBuilder, SpotAnimationPlayerBlock.class); encodeBlock(message, blockBuilder, TurnToPositionPlayerBlock.class); } }
@Override public GameFrame encode(ByteBufAllocator alloc, PrivateChatSentMessage message) { GameFrameBuilder builder = new GameFrameBuilder(alloc, 71, Type.VARIABLE_BYTE); builder.put(DataType.LONG, message.getName()); // builder.put(DataType.BYTE, message.getPacked().length); builder.putBytes(message.getPacked()); return builder.toGameFrame(); }
public void putRawBuilder(GameFrameBuilder builder) { checkByteAccess(); if (builder.type != Type.RAW) { throw new IllegalArgumentException("Builder must be raw!"); } builder.checkByteAccess(); putBytes(builder.buffer); }
public void putRawBuilder(GameFrameBuilder builder, DataTransformation transformation) { checkByteAccess(); if (builder.type != Type.RAW) { throw new IllegalArgumentException("Builder must be raw!"); } builder.checkByteAccess(); byte[] tmp = new byte[builder.buffer.readableBytes()]; builder.buffer.readBytes(tmp); putBytes(transformation, tmp); }
@Override public void encode(PlayerUpdateMessage message, GameFrameBuilder builder) { Gender gender = appearance.getGender(); GameFrameBuilder propertiesBuilder = new GameFrameBuilder(builder.getAllocator()); /* * flags field: bit 0 - gender (0 = male, 1 = female) bit 1 - unused bit 2 - show skill * level instead of combat level bit 3-5 - unknown bit 6-7 - unknown */ int flags = gender.ordinal(); propertiesBuilder.put(DataType.BYTE, flags); propertiesBuilder.put(DataType.BYTE, -1); // pk icon propertiesBuilder.put(DataType.BYTE, headIcon.getIconId()); if (hidden) { for (int i = 0; i < 12; i++) { propertiesBuilder.put(DataType.BYTE, 0); } } else { if (pnpc > -1) { propertiesBuilder.put(DataType.SHORT, -1); propertiesBuilder.put(DataType.SHORT, pnpc); propertiesBuilder.put(DataType.BYTE, 255); } else { Item item = equipment.get(Equipment.HEAD); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.BYTE, 0); } item = equipment.get(Equipment.CAPE); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.BYTE, 0); } item = equipment.get(Equipment.NECK); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.BYTE, 0); } item = equipment.get(Equipment.WEAPON); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 + EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.BYTE, 0); } item = equipment.get(Equipment.BODY); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.TORSO)); } item = equipment.get(Equipment.SHIELD); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.BYTE, 0); } boolean fullBody = false; item = equipment.get(Equipment.BODY); if (item != null) fullBody = EquipmentDefinition.forId(item.getId()).isFullBody(); if (!fullBody) { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.ARMS)); } else { propertiesBuilder.put(DataType.BYTE, 0); } item = equipment.get(Equipment.LEGS); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.LEGS)); } boolean fullHelm = false, fullMask = false; item = equipment.get(Equipment.HEAD); if (item != null) { fullHelm = EquipmentDefinition.forId(item.getId()).isFullHelm(); fullMask = EquipmentDefinition.forId(item.getId()).isFullMask(); } if (!fullHelm) { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.HAIR)); } else { propertiesBuilder.put(DataType.BYTE, 0); } item = equipment.get(Equipment.HANDS); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.WRISTS)); } item = equipment.get(Equipment.FEET); if (item != null) { propertiesBuilder.put( DataType.SHORT, 0x8000 | EquipmentDefinition.forId(item.getId()).getEquipmentId()); } else { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.FEET)); } item = equipment.get(Equipment.HEAD); // TODO check if (gender == Gender.MALE && !fullMask) { propertiesBuilder.put(DataType.SHORT, 0x100 | appearance.getStyle(Feature.FACIAL_HAIR)); } else { propertiesBuilder.put(DataType.BYTE, 0); } } } propertiesBuilder.put(DataType.BYTE, appearance.getColor(Feature.HAIR)); propertiesBuilder.put(DataType.BYTE, appearance.getColor(Feature.TORSO)); propertiesBuilder.put(DataType.BYTE, appearance.getColor(Feature.LEGS)); propertiesBuilder.put(DataType.BYTE, appearance.getColor(Feature.FEET)); propertiesBuilder.put(DataType.BYTE, appearance.getColor(Feature.SKIN)); propertiesBuilder.put(DataType.SHORT, stance); propertiesBuilder.put(DataType.LONG, Base37Utils.encodeBase37(username)); propertiesBuilder.put(DataType.BYTE, combat); if ((flags & 0x4) != 0) { propertiesBuilder.put(DataType.SHORT, skill); } else { propertiesBuilder.put(DataType.BYTE, 0); propertiesBuilder.put(DataType.BYTE, 0); } propertiesBuilder.put(DataType.BYTE, 0); /* if the above byte is non-zero, four unknown shorts are written */ builder.put(DataType.BYTE, DataTransformation.ADD, propertiesBuilder.getLength()); builder.putRawBuilder(propertiesBuilder); }
@Override public void encode(PlayerUpdateMessage message, GameFrameBuilder builder) { builder.put(DataType.SHORT, DataTransformation.ADD, turnToTarget); }