1package com.runehive.game.world.items;
3import com.google.common.collect.Iterables;
4import com.runehive.game.world.entity.combat.attack.FightType;
5import com.runehive.game.world.entity.combat.ranged.RangedWeaponDefinition;
6import com.runehive.game.world.entity.combat.weapon.WeaponInterface;
7import com.runehive.game.world.items.containers.equipment.EquipmentType;
8import com.runehive.game.world.items.containers.pricechecker.PriceType;
9import com.runehive.util.Utility;
11import java.util.ArrayList;
13import java.util.Optional;
14import java.util.OptionalInt;
21public class Item implements Cloneable {
45 public Item(
int id,
int minAmt,
int maxAmt) {
46 if (minAmt < 0 || maxAmt < 0)
amount = 0;
55 }
else if (
amount > Integer.MAX_VALUE) {
56 amount2 = Integer.MAX_VALUE;
61 this.amount = amount2;
66 return (
Item) super.clone();
67 }
catch (CloneNotSupportedException e) {
106 return def.getValue();
107 case HIGH_ALCH_VALUE:
108 return def.getHighAlch();
110 return def.getLowAlch();
117 return (
int) Math.floor(
getValue() / 2);
130 return def.getValue();
159 if (
amount == newAmount) {
162 return new Item(
id, newAmount);
179 int newAmount =
amount + addAmount;
182 newAmount = Integer.MAX_VALUE;
199 if (removeAmount < 0) {
203 int newAmount =
amount - removeAmount;
206 if (newAmount < 1 || newAmount >
amount) {
211 clone.setAmount(newAmount);
231 List<Integer> values =
new ArrayList<>();
232 for (
Item identifier : ids) {
233 values.add(identifier.getId());
235 return values.stream().mapToInt(Integer::intValue).toArray();
245 List<Item>
items =
new ArrayList<>();
246 for (
int identifier :
id) {
249 return Iterables.toArray(
items,
Item.class);
260 return item !=
null && item.id > 0 && item.id < ItemDefinition.DEFINITIONS.length && item.
getDefinition() !=
null;
303 if ((this.amount -
amount) < 1) {
462 return other !=
null &&
id == other.
id;
466 return this.id ==
id;
471 return String.format(
"item[id=%d amount=%d]",
id,
amount);
476 if (obj instanceof
Item) {
478 return other.id ==
id && other.amount ==
amount;
485 return amount << 16 |
id & 0xFFFF;
Represents all of an in-game Item's attributes.
boolean isNoted()
Gets the item note state.
static ItemDefinition get(int id)
Gets an item definition.
String getDestroyMessage()
Gets the item destroy message.
String getName()
Gets the item name.
final void setAmount(int amount)
Sets the quantity of this item.
static final int[] convert(Item... ids)
Converts an Item array into an Integer array.
Optional< RangedWeaponDefinition > getRangedDefinition()
final int getId()
Gets the identification of this item.
final void decrementAmount()
Decrements the amount by 1.
int getValue()
Gets the value for this item.
Item(int id, long amount)
static boolean valid(Item item)
Determines if item is valid.
Item createWithId(int newId)
Creates a new item with newId and the same amount as this instance.
final int getAmount()
Gets the quantity of this item.
int id
The identification of this item.
Item noted()
Gets the item note item.
Item copy()
A substitute for Object#clone() that creates another 'copy' of this instance.
ItemDefinition getDefinition()
Gets the item definition for the item identifier.
Item createAndIncrement(int addAmount)
Creates a new item with amount + addAmount and the same identifier.
int getValue(PriceType type)
Gets the value for this item.
final void decrementAmountBy(int amount)
Decrements the amount by amount @endiliteral.
Item(int id, int minAmt, int maxAmt)
Creates a new Item with a random amount between minAmt and maxAmt.
Item createWithAmount(int newAmount)
Creates a new item with newAmount and the same identifier as this instance.
boolean equals(Object obj)
WeaponInterface getWeaponInterface()
OptionalInt getAttackAnimation(FightType type)
OptionalInt getBlockAnimation()
final void incrementAmount()
Increments the amount by 1.
String getDestroyMessage()
int amount
The quantity of this item.
Item(int id)
Creates a new Item with an quantity of 1.
boolean equalIds(Item other)
Item unnoted()
Gets the unnoted item.
final void setId(int id)
Sets the identification of this item.
static final Item[] convert(int... id)
Converts an int array into an Item array.
final void incrementAmountBy(int amount)
Increments the amount by amount.
boolean matchesId(int id)
EquipmentType getEquipmentType()
Item createAndDecrement(int removeAmount)
Creates a new item with amount - removeAmount and the same identifier.
Item(int id, int amount)
Creates a new Item.
Handles miscellaneous methods.
static int random(int bound)
The enumerated type whose elements represent the fighting types.
The enumerated type whose elements represent the weapon interfaces.
The enumerated types of a players equipped item slots.