/** * Equips the item from a given slot. * * @param index the item index * @param slot the item slot */ public Equipment equip(int index, int slot) { if (!checkRequirements(index)) { return this; } Item item = player().getInventory().items()[slot].copy(); if (item.getIndex() != index) { return this; } int equipmentSlot = ItemDefinition.get(index).equipmentSlot(); if (ItemDefinition.get(index).twoHanded() && equipmentSlot == WEAPON_SLOT && items()[SHIELD_SLOT].getIndex() != -1) { if (player().getInventory().freeSpace() == 0) { player().getInventory().noSpace(); return this; } else { player() .getInventory() .add(items()[SHIELD_SLOT].getIndex(), items()[SHIELD_SLOT].getAmount(), false); set(SHIELD_SLOT, -1, 0); } } Item unequipItem = null; if (ItemDefinition.get(index).stackable() && items()[equipmentSlot].getIndex() == index) { long totalAmount = (long) item.getAmount() + (long) items()[equipmentSlot].getAmount(); if (totalAmount > Integer.MAX_VALUE) { item.setAmount(Integer.MAX_VALUE); unequipItem = items()[equipmentSlot].copy().setAmount((int) (totalAmount - Integer.MAX_VALUE)); } else { item.setAmount((int) totalAmount); } } else { if (equipmentSlot == SHIELD_SLOT && ItemDefinition.get(items()[WEAPON_SLOT].getIndex()).twoHanded()) { unequipItem = items()[WEAPON_SLOT].copy(); set(WEAPON_SLOT, -1, 0); } else if (items()[equipmentSlot].getIndex() != -1) { unequipItem = items()[equipmentSlot].copy(); } } set(equipmentSlot, item.getIndex(), item.getAmount()); if (unequipItem != null) { player().getInventory().set(slot, unequipItem); } else { player().getInventory().set(slot, -1, 0); } setUsingSpecial(false); player().getInventory().refreshItems(); refreshItems(); Combat.resetCombat(player()); return this; }
public boolean checkRequirements(int itemId) { boolean canWear = true; for (int i = 0; i < 21; i++) { if (ItemDefinition.get(itemId) != null) { if (player().getSkills().getPlayerLevel()[i] < ItemDefinition.get(itemId).getReq()[i]) { player() .getPacketDispatcher() .sendMessage( "You need a " + SkillHandler.SKILL_NAMES[i] + " level of " + ItemDefinition.get(itemId).getReq()[i] + " to wear this."); canWear = false; break; } } } return canWear; }
public Equipment sendWeapon(Player player) { Item weapon = player.getEquipment().get(3); int id = -1; String name = "Unarmed"; if (weapon.getIndex() > -1) { name = ItemDefinition.get(weapon.getIndex()).name(); id = weapon.getIndex(); } String name2 = filterWeaponName(name).trim(); sendWeapon(player, id, name, name2); sendSpecialBar(player, id, name); return this; }
/** * Sets the equipment bonuses * * @param player The player instance * @return The equipment container */ public Equipment setBonus(Player player) { player.resetBonuses(); for (Item item : player.getEquipment().items()) { for (int i = 0; i < player.getBonuses().length; i++) { if (item != null && item.getIndex() < 8000) { player.setBonuses( i, player.getBonuses()[i] + ItemDefinition.get(item.getIndex()).bonus(i)); } } } sendBonusToInterface(player); return this; }
/** * Unequips the item from a given slot. * * @param index the item index * @param slot the item slot */ public Equipment unequip(int index, int slot) { Item item = items()[slot].copy(); if (item.getIndex() != index) { return this; } if (ItemDefinition.get(index).stackable()) { int otherItemSlot = player().getInventory().itemSlot(index); if (player().getInventory().isFull() && otherItemSlot == -1) { player().getInventory().noSpace(); return this; } if (otherItemSlot != -1) { int otherItemAmount = player().getInventory().items()[otherItemSlot].getAmount(); long totalAmount = (long) item.getAmount() + (long) otherItemAmount; if (totalAmount > Integer.MAX_VALUE) { set(slot, index, item.getAmount() - (int) (Integer.MAX_VALUE - otherItemAmount)); item.setAmount((int) (Integer.MAX_VALUE - otherItemAmount)); } else { set(slot, -1, 0); } } else { set(slot, -1, 0); } player().getInventory().add(item.getIndex(), item.getAmount(), false); } else { if (player().getInventory().isFull()) { player().getInventory().noSpace(); return this; } player().getInventory().add(item.getIndex(), item.getAmount(), false); set(slot, -1, 0); } player().getInventory().refreshItems(); refreshItems(); return this; }