RuneHive-Game
Loading...
Searching...
No Matches
Equipment.java
Go to the documentation of this file.
1package com.runehive.game.world.items.containers.equipment;
2
3import com.google.common.collect.ImmutableSet;
4import com.runehive.content.emote.Skillcape;
5import com.runehive.content.skillcape.SkillCape;
6import com.runehive.game.Graphic;
7import com.runehive.game.UpdatePriority;
8import com.runehive.game.world.entity.combat.CombatType;
9import com.runehive.game.world.entity.combat.attack.listener.CombatListenerManager;
10import com.runehive.game.world.entity.combat.ranged.RangedAmmunition;
11import com.runehive.game.world.entity.combat.ranged.RangedWeaponDefinition;
12import com.runehive.game.world.entity.combat.ranged.RangedWeaponType;
13import com.runehive.game.world.entity.combat.weapon.WeaponInterface;
14import com.runehive.game.world.entity.mob.UpdateFlag;
15import com.runehive.game.world.entity.mob.player.Player;
16import com.runehive.game.world.items.Item;
17import com.runehive.game.world.items.containers.ItemContainer;
18import com.runehive.game.world.items.containers.ItemContainerAdapter;
19import com.runehive.game.world.items.containers.inventory.Inventory;
20import com.runehive.game.world.items.ground.GroundItem;
21import com.runehive.net.packet.out.SendItemOnInterface;
22import com.runehive.net.packet.out.SendMessage;
23import com.runehive.net.packet.out.SendString;
24import com.runehive.util.Items;
25import com.runehive.util.Utility;
26
27import java.util.Arrays;
28import java.util.Optional;
29import java.util.stream.IntStream;
30
31import static com.runehive.game.world.entity.mob.MobAnimation.*;
32
33/**
34 * The container that manages the equipment for a player.
35 *
36 * @author lare96 <http://github.com/lare96>
37 */
38public final class Equipment extends ItemContainer {
39
40 /** The size of all equipment instances. */
41 public static final int SIZE = 14;
42
43 /** The equipment item display widget identifier. */
44 private static final int EQUIPMENT_DISPLAY_ID = 1688;
45
46 /** Equipment slot constants. */
47 public static final int
55
61
62 /** Equipment bonus constants. */
63 public static final int
78
79 /** An array of bonus ids. */
80 private static final int[] BONUS_IDS = IntStream.rangeClosed(15130, 15143).toArray();
81
82 /** Item bonus names. */
83 private static final String[] BONUS_NAMES = {
84 /* 00 */ "Stab",
85 /* 01 */ "Slash",
86 /* 02 */ "Crush",
87 /* 03 */ "Magic",
88 /* 04 */ "Range",
89 /* - */
90 /* 05 */ "Stab",
91 /* 06 */ "Slash",
92 /* 07 */ "Crush",
93 /* 08 */ "Magic",
94 /* 09 */ "Range",
95 /* - */
96 /* 10 */ "Strength",
97 /* 11 */ "Ranged Strength",
98 /* 12 */ "Magic Strength",
99 /* 13 */ "Prayer"
100 };
101
102 /**
103 * The error message printed when certain functions from the superclass are
104 * utilized.
105 */
106 private static final String EXCEPTION_MESSAGE = "Please use { equipment.set(index, Item) } instead";
107
108 /**
109 * An {@link ImmutableSet} containing equipment indexes that don't require
110 * appearance updates.
111 */
112 private static final ImmutableSet<Integer> NO_APPEARANCE = ImmutableSet.of(RING_SLOT, ARROWS_SLOT);
113
114 /** The player who's equipment is being managed. */
115 private final Player player;
116
117 private boolean login;
118
119 /** Creates a new {@link Equipment}. */
121 super(SIZE, StackPolicy.STANDARD);
122 this.player = player;
124 }
125
126 /**
127 * Handles refreshing all the equipment items.
128 */
129 public void login() {
130 login = true;
131 Arrays.fill(player.getBonuses(), 0);
132 for (int index = 0; index < getItems().length; index++) {
133 fireItemUpdatedEvent(null, get(index), index, false, true);
134 }
135 login = false;
136 updateWeight();
137 refresh();
138 }
139
140 /** Handles opening the equipment screen itemcontainer. */
141 public void openInterface() {
142 player.send(new SendString(Utility.formatDigits(updateWeight()) + " kg", 15145));
143 player.send(new SendString("Melee Maxhit: <col=ff7000>" + player.playerAssistant.getMaxHit(player, CombatType.MELEE) + "</col>", 15116));
144 player.send(new SendString("Range Maxhit: <col=ff7000>" + player.playerAssistant.getMaxHit(player, CombatType.RANGED) + "</col>", 15117));
145 player.send(new SendString(Utility.formatDigits(player.playerAssistant.weight()) + " kg", 15145));
146 writeBonuses();
147 player.interfaceManager.open(15106);
148 }
149
150 /**
151 * Adds an item to the equipment container.
152 *
153 * @param item The {@link Item} to deposit.
154 * @param preferredIndex The preferable index to deposit {@code item} to.
155 * @param refresh The condition if we will be refreshing our
156 * container.
157 */
158 @Override
159 public boolean add(Item item, int preferredIndex, boolean refresh) {
160 return true;
161 }
162
163 /**
164 * Removes an item from the equipment container.
165 *
166 * @param item The {@link Item} to withdraw.
167 * @param preferredIndex The preferable index to withdraw {@code item}
168 * from.
169 * @param refresh The condition if we will be refreshing our
170 * container.
171 */
172 @Override
173 public boolean remove(Item item, int preferredIndex, boolean refresh) {
174 boolean removed = super.remove(item, preferredIndex, refresh);
175 if (removed && !contains(item)) {
176 this.appearanceForIndex(item.getEquipmentType().getSlot());
177 }
178 return removed;
179 }
180
181 /** @return the current weight value of the player */
182 private double updateWeight() {
183 double weight = 0;
184 for (Item equipment : toArray()) {
185 if (equipment == null)
186 continue;
187 weight += equipment.getWeight();
188 }
189 for (Item item : player.inventory.toArray()) {
190 if (item == null)
191 continue;
192 weight += item.getWeight();
193 }
194 return weight;
195 }
196
197 /**
198 * Manually wears multiple items (does not have any restrictions).
199 *
200 * @param items The items to wear.
201 */
202 public void manualWearAll(Item[] items) {
203 for (Item item : items) {
204 manualWear(item);
205 }
206 }
207
208 /**
209 * Manually wears an item (does not have any restrictions).
210 *
211 * @param item The item to wear.
212 */
213 public void manualWear(Item item) {
214 if (item == null)
215 return;
216 if (!item.isEquipable())
217 return;
218 EquipmentType type = item.getEquipmentType();
219 if (type.getSlot() == -1)
220 return;
221 set(type.getSlot(), item, false);
223 }
224
225 public boolean equip(Item item) {
226 int index = player.inventory.computeIndexForId(item.getId());
227 return equip(index);
228 }
229
230 public boolean equip(int inventoryIndex) {
231 if (inventoryIndex == -1)
232 return false;
233
234 Inventory inventory = player.inventory;
235 Item item = inventory.get(inventoryIndex);
236
237 if (!Item.valid(item))
238 return false;
239
240 if (!item.isEquipable())
241 return false;
242
243 if (!Utility.checkRequirements(player, item.getRequirements(), "to equip this item."))
244 return false;
245
246 if (!Skillcape.equip(player, item))
247 return false;
248
249 if (item.getId() == 21633)
250 player.graphic(new Graphic(1395, true, UpdatePriority.VERY_HIGH));
251
252 EquipmentType type = item.getEquipmentType();
253 Item current = get(type.getSlot());
254 Item toRemove = null;
255
256 if (current != null && item.isStackable() && isItem(type.getSlot(), item.getId())) {
257 int amount = item.getAmount();
258 if (Integer.MAX_VALUE - current.getAmount() < amount) {
259 amount = Integer.MAX_VALUE - current.getAmount();
260 }
261 set(type.getSlot(), current.createAndIncrement(amount), true);
262 inventory.remove(new Item(item.getId(), amount), inventoryIndex, true);
263 return true;
264 }
265
266 if (hasWeapon() && type.equals(EquipmentType.SHIELD))
267 if (item.isTwoHanded() || getWeapon().isTwoHanded())
268 toRemove = getWeapon();
269
270 if (hasShield() && type.equals(EquipmentType.WEAPON))
271 if (item.isTwoHanded() || getShield().isTwoHanded())
272 toRemove = getShield();
273
274
275 if (toRemove != null && !inventory.hasCapacityFor(toRemove)) {
276 player.send(new SendMessage("You do not have enough space in your inventory."));
277 return false;
278 }
279 inventory.remove(item, inventoryIndex);
280 set(type.getSlot(), item, true);
281 if (current != null) {
282 inventory.add(current, inventoryIndex);
283 }
285
286// if (player.getCombat().isAttacking(player.getCombat().getDefender()) && !player.getCombat().checkWithin(player, player.getCombat().getDefender(), player.getStrategy())) {
287// Mob defender = player.getCombat().getDefender();
288// player.getCombat().reset();
289// System.out.println("ka");
290// player.movement.dijkstraPath(defender);
291// } else {
292 player.getCombat().reset();
293// }
294
295 if (toRemove != null) {
296 int slot = toRemove.getEquipmentType().getSlot();
297 set(slot, null, true);
299 inventory.add(toRemove, inventoryIndex, true);
300 }
301
302 if (player.interfaceManager.isInterfaceOpen(15106)) {
304 }
305
306 return true;
307 }
308 /**
309 * Unequips an {@link Item} from the underlying player's {@code Equipment}.
310 *
311 * @param equipmentIndex The {@code Equipment} index to unequip the {@code
312 * Item} from.
313 * @return {@code true} if the item was unequipped, {@code false} otherwise.
314 */
315 public boolean unequip(int equipmentIndex) {
316 return unequip(equipmentIndex, -1, player.inventory);
317 }
318
319 /**
320 * Unequips an {@link Item} from the underlying player's {@code Equipment}.
321 *
322 * @param equipmentIndex The {@code Equipment} index to unequip the {@code
323 * Item} from.
324 * @param preferredIndex The preferred inventory slot.
325 * @param container The container to which we are putting the items
326 * on.
327 * @return {@code true} if the item was unequipped, {@code false} otherwise.
328 */
329 private boolean unequip(int equipmentIndex, int preferredIndex, ItemContainer container) {
330 if (equipmentIndex == -1)
331 return false;
332
333 Item unequip = get(equipmentIndex);
334 if (unequip == null)
335 return false;
336
337 if (!container.add(unequip, preferredIndex, true)) {
338 return false;
339 }
340
341 set(equipmentIndex, null, true);
342 appearanceForIndex(equipmentIndex);
343
344// if (player.getCombat().isAttacking(player.getCombat().getDefender())
345// && !player.getCombat().checkWithin(player, player.getCombat().getDefender(), player.getStrategy())) {
346// Mob defender = player.getCombat().getDefender();
347// player.getCombat().reset();
348// player.movement.dijkstraPath(defender);
349// } else {
350 player.getCombat().reset();
351// }
352
353 if (!player.interfaceManager.isClear() && !player.interfaceManager.isInterfaceOpen(15106)) {
354 player.interfaceManager.close(false);
355 }
356
357 if (player.interfaceManager.isInterfaceOpen(15106)) {
359 }
360
361 return true;
362 }
363
364 /**
365 * Flags the {@code APPEARANCE} update block, only if the equipment piece on
366 * {@code equipmentIndex} requires an appearance update.
367 */
368 private void appearanceForIndex(int equipmentIndex) {
369 if (!NO_APPEARANCE.contains(equipmentIndex)) {
370 player.updateFlags.add(UpdateFlag.APPEARANCE);
371 }
372 }
373
374 private void addBonus(Item item) {
375 for (int index = 0; index < item.getBonuses().length; index++) {
376 player.appendBonus(index, item.getBonus(index));
377 }
378 }
379
380 private void removeBonus(Item item) {
381 for (int index = 0; index < item.getBonuses().length; index++) {
382 player.appendBonus(index, -item.getBonus(index));
383 }
384 }
385
386 /** Writes a specific the bonus value on the equipment itemcontainer. */
387 private void writeBonuses() {
388 for (int i = 0; i < player.getBonuses().length; i++) {
389 String bonus = BONUS_NAMES[i] + ": ";
390
391 if (player.getBonus(i) >= 0)
392 bonus += "+";
393
394 bonus += player.getBonus(i);
395
396 if (i == 12)
397 bonus += "%";
398
399 player.send(new SendString(bonus, BONUS_IDS[i]));
400 }
401 }
402
403 public boolean hasHead() {
404 return get(HEAD_SLOT) != null;
405 }
406
407 public boolean hasAmulet() {
408 return get(AMULET_SLOT) != null;
409 }
410
411 public boolean hasAmmo() {
412 return get(ARROWS_SLOT) != null;
413 }
414
415 public boolean hasChest() {
416 return get(CHEST_SLOT) != null;
417 }
418
419 public boolean hasLegs() {
420 return get(LEGS_SLOT) != null;
421 }
422
423 public boolean hasHands() {
424 return get(HANDS_SLOT) != null;
425 }
426
427 public boolean hasFeet() {
428 return get(FEET_SLOT) != null;
429 }
430
431 public boolean hasRing() {
432 return get(RING_SLOT) != null;
433 }
434
436 return get(AMULET_SLOT);
437 }
438
439 public boolean hasWeapon() {
440 return get(WEAPON_SLOT) != null;
441 }
442
443 public boolean hasCape() {
444 return get(CAPE_SLOT) != null;
445 }
446
447 public Item getWeapon() {
448 return get(WEAPON_SLOT);
449 }
450
451 public Item getCape() {
452 return get(CAPE_SLOT);
453 }
454
455 public boolean hasShield() {
456 return get(SHIELD_SLOT) != null;
457 }
458
459 public Item getShield() {
460 return get(SHIELD_SLOT);
461 }
462
463 public Item[] getEquipment() {
464 Item[] equipment = new Item[15];
465 equipment[1] = player.equipment.get(Equipment.HELM_SLOT);
466 equipment[3] = player.equipment.get(Equipment.CAPE_SLOT);
467 equipment[4] = player.equipment.get(Equipment.AMULET_SLOT);
468 equipment[5] = player.equipment.get(Equipment.ARROWS_SLOT);
469 equipment[6] = player.equipment.get(Equipment.WEAPON_SLOT);
470 equipment[7] = player.equipment.get(Equipment.CHEST_SLOT);
471 equipment[8] = player.equipment.get(Equipment.SHIELD_SLOT);
472 equipment[10] = player.equipment.get(Equipment.LEGS_SLOT);
473 equipment[12] = player.equipment.get(Equipment.HANDS_SLOT);
474 equipment[13] = player.equipment.get(Equipment.FEET_SLOT);
475 equipment[14] = player.equipment.get(Equipment.RING_SLOT);
476 return equipment;
477 }
478
479
480 /**
481 * Forces a refresh of {@code Equipment} items to the {@code
482 * EQUIPMENT_DISPLAY_ID} widget.
483 */
484 public void refresh() {
486 }
487
488 /**
489 * Forces a refresh of {@code Equipment} items to the {@code
490 * EQUIPMENT_DISPLAY_ID} widget.
491 */
492 @Override
493 public void refresh(Player player, int widget) {
494 player.send(new SendItemOnInterface(widget, toArray()));
495 }
496
497 @Override
498 public void clear() {
499 super.clear();
500 Arrays.fill(player.getBonuses(), 0);
501 }
502
503 private boolean isItem(int slot, int itemId) {
504 Item item = get(slot);
505 return item != null && item.getId() == itemId;
506 }
507
508 public void unEquip(Item item) {
509 if (item == null) {
510 return;
511 }
512 for (Item equip : getItems()) {
513 if (equip != null && equip.getId() == item.getId()) {
514 EquipmentType type = item.getEquipmentType();
515 set(type.getSlot(), null, true);
517 if (!player.inventory.add(equip))
519 }
520 }
521 }
522
523 private void onEquip(Item item) {
524 EquipmentType type = item.getEquipmentType();
525 double boostedExperience = 0.2;
526 for (int index = 0; index < LUMBERJACK_PIECES.length; index++) {
527 if (contains(LUMBERJACK_PIECES[index][0])) {
528 boostedExperience *= SKILLING_SETS_EXPERIENCE_BOOST_PER_PIECE;
529 }
530 }
531
532 if (type == EquipmentType.SHIELD || type == EquipmentType.WEAPON) {
534
535 if (item.matchesId(12926) && player.blowpipeDarts != null) {
536 addBonus(player.blowpipeDarts);
537 retrieve(ARROWS_SLOT).ifPresent(this::removeBonus);
538 return;
539 }
540
542 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
543 .ifPresent(def -> retrieve(ARROWS_SLOT).ifPresent(this::removeBonus));
544 } else if (type == EquipmentType.ARROWS) {
546
547 if (!hasWeapon())
548 return;
549
550 if (getWeapon().matchesId(12_926) && !login) {
551 removeBonus(item);
552 return;
553 }
554
556 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
557 .ifPresent(def -> removeBonus(item));
558 }
559 }
560
561 private void onRemove(Item item) {
562 EquipmentType type = item.getEquipmentType();
563
564 if (type == EquipmentType.SHIELD || type == EquipmentType.WEAPON) {
565 boolean isBlowpipe = item.matchesId(12_926);
566
567 if (isBlowpipe && player.blowpipeDarts != null) {
568 removeBonus(player.blowpipeDarts);
569 }
570
571 if (isBlowpipe || item.getRangedDefinition()
572 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
573 .isPresent()) {
574 retrieve(ARROWS_SLOT).ifPresent(this::addBonus);
575 }
577 } else if (type == EquipmentType.ARROWS) {
578 if (!hasWeapon())
579 return;
580
581 boolean isBlowpipe = getWeapon().matchesId(12_926);
582
583 if (isBlowpipe || getWeapon().getRangedDefinition()
584 .filter(def -> def.getType().equals(RangedWeaponType.THROWN))
585 .isPresent()) {
586 addBonus(item);
587 }
588
590 }
591 }
592
593 public void updateRangedEquipment() {
594 if (!hasWeapon() || !getWeapon().getRangedDefinition().isPresent()) {
595 if (hasWeapon() && getWeapon().matchesId(12_926) && player.blowpipeDarts != null) {
596 player.rangedAmmo = RangedAmmunition.find(getWeapon(), player.blowpipeDarts);
597 } else {
598 player.rangedAmmo =
600 .map(arrow -> RangedAmmunition.find(getWeapon(), arrow))
601 .orElse(null);
602 }
603 player.rangedDefinition = null;
604 return;
605 }
606
608 player.rangedDefinition = def;
609
610 switch (def.getType()) {
611
612 case SHOT:
613 player.rangedAmmo =
615 .map(arrow -> RangedAmmunition.find(getWeapon(), arrow))
616 .orElse(null);
617 break;
618
619 case THROWN:
620 player.rangedAmmo = RangedAmmunition.find(getWeapon(), getWeapon());
621 break;
622 }
623 }
624
625 /**
626 * Updates the weapon animation.
627 */
628 public void updateAnimation() {
629 int stand = PLAYER_STAND;
630 int walk = PLAYER_WALK;
631 int run = PLAYER_RUN;
632
633 if (hasWeapon()) {
634 Item weapon = getWeapon();
635 stand = weapon.getStandAnimation();
636 walk = weapon.getWalkAnimation();
637 run = weapon.getRunAnimation();
638 }
639
640 if (player.overrides.hasOverride(Equipment.WEAPON_SLOT)) {
641 Item weapon = player.overrides.get(Equipment.WEAPON_SLOT);
642 stand = weapon.getStandAnimation();
643 walk = weapon.getWalkAnimation();
644 run = weapon.getRunAnimation();
645 }
646
647 player.mobAnimation.setStand(stand);
648 player.mobAnimation.setWalk(walk);
649 player.mobAnimation.setRun(run);
650 }
651
652 public static boolean isWearingDFS(Player player) {
653 if (!player.equipment.hasShield()) {
654 return false;
655 }
656
657 Item shield = player.equipment.getShield();
658
659 return shield.getId() == 11283 || shield.getId() == 11284 ||
660 shield.getId() == 21633 || shield.getId() == 21634 ||
661 shield.getId() == 22002 || shield.getId() == 22003;
662 }
663
664 public static boolean hasAttractor(Player player) {
665 Item cape = player.equipment.getCape();
666 return cape != null && (cape.matchesId(10498) || cape.matchesId(13337) || cape.matchesId(27363) || cape.matchesId(27365 ) || SkillCape.isEquipped(player, SkillCape.RANGED));
667 }
668
669 public static boolean hasAccumulator(Player player) {
670 Item cape = player.equipment.getCape();
671 return cape != null && (cape.matchesId(10499) || cape.matchesId(13337) || cape.matchesId(27363) || cape.matchesId(27365 ) || SkillCape.isEquipped(player, SkillCape.RANGED));
672 }
673
674 public static boolean hasAssembler(Player player) {
675 Item cape = player.equipment.getCape();
676 return cape != null && (cape.matchesId(22109) || cape.matchesId(21898));
677 }
678
679 public static final int[][] LUMBERJACK_PIECES =
680 {
681 {10933, Equipment.FEET_SLOT},
682 {10939, Equipment.CHEST_SLOT},
683 {10940, Equipment.LEGS_SLOT},
684 {10941, Equipment.HEAD_SLOT},
685 };
686 public static final int [][] SHAYZIEN_PIECES =
687 {
688 {Items.SHAYZIEN_GLOVES_5_, Equipment.HANDS_SLOT},
689 {Items.SHAYZIEN_BOOTS_5_, Equipment.FEET_SLOT},
690 {Items.SHAYZIEN_HELM_5_, Equipment.HEAD_SLOT},
693 };
694
695 /**
696 * Fishing.
697 */
698 public static final int[][] ANGLER_PIECES =
699 {
700 {13258, Equipment.HEAD_SLOT},
701 {13259, Equipment.CHEST_SLOT},
702 {13260, Equipment.LEGS_SLOT},
703 {13261, Equipment.FEET_SLOT},
704 };
705
706 /**
707 * Mining.
708 */
709 public static final int[][] PROSPECTOR_PIECES =
710 {
711 {12013, Equipment.HEAD_SLOT},
712 {12014, Equipment.CHEST_SLOT},
713 {12015, Equipment.LEGS_SLOT},
714 {12016, Equipment.FEET_SLOT},
715 };
716
717 public final static double SKILLING_SETS_EXPERIENCE_BOOST_PER_PIECE = 1.02;
718
719 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};
720 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};
721 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};
722 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};
723 public static final int [] SHAYZIEN_ITEMS = {13377, 13378, 13379, 13380, 13381};
724 public static final int [] PICKAXES = {1265, 1267, 1269, 1273, 1271, 1275, 13243, 20014, 11920, 12797};
725
726 public boolean hasShayzien() {
728 }
729 public boolean hasArmadyl() {
731 }
732
733 public boolean hasBandos() {
735 }
736
737 public boolean hasSaradomin() {
739 }
740
741 public boolean hasZamorak() {
743 }
744
745 public boolean hasRow() {
746 return containsAny(2572, 12785);
747 }
748
749 public boolean contains(int[] bowsWithNoArrowsRequired) {
750 return containsAny(22550, 25865, 25867, 25884, 25886, 25890, 25892, 25894, 25896, 25888);
751 }
752
753 /** An {@link ItemContainerAdapter} implementation that listens for changes to equipment. */
754 private final class EquipmentListener extends ItemContainerAdapter {
755
756 /** Creates a new {@link EquipmentListener}. */
758 super(player);
759 }
760
761 @Override
762 public int getWidgetId() {
764 }
765
766 @Override
767 public String getCapacityExceededMsg() {
768 throw new IllegalStateException(EXCEPTION_MESSAGE);
769 }
770
771 @Override
772 public void itemUpdated(ItemContainer container, Optional<Item> oldItem, Optional<Item> newItem, int index, boolean refresh, boolean login) {
773 if (oldItem.equals(newItem))
774 return;
775
776 boolean weapon =
777 oldItem.filter(item -> item.getWeaponInterface() != null)
778 .orElse(newItem.filter(item -> item.getWeaponInterface() != null)
779 .orElse(null)) != null;
780
781 oldItem.ifPresent(item -> {
782 removeBonus(item);
783 onRemove(item);
785 });
786
787 newItem.ifPresent(item -> {
788 addBonus(item);
789 onEquip(item);
791 });
792
793 if (weapon && !login)
795
796 if (refresh)
797 sendItemsToWidget(container);
798 }
799
800 @Override
801 public void bulkItemsUpdated(ItemContainer container) {
802 sendItemsToWidget(container);
803 }
804 }
805}
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
This class represents a character controlled by a player.
Definition Player.java:125
The container class that represents an item that can be interacted with.
Definition Item.java:21
Optional< RangedWeaponDefinition > getRangedDefinition()
Definition Item.java:445
final int getId()
Gets the identification of this item.
Definition Item.java:324
static boolean valid(Item item)
Determines if item is valid.
Definition Item.java:259
final int getAmount()
Gets the quantity of this item.
Definition Item.java:342
Item createAndIncrement(int addAmount)
Creates a new item with amount + addAmount and the same identifier.
Definition Item.java:174
EquipmentType getEquipmentType()
Definition Item.java:441
void sendItemsToWidget(ItemContainer container)
Queues a message that displays items from an ItemContainer on a widget.
ItemContainerAdapter(Player player)
Creates a new ItemContainerAdapter.
final void fireItemUpdatedEvent(Item oldItem, Item newItem, int index, boolean refresh)
Fires the ItemContainerListener.itemUpdated(ItemContainer, int) event.
ItemContainer(int capacity, StackPolicy policy, Item[] items)
Creates a new ItemContainer.
Item[] items
The Items within this container.
boolean add(Item item)
Attempts to deposit item into this container.
final boolean addListener(ItemContainerListener listener)
Adds an ItemContainerListener to this container.
final Optional< Item > retrieve(int index)
Retrieves the item located on index.
final boolean containsAny(int... identifiers)
Determines if this container contains any identifiers.
final void ifPresent(int index, Consumer< Item > action)
Consumes an action if the index is a valid item index in this container.
final Item[] toArray()
Returns a shallow copy of the backing array.
An ItemContainerAdapter implementation that listens for changes to equipment.
void itemUpdated(ItemContainer container, Optional< Item > oldItem, Optional< Item > newItem, int index, boolean refresh, boolean login)
Fired when an Item is added, removed, or replaced.
void bulkItemsUpdated(ItemContainer container)
Fired when an Items are added, removed, or replaced in bulk.
boolean unequip(int equipmentIndex)
Unequips an Item from the underlying player's Equipment.
boolean contains(int[] bowsWithNoArrowsRequired)
void openInterface()
Handles opening the equipment screen itemcontainer.
void clear()
Removes all of the items from this container.
static final int EQUIPMENT_DISPLAY_ID
The equipment item display widget identifier.
void appearanceForIndex(int equipmentIndex)
Flags the APPEARANCE update block, only if the equipment piece on equipmentIndex requires an appearan...
static final int[] BONUS_IDS
An array of bonus ids.
Equipment(Player player)
Creates a new Equipment.
boolean add(Item item, int preferredIndex, boolean refresh)
Adds an item to the equipment container.
static final int HEAD_SLOT
Equipment slot constants.
static final int SIZE
The size of all equipment instances.
void manualWear(Item item)
Manually wears an item (does not have any restrictions).
void refresh()
Forces a refresh of Equipment items to the EQUIPMENT_DISPLAY_ID widget.
void manualWearAll(Item[] items)
Manually wears multiple items (does not have any restrictions).
boolean unequip(int equipmentIndex, int preferredIndex, ItemContainer container)
Unequips an Item from the underlying player's Equipment.
void login()
Handles refreshing all the equipment items.
static final String[] BONUS_NAMES
Item bonus names.
final Player player
The player who's equipment is being managed.
static final int STAB_OFFENSE
Equipment bonus constants.
void writeBonuses()
Writes a specific the bonus value on the equipment itemcontainer.
void refresh(Player player, int widget)
Forces a refresh of Equipment items to the EQUIPMENT_DISPLAY_ID widget.
static final ImmutableSet< Integer > NO_APPEARANCE
An ImmutableSet containing equipment indexes that don't require appearance updates.
static final String EXCEPTION_MESSAGE
The error message printed when certain functions from the superclass are utilized.
An ItemContainer implementation that manages the inventory for a Player.
Represents a single Ground item on the world map.
static GroundItem create(Player player, Item item)
Creates a new GroundItem object for a player and an item.
The OutgoingPacket that sends a message to a Players chatbox in the client.
The OutgoingPacket that sends a string to a Players itemcontainer in the client.
static final int SHAYZIEN_BOOTS_5_
Definition Items.java:13383
static final int SHAYZIEN_HELM_5_
Definition Items.java:13384
static final int SHAYZIEN_GLOVES_5_
Definition Items.java:13382
static final int SHAYZIEN_GREAVES_5_
Definition Items.java:13385
static final int SHAYZIEN_PLATEBODY_5_
Definition Items.java:13386
Handles miscellaneous methods.
Definition Utility.java:27
static String formatDigits(final int amount)
Formats digits for integers.
Definition Utility.java:41
static boolean checkRequirements(Player player, int[] requirements, String action)
Definition Utility.java:807
Holds the data for skillcape emotes.
static boolean equip(Player player, Item item)
static boolean isEquipped(Player player, SkillCape cape)
Represents different priorities for updating.
static RangedAmmunition find(Item weapon, Item item)
The enumerated type whose elements represent the weapon interfaces.
static void execute(Player player, Item item)
The method executed when weapon item is equipped or unequipped that assigns a weapon interface to pla...
An enumerated type defining policies for stackable Items.
STANDARD
The STANDARD policy, items are only stacked if they are defined as stackable in their ItemDefinition ...
The enumerated types of a players equipped item slots.