Search in sources :

Example 1 with ItemDefinition

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

the class ItemDefinitionDecoder method run.

@Override
public void run() {
    try {
        Archive config = fs.getArchive(0, 2);
        ByteBuffer data = config.getEntry("obj.dat").getBuffer();
        ByteBuffer idx = config.getEntry("obj.idx").getBuffer();
        int count = idx.getShort(), index = 2;
        int[] indices = new int[count];
        for (int i = 0; i < count; i++) {
            indices[i] = index;
            index += idx.getShort();
        }
        ItemDefinition[] definitions = new ItemDefinition[count];
        for (int i = 0; i < count; i++) {
            data.position(indices[i]);
            definitions[i] = decode(i, data);
        }
        ItemDefinition.init(definitions);
    } catch (IOException e) {
        throw new UncheckedIOException("Error decoding ItemDefinitions.", e);
    }
}
Also used : Archive(org.apollo.cache.archive.Archive) ItemDefinition(org.apollo.cache.def.ItemDefinition) UncheckedIOException(java.io.UncheckedIOException) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) ByteBuffer(java.nio.ByteBuffer)

Example 2 with ItemDefinition

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

the class EquipmentUpdater method main.

/**
 * The entry point of the application.
 *
 * @param args The command line arguments.
 * @throws Exception If an error occurs.
 */
public static void main(String[] args) throws Exception {
    Preconditions.checkArgument(args.length == 1, "Usage:\njava -cp ... org.apollo.tools.EquipmentUpdater [release].");
    String release = args[0];
    try (DataOutputStream os = new DataOutputStream(new BufferedOutputStream(new FileOutputStream("data/equipment-" + release + ".dat")));
        IndexedFileSystem fs = new IndexedFileSystem(Paths.get("data/fs/", release), true)) {
        ItemDefinitionDecoder decoder = new ItemDefinitionDecoder(fs);
        decoder.run();
        int count = ItemDefinition.count();
        os.writeShort(count);
        for (int id = 0; id < count; id++) {
            ItemDefinition definition = ItemDefinition.lookup(id);
            int type = getWeaponType(definition);
            os.writeByte(type);
            if (type != -1) {
                os.writeBoolean(isTwoHanded(definition));
                os.writeBoolean(isFullBody(definition));
                os.writeBoolean(isFullHat(definition));
                os.writeBoolean(isFullMask(definition));
                os.writeByte(getAttackRequirement(definition));
                os.writeByte(getStrengthRequirement(definition));
                os.writeByte(getDefenceRequirement(definition));
                os.writeByte(getRangedRequirement(definition));
                os.writeByte(getPrayerRequirement(definition));
                os.writeByte(getMagicRequirement(definition));
            }
        }
    }
}
Also used : DataOutputStream(java.io.DataOutputStream) ItemDefinitionDecoder(org.apollo.cache.decoder.ItemDefinitionDecoder) FileOutputStream(java.io.FileOutputStream) ItemDefinition(org.apollo.cache.def.ItemDefinition) IndexedFileSystem(org.apollo.cache.IndexedFileSystem) BufferedOutputStream(java.io.BufferedOutputStream)

Example 3 with ItemDefinition

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

the class ItemOnItemVerificationHandlerTests method setupTestItemDefinitions.

@Before
public void setupTestItemDefinitions() {
    mockStatic(ItemDefinition.class);
    when(ItemDefinition.lookup(4151)).thenReturn(new ItemDefinition(4151));
}
Also used : ItemDefinition(org.apollo.cache.def.ItemDefinition) Before(org.junit.Before)

Example 4 with ItemDefinition

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

the class ItemOnObjectVerificationHandlerTests method setupTestItemDefinitions.

@Before
public void setupTestItemDefinitions() {
    mockStatic(ItemDefinition.class);
    when(ItemDefinition.lookup(4151)).thenReturn(new ItemDefinition(4151));
    mockStatic(ObjectDefinition.class);
    when(ObjectDefinition.count()).thenReturn(2);
}
Also used : ItemDefinition(org.apollo.cache.def.ItemDefinition) Before(org.junit.Before)

Example 5 with ItemDefinition

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

the class Inventory method remove.

/**
 * Removes {@code amount} of the item with the specified {@code id}. If the item is stackable, it will remove it
 * from the stack. If not, it'll remove {@code amount} items.
 *
 * @param id The id.
 * @param amount The amount.
 * @return The amount that was removed.
 */
public int remove(int id, int amount) {
    ItemDefinition def = ItemDefinition.lookup(id);
    boolean stackable = isStackable(def);
    if (stackable) {
        int slot = slotOf(id);
        if (slot != -1) {
            Item item = items[slot];
            if (amount >= item.getAmount()) {
                set(slot, null);
                return item.getAmount();
            }
            set(slot, new Item(item.getId(), item.getAmount() - amount));
            return amount;
        }
        return 0;
    }
    int removed = 0;
    stopFiringEvents();
    try {
        for (int slot = 0; slot < capacity; slot++) {
            Item item = items[slot];
            if (item != null && item.getId() == id) {
                set(slot, null);
                if (++removed >= amount) {
                    break;
                }
            }
        }
    } finally {
        startFiringEvents();
        if (removed > 0) {
            notifyItemsUpdated();
        }
    }
    return removed;
}
Also used : Item(org.apollo.game.model.Item) 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