RuneHive-Tarnish
Neural OSRS Enhancement Framework
Loading...
Searching...
No Matches
Equipment.java
1package com.osroyale.game.world.items.containers.equipment;
2
3import com.google.common.collect.ImmutableSet;
4import com.osroyale.content.emote.Skillcape;
5import com.osroyale.content.skillcape.SkillCape;
6import com.osroyale.game.Graphic;
7import com.osroyale.game.UpdatePriority;
8import com.osroyale.game.world.entity.combat.CombatType;
9import com.osroyale.game.world.entity.combat.attack.listener.CombatListenerManager;
10import com.osroyale.game.world.entity.combat.ranged.RangedAmmunition;
11import com.osroyale.game.world.entity.combat.ranged.RangedWeaponDefinition;
12import com.osroyale.game.world.entity.combat.ranged.RangedWeaponType;
13import com.osroyale.game.world.entity.combat.weapon.WeaponInterface;
14import com.osroyale.game.world.entity.mob.UpdateFlag;
15import com.osroyale.game.world.entity.mob.player.Player;
16import com.osroyale.game.world.items.Item;
17import com.osroyale.game.world.items.containers.ItemContainer;
18import com.osroyale.game.world.items.containers.ItemContainerAdapter;
19import com.osroyale.game.world.items.containers.inventory.Inventory;
20import com.osroyale.game.world.items.ground.GroundItem;
21import com.osroyale.net.packet.out.SendItemOnInterface;
22import com.osroyale.net.packet.out.SendMessage;
23import com.osroyale.net.packet.out.SendString;
24import com.osroyale.util.Items;
25import com.osroyale.util.Utility;
26
27import java.util.Arrays;
28import java.util.Optional;
29import java.util.stream.IntStream;
30
31import static com.osroyale.game.world.entity.mob.MobAnimation.*;
32
74
75public final class Equipment extends ItemContainer {
76
78 public static final int SIZE = 14;
79
81 private static final int EQUIPMENT_DISPLAY_ID = 1688;
82
84 public static final int
86 HELM_SLOT = 0,
87 CAPE_SLOT = 1,
88 AMULET_SLOT = 2,
89 WEAPON_SLOT = 3,
90 CHEST_SLOT = 4,
91 SHIELD_SLOT = 5,
92
93 LEGS_SLOT = 7,
94 HANDS_SLOT = 9,
95 FEET_SLOT = 10,
96 RING_SLOT = 12,
97 ARROWS_SLOT = 13;
98
100 public static final int
102 SLASH_OFFENSE = 1,
103 CRUSH_OFFENSE = 2,
104 MAGIC_OFFENSE = 3,
105 RANGED_OFFENSE = 4,
106 STAB_DEFENSE = 5,
107 SLASH_DEFENSE = 6,
108 CRUSH_DEFENCE = 7,
109 MAGIC_DEFENSE = 8,
110 RANGED_DEFENSE = 9,
111 STRENGTH_BONUS = 10,
112 RANGED_STRENGTH = 11,
113 MAGIC_STRENGTH = 12,
114 PRAYER_BONUS = 13;
115
117 private static final int[] BONUS_IDS = IntStream.rangeClosed(15130, 15143).toArray();
118
120 private static final String[] BONUS_NAMES = {
121 /* 00 */ "Stab",
122 /* 01 */ "Slash",
123 /* 02 */ "Crush",
124 /* 03 */ "Magic",
125 /* 04 */ "Range",
126 /* - */
127 /* 05 */ "Stab",
128 /* 06 */ "Slash",
129 /* 07 */ "Crush",
130 /* 08 */ "Magic",
131 /* 09 */ "Range",
132 /* - */
133 /* 10 */ "Strength",
134 /* 11 */ "Ranged Strength",
135 /* 12 */ "Magic Strength",
136 /* 13 */ "Prayer"
137 };
138
143 private static final String EXCEPTION_MESSAGE = "Please use { equipment.set(index, Item) } instead";
144
149 private static final ImmutableSet<Integer> NO_APPEARANCE = ImmutableSet.of(RING_SLOT, ARROWS_SLOT);
150
152 private final Player player;
153
154 private boolean login;
155
157 public Equipment(Player player) {
158 super(SIZE, StackPolicy.STANDARD);
159 this.player = player;
160 addListener(new EquipmentListener());
161 }
162
166 public void login() {
167 login = true;
168 Arrays.fill(player.getBonuses(), 0);
169 for (int index = 0; index < getItems().length; index++) {
170 fireItemUpdatedEvent(null, get(index), index, false, true);
171 }
172 login = false;
173 updateWeight();
174 refresh();
175 }
176
178 public void openInterface() {
179 player.send(new SendString(Utility.formatDigits(updateWeight()) + " kg", 15145));
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));
182 player.send(new SendString(Utility.formatDigits(player.playerAssistant.weight()) + " kg", 15145));
183 writeBonuses();
184 player.interfaceManager.open(15106);
185 }
186
195 @Override
196 public boolean add(Item item, int preferredIndex, boolean refresh) {
197 return true;
198 }
199
209 @Override
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());
214 }
215 return removed;
216 }
217
219 private double updateWeight() {
220 double weight = 0;
221 for (Item equipment : toArray()) {
222 if (equipment == null)
223 continue;
224 weight += equipment.getWeight();
225 }
226 for (Item item : player.inventory.toArray()) {
227 if (item == null)
228 continue;
229 weight += item.getWeight();
230 }
231 return weight;
232 }
233
239 public void manualWearAll(Item[] items) {
240 for (Item item : items) {
241 manualWear(item);
242 }
243 }
244
250 public void manualWear(Item item) {
251 if (item == null)
252 return;
253 if (!item.isEquipable())
254 return;
255 EquipmentType type = item.getEquipmentType();
256 if (type.getSlot() == -1)
257 return;
258 set(type.getSlot(), item, false);
259 appearanceForIndex(type.getSlot());
260 }
261
262 public boolean equip(Item item) {
263 int index = player.inventory.computeIndexForId(item.getId());
264 return equip(index);
265 }
266
267 public boolean equip(int inventoryIndex) {
268 if (inventoryIndex == -1)
269 return false;
270
271 Inventory inventory = player.inventory;
272 Item item = inventory.get(inventoryIndex);
273
274 if (!Item.valid(item))
275 return false;
276
277 if (!item.isEquipable())
278 return false;
279
280 if (!Utility.checkRequirements(player, item.getRequirements(), "to equip this item."))
281 return false;
282
283 if (!Skillcape.equip(player, item))
284 return false;
285
286 if (item.getId() == 21633)
287 player.graphic(new Graphic(1395, true, UpdatePriority.VERY_HIGH));
288
289 EquipmentType type = item.getEquipmentType();
290 Item current = get(type.getSlot());
291 Item toRemove = null;
292
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();
297 }
298 set(type.getSlot(), current.createAndIncrement(amount), true);
299 inventory.remove(new Item(item.getId(), amount), inventoryIndex, true);
300 return true;
301 }
302
303 if (hasWeapon() && type.equals(EquipmentType.SHIELD))
304 if (item.isTwoHanded() || getWeapon().isTwoHanded())
305 toRemove = getWeapon();
306
307 if (hasShield() && type.equals(EquipmentType.WEAPON))
308 if (item.isTwoHanded() || getShield().isTwoHanded())
309 toRemove = getShield();
310
311
312 if (toRemove != null && !inventory.hasCapacityFor(toRemove)) {
313 player.send(new SendMessage("You do not have enough space in your inventory."));
314 return false;
315 }
316 inventory.remove(item, inventoryIndex);
317 set(type.getSlot(), item, true);
318 if (current != null) {
319 inventory.add(current, inventoryIndex);
320 }
321 appearanceForIndex(type.getSlot());
322
323// if (player.getCombat().isAttacking(player.getCombat().getDefender()) && !player.getCombat().checkWithin(player, player.getCombat().getDefender(), player.getStrategy())) {
324// Mob defender = player.getCombat().getDefender();
325// player.getCombat().reset();
326// System.out.println("ka");
327// player.movement.dijkstraPath(defender);
328// } else {
329 player.getCombat().reset();
330// }
331
332 if (toRemove != null) {
333 int slot = toRemove.getEquipmentType().getSlot();
334 set(slot, null, true);
335 appearanceForIndex(slot);
336 inventory.add(toRemove, inventoryIndex, true);
337 }
338
339 if (player.interfaceManager.isInterfaceOpen(15106)) {
341 }
342
343 return true;
344 }
352 public boolean unequip(int equipmentIndex) {
353 return unequip(equipmentIndex, -1, player.inventory);
354 }
355
366 private boolean unequip(int equipmentIndex, int preferredIndex, ItemContainer container) {
367 if (equipmentIndex == -1)
368 return false;
369
370 Item unequip = get(equipmentIndex);
371 if (unequip == null)
372 return false;
373
374 if (!container.add(unequip, preferredIndex, true)) {
375 return false;
376 }
377
378 set(equipmentIndex, null, true);
379 appearanceForIndex(equipmentIndex);
380
381// if (player.getCombat().isAttacking(player.getCombat().getDefender())
382// && !player.getCombat().checkWithin(player, player.getCombat().getDefender(), player.getStrategy())) {
383// Mob defender = player.getCombat().getDefender();
384// player.getCombat().reset();
385// player.movement.dijkstraPath(defender);
386// } else {
387 player.getCombat().reset();
388// }
389
390 if (!player.interfaceManager.isClear() && !player.interfaceManager.isInterfaceOpen(15106)) {
391 player.interfaceManager.close(false);
392 }
393
394 if (player.interfaceManager.isInterfaceOpen(15106)) {
396 }
397
398 return true;
399 }
400
405 private void appearanceForIndex(int equipmentIndex) {
406 if (!NO_APPEARANCE.contains(equipmentIndex)) {
407 player.updateFlags.add(UpdateFlag.APPEARANCE);
408 }
409 }
410
411 private void addBonus(Item item) {
412 for (int index = 0; index < item.getBonuses().length; index++) {
413 player.appendBonus(index, item.getBonus(index));
414 }
415 }
416
417 private void removeBonus(Item item) {
418 for (int index = 0; index < item.getBonuses().length; index++) {
419 player.appendBonus(index, -item.getBonus(index));
420 }
421 }
422
424 private void writeBonuses() {
425 for (int i = 0; i < player.getBonuses().length; i++) {
426 String bonus = BONUS_NAMES[i] + ": ";
427
428 if (player.getBonus(i) >= 0)
429 bonus += "+";
430
431 bonus += player.getBonus(i);
432
433 if (i == 12)
434 bonus += "%";
435
436 player.send(new SendString(bonus, BONUS_IDS[i]));
437 }
438 }
439
440 public boolean hasHead() {
441 return get(HEAD_SLOT) != null;
442 }
443
444 public boolean hasAmulet() {
445 return get(AMULET_SLOT) != null;
446 }
447
448 public boolean hasAmmo() {
449 return get(ARROWS_SLOT) != null;
450 }
451
452 public boolean hasChest() {
453 return get(CHEST_SLOT) != null;
454 }
455
456 public boolean hasLegs() {
457 return get(LEGS_SLOT) != null;
458 }
459
460 public boolean hasHands() {
461 return get(HANDS_SLOT) != null;
462 }
463
464 public boolean hasFeet() {
465 return get(FEET_SLOT) != null;
466 }
467
468 public boolean hasRing() {
469 return get(RING_SLOT) != null;
470 }
471
472 public Item getAmuletSlot() {
473 return get(AMULET_SLOT);
474 }
475
476 public boolean hasWeapon() {
477 return get(WEAPON_SLOT) != null;
478 }
479
480 public boolean hasCape() {
481 return get(CAPE_SLOT) != null;
482 }
483
484 public Item getWeapon() {
485 return get(WEAPON_SLOT);
486 }
487
488 public Item getCape() {
489 return get(CAPE_SLOT);
490 }
491
492 public boolean hasShield() {
493 return get(SHIELD_SLOT) != null;
494 }
495
496 public Item getShield() {
497 return get(SHIELD_SLOT);
498 }
499
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);
513 return equipment;
514 }
515
516
521 public void refresh() {
522 refresh(player, EQUIPMENT_DISPLAY_ID);
523 }
524
529 @Override
530 public void refresh(Player player, int widget) {
531 player.send(new SendItemOnInterface(widget, toArray()));
532 }
533
534 @Override
535 public void clear() {
536 super.clear();
537 Arrays.fill(player.getBonuses(), 0);
538 }
539
540 private boolean isItem(int slot, int itemId) {
541 Item item = get(slot);
542 return item != null && item.getId() == itemId;
543 }
544
545 public void unEquip(Item item) {
546 if (item == null) {
547 return;
548 }
549 for (Item equip : getItems()) {
550 if (equip != null && equip.getId() == item.getId()) {
551 EquipmentType type = item.getEquipmentType();
552 set(type.getSlot(), null, true);
553 appearanceForIndex(type.getSlot());
554 if (!player.inventory.add(equip))
555 GroundItem.create(player, equip);
556 }
557 }
558 }
559
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;
566 }
567 }
568
569 if (type == EquipmentType.SHIELD || type == EquipmentType.WEAPON) {
570 updateRangedEquipment();
571
572 if (item.matchesId(12926) && player.blowpipeDarts != null) {
573 addBonus(player.blowpipeDarts);
574 retrieve(ARROWS_SLOT).ifPresent(this::removeBonus);
575 return;
576 }
577
578 item.getRangedDefinition()
579 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
580 .ifPresent(def -> retrieve(ARROWS_SLOT).ifPresent(this::removeBonus));
581 } else if (type == EquipmentType.ARROWS) {
582 updateRangedEquipment();
583
584 if (!hasWeapon())
585 return;
586
587 if (getWeapon().matchesId(12_926) && !login) {
588 removeBonus(item);
589 return;
590 }
591
592 getWeapon().getRangedDefinition()
593 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
594 .ifPresent(def -> removeBonus(item));
595 }
596 }
597
598 private void onRemove(Item item) {
599 EquipmentType type = item.getEquipmentType();
600
601 if (type == EquipmentType.SHIELD || type == EquipmentType.WEAPON) {
602 boolean isBlowpipe = item.matchesId(12_926);
603
604 if (isBlowpipe && player.blowpipeDarts != null) {
605 removeBonus(player.blowpipeDarts);
606 }
607
608 if (isBlowpipe || item.getRangedDefinition()
609 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
610 .isPresent()) {
611 retrieve(ARROWS_SLOT).ifPresent(this::addBonus);
612 }
613 updateRangedEquipment();
614 } else if (type == EquipmentType.ARROWS) {
615 if (!hasWeapon())
616 return;
617
618 boolean isBlowpipe = getWeapon().matchesId(12_926);
619
620 if (isBlowpipe || getWeapon().getRangedDefinition()
621 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
622 .isPresent()) {
623 addBonus(item);
624 }
625
626 updateRangedEquipment();
627 }
628 }
629
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);
634 } else {
635 player.rangedAmmo =
636 retrieve(ARROWS_SLOT)
637 .map(arrow -> RangedAmmunition.find(getWeapon(), arrow))
638 .orElse(null);
639 }
640 player.rangedDefinition = null;
641 return;
642 }
643
644 RangedWeaponDefinition def = getWeapon().getRangedDefinition().get();
645 player.rangedDefinition = def;
646
647 switch (def.getType()) {
648
649 case SHOT:
650 player.rangedAmmo =
651 retrieve(ARROWS_SLOT)
652 .map(arrow -> RangedAmmunition.find(getWeapon(), arrow))
653 .orElse(null);
654 break;
655
656 case THROWN:
657 player.rangedAmmo = RangedAmmunition.find(getWeapon(), getWeapon());
658 break;
659 }
660 }
661
665 public void updateAnimation() {
666 int stand = PLAYER_STAND;
667 int walk = PLAYER_WALK;
668 int run = PLAYER_RUN;
669
670 if (hasWeapon()) {
671 Item weapon = getWeapon();
672 stand = weapon.getStandAnimation();
673 walk = weapon.getWalkAnimation();
674 run = weapon.getRunAnimation();
675 }
676
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();
682 }
683
684 player.mobAnimation.setStand(stand);
685 player.mobAnimation.setWalk(walk);
686 player.mobAnimation.setRun(run);
687 }
688
689 public static boolean isWearingDFS(Player player) {
690 if (!player.equipment.hasShield()) {
691 return false;
692 }
693
694 Item shield = player.equipment.getShield();
695
696 return shield.getId() == 11283 || shield.getId() == 11284 ||
697 shield.getId() == 21633 || shield.getId() == 21634 ||
698 shield.getId() == 22002 || shield.getId() == 22003;
699 }
700
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));
704 }
705
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));
709 }
710
711 public static boolean hasAssembler(Player player) {
712 Item cape = player.equipment.getCape();
713 return cape != null && (cape.matchesId(22109) || cape.matchesId(21898));
714 }
715
716 public static final int[][] LUMBERJACK_PIECES =
717 {
718 {10933, Equipment.FEET_SLOT},
719 {10939, Equipment.CHEST_SLOT},
720 {10940, Equipment.LEGS_SLOT},
721 {10941, Equipment.HEAD_SLOT},
722 };
723 public static final int [][] SHAYZIEN_PIECES =
724 {
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},
730 };
731
735 public static final int[][] ANGLER_PIECES =
736 {
737 {13258, Equipment.HEAD_SLOT},
738 {13259, Equipment.CHEST_SLOT},
739 {13260, Equipment.LEGS_SLOT},
740 {13261, Equipment.FEET_SLOT},
741 };
742
746 public static final int[][] PROSPECTOR_PIECES =
747 {
748 {12013, Equipment.HEAD_SLOT},
749 {12014, Equipment.CHEST_SLOT},
750 {12015, Equipment.LEGS_SLOT},
751 {12016, Equipment.FEET_SLOT},
752 };
753
754 public final static double SKILLING_SETS_EXPERIENCE_BOOST_PER_PIECE = 1.02;
755
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};
762
763 public boolean hasShayzien() {
764 return containsAny(SHAYZIEN_ITEMS);
765 }
766 public boolean hasArmadyl() {
767 return containsAny(ARMADYL_ITEMS);
768 }
769
770 public boolean hasBandos() {
771 return containsAny(BANDOS_ITEMS);
772 }
773
774 public boolean hasSaradomin() {
775 return containsAny(SARADOMIN_ITEMS);
776 }
777
778 public boolean hasZamorak() {
779 return containsAny(ZAMORAK_ITEMS);
780 }
781
782 public boolean hasRow() {
783 return containsAny(2572, 12785);
784 }
785
786 public boolean contains(int[] bowsWithNoArrowsRequired) {
787 return containsAny(22550, 25865, 25867, 25884, 25886, 25890, 25892, 25894, 25896, 25888);
788 }
789
791 private final class EquipmentListener extends ItemContainerAdapter {
792
794 EquipmentListener() {
795 super(player);
796 }
797
798 @Override
799 public int getWidgetId() {
800 return EQUIPMENT_DISPLAY_ID;
801 }
802
803 @Override
804 public String getCapacityExceededMsg() {
805 throw new IllegalStateException(EXCEPTION_MESSAGE);
806 }
807
808 @Override
809 public void itemUpdated(ItemContainer container, Optional<Item> oldItem, Optional<Item> newItem, int index, boolean refresh, boolean login) {
810 if (oldItem.equals(newItem))
811 return;
812
813 boolean weapon =
814 oldItem.filter(item -> item.getWeaponInterface() != null)
815 .orElse(newItem.filter(item -> item.getWeaponInterface() != null)
816 .orElse(null)) != null;
817
818 oldItem.ifPresent(item -> {
819 removeBonus(item);
820 onRemove(item);
821 CombatListenerManager.removeListener(player, item.getId());
822 });
823
824 newItem.ifPresent(item -> {
825 addBonus(item);
826 onEquip(item);
827 CombatListenerManager.addListener(player, item.getId());
828 });
829
830 if (weapon && !login)
831 WeaponInterface.execute(player, getWeapon());
832
833 if (refresh)
834 sendItemsToWidget(container);
835 }
836
837 @Override
838 public void bulkItemsUpdated(ItemContainer container) {
839 sendItemsToWidget(container);
840 }
841 }
842}
ItemContainer(int capacity, StackPolicy policy, Item[] items)
final void fireItemUpdatedEvent(Item oldItem, Item newItem, int index, boolean refresh)
final boolean addListener(ItemContainerListener listener)
final void ifPresent(int index, Consumer< Item > action)
boolean add(Item item, int preferredIndex, boolean refresh)
static String formatDigits(final int amount)
Definition Utility.java:78