Search in sources :

Example 1 with SlottedItem

use of org.apollo.game.model.inv.SlottedItem in project apollo by apollo-rsps.

the class UpdateSlottedItemsMessageEncoder method encode.

@Override
public GamePacket encode(UpdateSlottedItemsMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(134, PacketType.VARIABLE_SHORT);
    SlottedItem[] items = message.getSlottedItems();
    builder.put(DataType.SHORT, message.getInterfaceId());
    for (SlottedItem slottedItem : items) {
        builder.putSmart(slottedItem.getSlot());
        Item item = slottedItem.getItem();
        int id = item == null ? -1 : item.getId();
        int amount = item == null ? 0 : item.getAmount();
        builder.put(DataType.SHORT, id + 1);
        if (amount > 254) {
            builder.put(DataType.BYTE, 255);
            builder.put(DataType.INT, amount);
        } else {
            builder.put(DataType.BYTE, amount);
        }
    }
    return builder.toGamePacket();
}
Also used : SlottedItem(org.apollo.game.model.inv.SlottedItem) Item(org.apollo.game.model.Item) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) SlottedItem(org.apollo.game.model.inv.SlottedItem)

Example 2 with SlottedItem

use of org.apollo.game.model.inv.SlottedItem in project apollo by apollo-rsps.

the class UpdateSlottedItemsMessageEncoder method encode.

@Override
public GamePacket encode(UpdateSlottedItemsMessage message) {
    GamePacketBuilder builder = new GamePacketBuilder(34, PacketType.VARIABLE_SHORT);
    SlottedItem[] items = message.getSlottedItems();
    builder.put(DataType.SHORT, message.getInterfaceId());
    for (SlottedItem slottedItem : items) {
        builder.putSmart(slottedItem.getSlot());
        Item item = slottedItem.getItem();
        int id = item == null ? -1 : item.getId();
        int amount = item == null ? 0 : item.getAmount();
        builder.put(DataType.SHORT, id + 1);
        if (amount > 254) {
            builder.put(DataType.BYTE, 255);
            builder.put(DataType.INT, amount);
        } else {
            builder.put(DataType.BYTE, amount);
        }
    }
    return builder.toGamePacket();
}
Also used : SlottedItem(org.apollo.game.model.inv.SlottedItem) Item(org.apollo.game.model.Item) GamePacketBuilder(org.apollo.net.codec.game.GamePacketBuilder) SlottedItem(org.apollo.game.model.inv.SlottedItem)

Aggregations

Item (org.apollo.game.model.Item)2 SlottedItem (org.apollo.game.model.inv.SlottedItem)2 GamePacketBuilder (org.apollo.net.codec.game.GamePacketBuilder)2