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