Search in sources :

Example 36 with GamePacketBuilder

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();
}
Also used : GamePacket(org.apollo.net.codec.game.GamePacket) Position(org.apollo.game.model.Position) RegionUpdateMessage(org.apollo.game.message.impl.RegionUpdateMessage) GroupedRegionUpdateMessage(org.apollo.game.message.impl.GroupedRegionUpdateMessage) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) MessageEncoder(org.apollo.net.release.MessageEncoder)

Example 37 with GamePacketBuilder

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();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 38 with GamePacketBuilder

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();
}
Also used : GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) HintIconMessage(org.apollo.game.message.impl.HintIconMessage) MobHintIconMessage(org.apollo.game.message.impl.MobHintIconMessage)

Example 39 with GamePacketBuilder

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();
}
Also used : Item(org.apollo.game.model.Item) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder)

Example 40 with GamePacketBuilder

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();
}
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