78 public static final int SIZE = 14;
81 private static final int EQUIPMENT_DISPLAY_ID = 1688;
84 public static final int
100 public static final int
112 RANGED_STRENGTH = 11,
117 private static final int[] BONUS_IDS = IntStream.rangeClosed(15130, 15143).toArray();
120 private static final String[] BONUS_NAMES = {
143 private static final String EXCEPTION_MESSAGE =
"Please use { equipment.set(index, Item) } instead";
149 private static final ImmutableSet<Integer> NO_APPEARANCE = ImmutableSet.of(RING_SLOT, ARROWS_SLOT);
152 private final Player player;
154 private boolean login;
159 this.player = player;
168 Arrays.fill(player.getBonuses(), 0);
169 for (
int index = 0; index <
getItems().length; index++) {
180 player.send(
new SendString(
"Melee Maxhit: <col=ff7000>" + player.playerAssistant.getMaxHit(player,
CombatType.MELEE) +
"</col>", 15116));
181 player.send(
new SendString(
"Range Maxhit: <col=ff7000>" + player.playerAssistant.getMaxHit(player,
CombatType.RANGED) +
"</col>", 15117));
184 player.interfaceManager.open(15106);
196 public boolean add(Item item,
int preferredIndex,
boolean refresh) {
210 public boolean remove(Item item,
int preferredIndex,
boolean refresh) {
211 boolean removed = super.remove(item, preferredIndex,
refresh);
212 if (removed && !contains(item)) {
213 this.appearanceForIndex(item.getEquipmentType().getSlot());
219 private double updateWeight() {
221 for (Item equipment :
toArray()) {
222 if (equipment ==
null)
224 weight += equipment.getWeight();
226 for (Item item : player.inventory.
toArray()) {
229 weight += item.getWeight();
240 for (Item item : items) {
253 if (!item.isEquipable())
256 if (type.getSlot() == -1)
258 set(type.getSlot(), item,
false);
259 appearanceForIndex(type.getSlot());
262 public boolean equip(Item item) {
267 public boolean equip(
int inventoryIndex) {
268 if (inventoryIndex == -1)
271 Inventory inventory = player.inventory;
272 Item item = inventory.get(inventoryIndex);
274 if (!Item.valid(item))
277 if (!item.isEquipable())
280 if (!
Utility.checkRequirements(player, item.getRequirements(),
"to equip this item."))
283 if (!Skillcape.equip(player, item))
286 if (item.getId() == 21633)
290 Item current =
get(type.getSlot());
291 Item toRemove =
null;
293 if (current !=
null && item.isStackable() && isItem(type.getSlot(), item.getId())) {
294 int amount = item.getAmount();
295 if (Integer.MAX_VALUE - current.getAmount() < amount) {
296 amount = Integer.MAX_VALUE - current.getAmount();
298 set(type.getSlot(), current.createAndIncrement(amount),
true);
299 inventory.remove(
new Item(item.getId(), amount), inventoryIndex,
true);
303 if (hasWeapon() && type.equals(EquipmentType.SHIELD))
304 if (item.isTwoHanded() || getWeapon().isTwoHanded())
305 toRemove = getWeapon();
307 if (hasShield() && type.equals(EquipmentType.WEAPON))
308 if (item.isTwoHanded() || getShield().isTwoHanded())
309 toRemove = getShield();
312 if (toRemove !=
null && !inventory.hasCapacityFor(toRemove)) {
313 player.send(
new SendMessage(
"You do not have enough space in your inventory."));
316 inventory.remove(item, inventoryIndex);
317 set(type.getSlot(), item,
true);
318 if (current !=
null) {
319 inventory.add(current, inventoryIndex);
321 appearanceForIndex(type.getSlot());
332 if (toRemove !=
null) {
333 int slot = toRemove.getEquipmentType().getSlot();
334 set(slot,
null,
true);
335 appearanceForIndex(slot);
336 inventory.add(toRemove, inventoryIndex,
true);
353 return unequip(equipmentIndex, -1, player.inventory);
367 if (equipmentIndex == -1)
370 Item
unequip =
get(equipmentIndex);
374 if (!container.
add(
unequip, preferredIndex,
true)) {
378 set(equipmentIndex,
null,
true);
379 appearanceForIndex(equipmentIndex);
391 player.interfaceManager.close(
false);
405 private void appearanceForIndex(
int equipmentIndex) {
406 if (!NO_APPEARANCE.contains(equipmentIndex)) {
407 player.updateFlags.add(UpdateFlag.APPEARANCE);
411 private void addBonus(Item item) {
412 for (
int index = 0; index < item.getBonuses().length; index++) {
413 player.appendBonus(index, item.getBonus(index));
417 private void removeBonus(Item item) {
418 for (
int index = 0; index < item.getBonuses().length; index++) {
419 player.appendBonus(index, -item.getBonus(index));
424 private void writeBonuses() {
425 for (
int i = 0; i < player.getBonuses().length; i++) {
426 String bonus = BONUS_NAMES[i] +
": ";
428 if (player.getBonus(i) >= 0)
431 bonus += player.getBonus(i);
436 player.send(
new SendString(bonus, BONUS_IDS[i]));
440 public boolean hasHead() {
444 public boolean hasAmulet() {
445 return get(AMULET_SLOT) !=
null;
448 public boolean hasAmmo() {
449 return get(ARROWS_SLOT) !=
null;
452 public boolean hasChest() {
453 return get(CHEST_SLOT) !=
null;
456 public boolean hasLegs() {
457 return get(LEGS_SLOT) !=
null;
460 public boolean hasHands() {
461 return get(HANDS_SLOT) !=
null;
464 public boolean hasFeet() {
465 return get(FEET_SLOT) !=
null;
468 public boolean hasRing() {
469 return get(RING_SLOT) !=
null;
472 public Item getAmuletSlot() {
473 return get(AMULET_SLOT);
476 public boolean hasWeapon() {
477 return get(WEAPON_SLOT) !=
null;
480 public boolean hasCape() {
481 return get(CAPE_SLOT) !=
null;
484 public Item getWeapon() {
485 return get(WEAPON_SLOT);
488 public Item getCape() {
489 return get(CAPE_SLOT);
492 public boolean hasShield() {
493 return get(SHIELD_SLOT) !=
null;
496 public Item getShield() {
497 return get(SHIELD_SLOT);
500 public Item[] getEquipment() {
501 Item[] equipment =
new Item[15];
502 equipment[1] = player.equipment.get(
Equipment.HELM_SLOT);
503 equipment[3] = player.equipment.get(
Equipment.CAPE_SLOT);
504 equipment[4] = player.equipment.get(
Equipment.AMULET_SLOT);
505 equipment[5] = player.equipment.get(
Equipment.ARROWS_SLOT);
506 equipment[6] = player.equipment.get(
Equipment.WEAPON_SLOT);
507 equipment[7] = player.equipment.get(
Equipment.CHEST_SLOT);
508 equipment[8] = player.equipment.get(
Equipment.SHIELD_SLOT);
509 equipment[10] = player.equipment.get(
Equipment.LEGS_SLOT);
510 equipment[12] = player.equipment.get(
Equipment.HANDS_SLOT);
511 equipment[13] = player.equipment.get(
Equipment.FEET_SLOT);
512 equipment[14] = player.equipment.get(
Equipment.RING_SLOT);
522 refresh(player, EQUIPMENT_DISPLAY_ID);
537 Arrays.fill(player.getBonuses(), 0);
540 private boolean isItem(
int slot,
int itemId) {
541 Item item =
get(slot);
542 return item !=
null && item.getId() == itemId;
545 public void unEquip(Item item) {
550 if (equip !=
null && equip.getId() == item.getId()) {
552 set(type.getSlot(),
null,
true);
553 appearanceForIndex(type.getSlot());
554 if (!player.inventory.
add(equip))
555 GroundItem.create(player, equip);
560 private void onEquip(Item item) {
561 EquipmentType type = item.getEquipmentType();
562 double boostedExperience = 0.2;
563 for (
int index = 0; index < LUMBERJACK_PIECES.length; index++) {
564 if (contains(LUMBERJACK_PIECES[index][0])) {
565 boostedExperience *= SKILLING_SETS_EXPERIENCE_BOOST_PER_PIECE;
569 if (type == EquipmentType.SHIELD || type == EquipmentType.WEAPON) {
570 updateRangedEquipment();
572 if (item.matchesId(12926) && player.blowpipeDarts !=
null) {
573 addBonus(player.blowpipeDarts);
574 retrieve(ARROWS_SLOT).ifPresent(this::removeBonus);
578 item.getRangedDefinition()
579 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
581 }
else if (type == EquipmentType.ARROWS) {
582 updateRangedEquipment();
587 if (getWeapon().matchesId(12_926) && !login) {
592 getWeapon().getRangedDefinition()
593 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
594 .ifPresent(def -> removeBonus(item));
598 private void onRemove(Item item) {
599 EquipmentType type = item.getEquipmentType();
601 if (type == EquipmentType.SHIELD || type == EquipmentType.WEAPON) {
602 boolean isBlowpipe = item.matchesId(12_926);
604 if (isBlowpipe && player.blowpipeDarts !=
null) {
605 removeBonus(player.blowpipeDarts);
608 if (isBlowpipe || item.getRangedDefinition()
609 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
611 retrieve(ARROWS_SLOT).ifPresent(this::addBonus);
613 updateRangedEquipment();
614 }
else if (type == EquipmentType.ARROWS) {
618 boolean isBlowpipe = getWeapon().matchesId(12_926);
620 if (isBlowpipe || getWeapon().getRangedDefinition()
621 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
626 updateRangedEquipment();
630 public void updateRangedEquipment() {
631 if (!hasWeapon() || !getWeapon().getRangedDefinition().isPresent()) {
632 if (hasWeapon() && getWeapon().matchesId(12_926) && player.blowpipeDarts !=
null) {
633 player.rangedAmmo = RangedAmmunition.find(getWeapon(), player.blowpipeDarts);
637 .map(arrow -> RangedAmmunition.find(getWeapon(), arrow))
640 player.rangedDefinition =
null;
644 RangedWeaponDefinition def = getWeapon().getRangedDefinition().get();
645 player.rangedDefinition = def;
647 switch (def.getType()) {
652 .map(arrow -> RangedAmmunition.find(getWeapon(), arrow))
657 player.rangedAmmo = RangedAmmunition.find(getWeapon(), getWeapon());
666 int stand = PLAYER_STAND;
667 int walk = PLAYER_WALK;
668 int run = PLAYER_RUN;
671 Item weapon = getWeapon();
672 stand = weapon.getStandAnimation();
673 walk = weapon.getWalkAnimation();
674 run = weapon.getRunAnimation();
677 if (player.overrides.hasOverride(
Equipment.WEAPON_SLOT)) {
678 Item weapon = player.overrides.get(
Equipment.WEAPON_SLOT);
679 stand = weapon.getStandAnimation();
680 walk = weapon.getWalkAnimation();
681 run = weapon.getRunAnimation();
684 player.mobAnimation.setStand(stand);
685 player.mobAnimation.setWalk(walk);
686 player.mobAnimation.setRun(run);
689 public static boolean isWearingDFS(
Player player) {
690 if (!player.equipment.hasShield()) {
694 Item shield = player.equipment.getShield();
696 return shield.getId() == 11283 || shield.getId() == 11284 ||
697 shield.getId() == 21633 || shield.getId() == 21634 ||
698 shield.getId() == 22002 || shield.getId() == 22003;
701 public static boolean hasAttractor(
Player player) {
702 Item cape = player.equipment.getCape();
703 return cape !=
null && (cape.matchesId(10498) || cape.matchesId(13337) || cape.matchesId(27363) || cape.matchesId(27365 ) || SkillCape.isEquipped(player, SkillCape.RANGED));
706 public static boolean hasAccumulator(
Player player) {
707 Item cape = player.equipment.getCape();
708 return cape !=
null && (cape.matchesId(10499) || cape.matchesId(13337) || cape.matchesId(27363) || cape.matchesId(27365 ) || SkillCape.isEquipped(player, SkillCape.RANGED));
711 public static boolean hasAssembler(Player player) {
712 Item cape = player.equipment.getCape();
713 return cape !=
null && (cape.matchesId(22109) || cape.matchesId(21898));
716 public static final int[][] LUMBERJACK_PIECES =
723 public static final int [][] SHAYZIEN_PIECES =
725 {Items.SHAYZIEN_GLOVES_5_,
Equipment.HANDS_SLOT},
726 {Items.SHAYZIEN_BOOTS_5_,
Equipment.FEET_SLOT},
727 {Items.SHAYZIEN_HELM_5_,
Equipment.HEAD_SLOT},
728 {Items.SHAYZIEN_GREAVES_5_,
Equipment.LEGS_SLOT},
729 {Items.SHAYZIEN_PLATEBODY_5_,
Equipment.CHEST_SLOT},
754 public final static double SKILLING_SETS_EXPERIENCE_BOOST_PER_PIECE = 1.02;
756 private static final int[] ZAMORAK_ITEMS = {1033, 1035, 2414, 2417, 2653, 2655, 2657, 2659, 3478, 4039, 6764, 10368, 10370, 10372, 10374, 10444, 10450, 10456, 10460, 10468, 10474, 10776, 10786, 10790, 11808, 11824, 11889, 11892, 12638, 13333, 13334, 19936, 20374, 21780, 21782, 21795, 1724, 3842, 20223, 11791, 12904};
757 private static final int[] SARADOMIN_ITEMS = {2412, 2415, 2661, 2663, 2665, 2667, 3479, 4037, 6762, 10384, 10386, 10388, 10390, 10440, 10446, 10452, 10458, 10464, 10470, 10778, 10784, 10792, 11806, 11838, 11891, 12637, 12809, 13331, 13332, 19933, 20372, 21776, 21778, 21791, 3840, 12598, 20220, 19997};
758 private static final int[] BANDOS_ITEMS = {11804, 11832, 11834, 11836, 12265, 12267, 12269, 12271, 12273, 12275, 12480, 12482, 12484, 12486, 12488, 12498, 12500, 12502, 12504, 19924, 20370, 20782, 20232, 11061, 12608, 21733};
759 private static final int[] ARMADYL_ITEMS = {84, 87, 11785, 11802, 11826, 11830, 12253, 12255, 12257, 12259, 12261, 12263, 12470, 12472, 12474, 12476, 12478, 12506, 12508, 12511, 12512, 19930, 20368, 20229, 12610};
760 public static final int [] SHAYZIEN_ITEMS = {13377, 13378, 13379, 13380, 13381};
761 public static final int [] PICKAXES = {1265, 1267, 1269, 1273, 1271, 1275, 13243, 20014, 11920, 12797};
763 public boolean hasShayzien() {
766 public boolean hasArmadyl() {
770 public boolean hasBandos() {
774 public boolean hasSaradomin() {
778 public boolean hasZamorak() {
782 public boolean hasRow() {
786 public boolean contains(
int[] bowsWithNoArrowsRequired) {
787 return containsAny(22550, 25865, 25867, 25884, 25886, 25890, 25892, 25894, 25896, 25888);
791 private final class EquipmentListener
extends ItemContainerAdapter {
794 EquipmentListener() {
800 return EQUIPMENT_DISPLAY_ID;
805 throw new IllegalStateException(EXCEPTION_MESSAGE);
809 public void itemUpdated(
ItemContainer container, Optional<Item> oldItem, Optional<Item> newItem,
int index,
boolean refresh,
boolean login) {
810 if (oldItem.equals(newItem))
814 oldItem.filter(item -> item.getWeaponInterface() !=
null)
815 .orElse(newItem.filter(item -> item.getWeaponInterface() !=
null)
816 .orElse(
null)) !=
null;
818 oldItem.ifPresent(item -> {
821 CombatListenerManager.removeListener(player, item.getId());
824 newItem.ifPresent(item -> {
827 CombatListenerManager.addListener(player, item.getId());
830 if (weapon && !
login)
831 WeaponInterface.execute(player, getWeapon());