Search in sources :

Example 21 with GamePacketBuilder

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, block.isSkulled() ? 1 : -1);
    playerProperties.put(DataType.BYTE, block.getHeadIcon());
    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, playerProperties.getLength());
    builder.putRawBuilderReverse(playerProperties);
}
Also used : Item(org.apollo.game.model.Item) EquipmentDefinition(org.apollo.cache.def.EquipmentDefinition) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) Appearance(org.apollo.game.model.Appearance) Inventory(org.apollo.game.model.inv.Inventory)

Example 22 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class SetWidgetVisibilityMessageEncoder method encode.

@Override
public GamePacket encode(SetWidgetVisibilityMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(82);
    builder.put(DataType.BYTE, message.isVisible() ? 0 : 1);
    builder.put(DataType.SHORT, message.getWidgetId());
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 23 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class UpdateSkillMessageEncoder method encode.

@Override
public GamePacket encode(UpdateSkillMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(49);
    Skill skill = message.getSkill();
    builder.put(DataType.BYTE, DataTransformation.NEGATE, message.getId());
    builder.put(DataType.BYTE, skill.getCurrentLevel());
    builder.put(DataType.INT, (int) skill.getExperience());
    return builder.toGamePacket();
}
Also used : Skill(org.apollo.game.model.entity.Skill) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 24 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class SetUpdatedRegionMessageEncoder method encode.

@Override
public GamePacket encode(SetUpdatedRegionMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(75);
    Position base = message.getPlayerPosition(), position = message.getRegionPosition();
    builder.put(DataType.BYTE, DataTransformation.NEGATE, position.getLocalX(base));
    builder.put(DataType.BYTE, DataTransformation.ADD, position.getLocalY(base));
    return builder.toGamePacket();
}
Also used : Position(org.apollo.game.model.Position) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 25 with GamePacketBuilder

use of org.apollo.net.codec.game.GamePacketBuilder in project apollo by apollo-rsps.

the class SetWidgetModelAnimationMessageEncoder method encode.

@Override
public GamePacket encode(SetWidgetModelAnimationMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(2);
    builder.put(DataType.SHORT, DataOrder.LITTLE, DataTransformation.ADD, message.getInterfaceId());
    builder.put(DataType.SHORT, DataTransformation.ADD, message.getAnimation() & 0xFFFF);
    return builder.toGamePacket();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Aggregations

GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)93 Position (org.apollo.game.model.Position)9 Item (org.apollo.game.model.Item)6 HintIconMessage (org.apollo.game.message.impl.HintIconMessage)4 SegmentType (org.apollo.game.sync.seg.SegmentType)4 SynchronizationSegment (org.apollo.game.sync.seg.SynchronizationSegment)4 EquipmentDefinition (org.apollo.cache.def.EquipmentDefinition)2 GroupedRegionUpdateMessage (org.apollo.game.message.impl.GroupedRegionUpdateMessage)2 Type (org.apollo.game.message.impl.HintIconMessage.Type)2 MobHintIconMessage (org.apollo.game.message.impl.MobHintIconMessage)2 PositionHintIconMessage (org.apollo.game.message.impl.PositionHintIconMessage)2 RegionUpdateMessage (org.apollo.game.message.impl.RegionUpdateMessage)2 Appearance (org.apollo.game.model.Appearance)2 Skill (org.apollo.game.model.entity.Skill)2 Inventory (org.apollo.game.model.inv.Inventory)2 SlottedItem (org.apollo.game.model.inv.SlottedItem)2 AddNpcSegment (org.apollo.game.sync.seg.AddNpcSegment)2 AddPlayerSegment (org.apollo.game.sync.seg.AddPlayerSegment)2 GamePacket (org.apollo.net.codec.game.GamePacket)2 MessageEncoder (org.apollo.net.release.MessageEncoder)2