Search in sources :

Example 6 with ItemDefinition

use of org.apollo.cache.def.ItemDefinition in project apollo by apollo-rsps.

the class ItemDefinitionDecoder method decode.

/**
 * Decodes a single definition.
 *
 * @param id The item's id.
 * @param buffer The buffer.
 * @return The {@link ItemDefinition}.
 */
private ItemDefinition decode(int id, ByteBuffer buffer) {
    ItemDefinition definition = new ItemDefinition(id);
    while (true) {
        int opcode = buffer.get() & 0xFF;
        if (opcode == 0) {
            return definition;
        } else if (opcode == 1) {
            buffer.getShort();
        } else if (opcode == 2) {
            definition.setName(BufferUtil.readString(buffer));
        } else if (opcode == 3) {
            definition.setDescription(BufferUtil.readString(buffer));
        } else if (opcode >= 4 && opcode <= 8 || opcode == 10) {
            buffer.getShort();
        } else if (opcode == 11) {
            definition.setStackable(true);
        } else if (opcode == 12) {
            definition.setValue(buffer.getInt());
        } else if (opcode == 16) {
            definition.setMembersOnly(true);
        } else if (opcode == 23) {
            buffer.getShort();
            buffer.get();
        } else if (opcode == 24) {
            buffer.getShort();
        } else if (opcode == 25) {
            buffer.getShort();
            buffer.get();
        } else if (opcode == 26) {
            buffer.getShort();
        } else if (opcode >= 30 && opcode < 35) {
            String str = BufferUtil.readString(buffer);
            if (str.equalsIgnoreCase("hidden")) {
                str = null;
            }
            definition.setGroundAction(opcode - 30, str);
        } else if (opcode >= 35 && opcode < 40) {
            definition.setInventoryAction(opcode - 35, BufferUtil.readString(buffer));
        } else if (opcode == 40) {
            int colourCount = buffer.get() & 0xFF;
            for (int i = 0; i < colourCount; i++) {
                buffer.getShort();
                buffer.getShort();
            }
        } else if (opcode == 78 || opcode == 79 || (opcode >= 90 && opcode <= 93) || opcode == 95) {
            buffer.getShort();
        } else if (opcode == 97) {
            definition.setNoteInfoId(buffer.getShort() & 0xFFFF);
        } else if (opcode == 98) {
            definition.setNoteGraphicId(buffer.getShort() & 0xFFFF);
        } else if (opcode >= 100 && opcode < 110) {
            buffer.getShort();
            buffer.getShort();
        } else if (opcode >= 110 && opcode <= 112) {
            buffer.getShort();
        } else if (opcode == 113 || opcode == 114) {
            buffer.get();
        } else if (opcode == 115) {
            definition.setTeam(buffer.get() & 0xFF);
        }
    }
}
Also used : ItemDefinition(org.apollo.cache.def.ItemDefinition)

Aggregations

ItemDefinition (org.apollo.cache.def.ItemDefinition)6 Before (org.junit.Before)2 BufferedOutputStream (java.io.BufferedOutputStream)1 DataOutputStream (java.io.DataOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 UncheckedIOException (java.io.UncheckedIOException)1 ByteBuffer (java.nio.ByteBuffer)1 IndexedFileSystem (org.apollo.cache.IndexedFileSystem)1 Archive (org.apollo.cache.archive.Archive)1 ItemDefinitionDecoder (org.apollo.cache.decoder.ItemDefinitionDecoder)1 Item (org.apollo.game.model.Item)1