RuneHive-Game
Loading...
Searching...
No Matches
ItemDefinition.java
Go to the documentation of this file.
1package com.runehive.game.world.items;
2
3import com.google.common.collect.LinkedListMultimap;
4import com.google.gson.JsonElement;
5import com.google.gson.JsonObject;
6import com.runehive.Config;
7import com.runehive.game.world.entity.combat.attack.FightType;
8import com.runehive.game.world.entity.combat.ranged.RangedAmmunition;
9import com.runehive.game.world.entity.combat.ranged.RangedWeaponDefinition;
10import com.runehive.game.world.entity.combat.ranged.RangedWeaponType;
11import com.runehive.game.world.entity.combat.weapon.WeaponInterface;
12import com.runehive.game.world.entity.mob.MobAnimation;
13import com.runehive.game.world.items.containers.equipment.EquipmentType;
14import com.runehive.util.parser.GsonParser;
15import com.runehive.util.parser.JsonSaver;
16import org.jire.runehiveps.defs.ItemDefLoader;
17
18import java.util.*;
19
20import static com.runehive.game.world.entity.combat.CombatConstants.*;
21
22/**
23 * Represents all of an in-game Item's attributes.
24 *
25 * @author Michael | Chex
26 * @author Daniel | Obey
27 */
28public class ItemDefinition {
29
30 /**
31 * An array of item definitions.
32 */
33 public static ItemDefinition[] DEFINITIONS;
34 private static final Map<FightType, Integer> EMPTY = new HashMap<>();
35 public static final ItemDefinition DEFAULT = new ItemDefinition(1, "null");
36
37 private final int id;
38 private final String name;
39 private String destroyMessage;
40 private boolean destroyable;
41 private boolean stackable;
42 private boolean twoHanded;
43 private boolean tradeable;
44 private int stand_animation;
45 private int attack_anim;
46 private int walk_animation;
47 private int run_animation;
48 private Map<FightType, Integer> attack_animations;
49 private int block_animation;
50 private int unnotedId;
51 private int notedId;
52 private int street_value;
53 private int base_value;
54 private int highAlch;
55 private int lowAlch;
56 private double weight;
60 private int[] requirements;
61 private int[] bonuses;
62
63 public ItemDefinition(int id, String name) {
64 this.id = id;
65 this.name = name;
66 this.destroyMessage = null;
67 this.destroyable = false;
68 this.stackable = false;
69 this.tradeable = true;
70 this.twoHanded = false;
71 this.unnotedId = id;
72 this.notedId = id;
73 this.street_value = 0;
74 this.base_value = 0;
75 this.highAlch = 0;
76 this.lowAlch = 0;
77 this.weight = 0;
78 this.stand_animation = MobAnimation.PLAYER_STAND;
79 this.walk_animation = MobAnimation.PLAYER_WALK;
80 this.run_animation = MobAnimation.PLAYER_RUN;
81 this.attack_animations = EMPTY;
82 this.block_animation = -1;
83 this.equipmentType = EquipmentType.NOT_WIELDABLE;
84 this.weaponInterface = null;
85 this.rangedDefinition = null;
86 this.requirements = EMPTY_REQUIREMENTS;
87 this.bonuses = EMPTY_BONUSES;
88 }
89
90 public static GsonParser createParser() {
91 return new GsonParser("def/item/item_definitions", false) {
92
93 @Override
94 public void initialize(int size) {
96 }
97
98 @Override
99 protected void parse(JsonObject data) {
100 int id = data.get("id").getAsInt();
101 String name = data.get("name").getAsString();
102
103 ItemDefinition definition = new ItemDefinition(id, name);
104
105 if (data.has("destroyable")) {
106 definition.destroyable = data.get("destroyable").getAsBoolean();
107 }
108
109 if (data.has("destroy-message")) {
110 definition.destroyable = true;
111 definition.destroyMessage = data.get("destroy-message").getAsString();
112 }
113
114 if (data.has("stackable")) {
115 definition.stackable = data.get("stackable").getAsBoolean();
116 }
117
118 if (data.has("tradeable")) {
119 definition.tradeable = data.get("tradeable").getAsBoolean();
120 }
121
122 if (data.has("two-handed")) {
123 definition.twoHanded = data.get("two-handed").getAsBoolean();
124 }
125
126 if (data.has("noted-id")) {
127 definition.notedId = data.get("noted-id").getAsInt();
128 }
129
130 if (data.has("unnoted-id")) {
131 definition.unnotedId = data.get("unnoted-id").getAsInt();
132 }
133
134 if (data.has("street-value")) {
135 definition.street_value = data.get("street-value").getAsInt();
136 }
137
138 if (data.has("base-value")) {
139 definition.base_value = data.get("base-value").getAsInt();
140 }
141
142 if (data.has("high-alch")) {
143 definition.highAlch = data.get("high-alch").getAsInt();
144 }
145
146 if (data.has("low-alch")) {
147 definition.lowAlch = data.get("low-alch").getAsInt();
148 }
149
150 if (data.has("weight")) {
151 definition.weight = data.get("weight").getAsDouble();
152 }
153
154 if (data.has("equipment-slot")) {
155 definition.equipmentType = EquipmentType.valueOf(data.get("equipment-slot").getAsString());
156 }
157
158 if (data.has("weapon-interface")) {
159 definition.weaponInterface = WeaponInterface.valueOf(data.get("weapon-interface").getAsString());
160 }
161
162 for (int index = 0; index < SKILL_REQUIREMENT_CONFIG_FIELD_NAMES.length; index++) {
163 String skillRequirement = SKILL_REQUIREMENT_CONFIG_FIELD_NAMES[index];
164 if (data.has(skillRequirement)) {
165 if (definition.requirements == EMPTY_REQUIREMENTS) {
166 definition.requirements = new int[EMPTY_REQUIREMENTS.length];
167 }
168 definition.requirements[index] = data.get(skillRequirement).getAsInt();
169 }
170 }
171
172 for (int index = 0; index < BONUS_CONFIG_FIELD_NAMES.length; index++) {
173 String bonusName = BONUS_CONFIG_FIELD_NAMES[index];
174 if (data.has(bonusName)) {
175 if (definition.bonuses == EMPTY_BONUSES) {
176 definition.bonuses = new int[EMPTY_BONUSES.length];
177 }
178 definition.bonuses[index] = data.get(bonusName).getAsInt();
179 }
180 }
181
182 if (data.has("ranged-type") && data.has("allowed")) {
183 RangedWeaponType type = builder.fromJson(data.get("ranged-type"), RangedWeaponType.class);
184 RangedAmmunition[] allowed = builder.fromJson(data.get("allowed"), RangedAmmunition[].class);
185 definition.rangedDefinition = new RangedWeaponDefinition(type, allowed);
186 }
187
188 if (data.has("stand-animation")) {
189 definition.stand_animation = data.get("stand-animation").getAsInt();
190 }
191
192 if (data.has("walk-animation")) {
193 definition.walk_animation = data.get("walk-animation").getAsInt();
194 }
195
196 if (data.has("run-animation")) {
197 definition.run_animation = data.get("run-animation").getAsInt();
198 }
199
200 if (data.has("attack-animations")) {
201 JsonObject object = (JsonObject) data.get("attack-animations");
202 definition.attack_animations = new HashMap<>(object.entrySet().size());
203
204 for (Map.Entry<String, JsonElement> entry : object.entrySet()) {
205 FightType fightType = FightType.valueOf(entry.getKey());
206 int animation = entry.getValue().getAsInt();
207
208 definition.attack_animations.put(fightType, animation);
209 }
210 }
211
212 if (data.has("block-animation")) {
213 definition.block_animation = data.get("block-animation").getAsInt();
214 }
215
216 DEFINITIONS[id] = definition;
217 }
218
219 @Override
220 protected void onEnd() {
221 ItemDefLoader.load();
222 }
223 };
224 }
225
226 public static ItemDefinition[] create(String path) {
228
229 new GsonParser(path) {
230
231 @Override
232 public void initialize(int size) {
233 createParser().run();
234 }
235
236 @Override
237 protected void parse(JsonObject data) {
238 int id = data.get("id").getAsInt();
239 String name = data.get("name").getAsString();
240
241 ItemDefinition definition = definitions[id] = new ItemDefinition(id, name);
243
244 if (data.has("destroyable")) {
245 definition.destroyable = data.get("destroyable").getAsBoolean();
246 }
247
248 if (data.has("destroy-message")) {
249 definition.destroyable = true;
250 definition.destroyMessage = data.get("destroy-message").getAsString();
251 }
252
253 if (data.has("stackable")) {
254 definition.stackable = data.get("stackable").getAsBoolean();
255 }
256
257 if (data.has("tradeable")) {
258 definition.tradeable = data.get("tradeable").getAsBoolean();
259 }
260
261 if (data.has("two-handed")) {
262 definition.twoHanded = data.get("two-handed").getAsBoolean();
263 }
264
265 if (data.has("noted-id")) {
266 definition.notedId = data.get("noted-id").getAsInt();
267 }
268
269 if (data.has("unnoted-id")) {
270 definition.unnotedId = data.get("unnoted-id").getAsInt();
271 }
272
273 if (data.has("street-value")) {
274 definition.street_value = data.get("street-value").getAsInt();
275 } else if (old != null) {
276 definition.street_value = old.street_value;
277 }
278
279 if (data.has("base-value")) {
280 definition.base_value = data.get("base-value").getAsInt();
281 }
282
283 if (data.has("high-alch")) {
284 definition.highAlch = data.get("high-alch").getAsInt();
285 }
286
287 if (data.has("low-alch")) {
288 definition.lowAlch = data.get("low-alch").getAsInt();
289 }
290
291 if (data.has("weight")) {
292 definition.weight = data.get("weight").getAsDouble();
293 }
294
295 if (old != null && old.equipmentType != EquipmentType.NOT_WIELDABLE) {
296 definition.equipmentType = old.equipmentType;
297 } else if (data.has("equipment-slot")) {
298 definition.equipmentType = EquipmentType.valueOf(data.get("equipment-slot").getAsString());
299 }
300
301 for (int index = 0; index < BONUS_CONFIG_FIELD_NAMES.length; index++) {
302 String bonusName = BONUS_CONFIG_FIELD_NAMES[index];
303 if (data.has(bonusName)) {
304 if (definition.bonuses == EMPTY_BONUSES) {
305 definition.bonuses = new int[EMPTY_BONUSES.length];
306 }
307 definition.bonuses[index] = data.get(bonusName).getAsInt();
308 }
309 }
310
311 if (old != null) {
312 definition.weaponInterface = old.weaponInterface;
313 definition.requirements = old.requirements;
314 definition.rangedDefinition = old.rangedDefinition;
315 definition.stand_animation = old.stand_animation;
316 definition.walk_animation = old.walk_animation;
317 definition.run_animation = old.run_animation;
318 definition.attack_animations = old.attack_animations;
319 definition.block_animation = old.block_animation;
320 }
321 }
322 }.run();
323
324 return definitions;
325 }
326
327 public static ItemDefinition[] fromClientDump(String path) {
329
330 new GsonParser(path) {
331 @Override
332 protected void parse(JsonObject data) {
333 int id = data.get("id").getAsInt();
334 String name = data.get("name").getAsString();
335
336 ItemDefinition definition = definitions[id] = new ItemDefinition(id, name);
337
338 if (data.has("stackable")) {
339 definition.stackable = data.get("stackable").getAsBoolean();
340 }
341 if (data.has("destroyable")) {
342 definition.destroyable = data.get("destroyable").getAsBoolean();
343 }
344 if (data.has("noted-id")) {
345 definition.notedId = data.get("noted-id").getAsInt();
346 }
347 if (data.has("unnoted-id")) {
348 definition.unnotedId = data.get("unnoted-id").getAsInt();
349 }
350 if (data.has("base-value")) {
351 definition.base_value = data.get("base-value").getAsInt();
352 definition.lowAlch = (int) (definition.base_value * 0.40);
353 definition.highAlch = (int) (definition.base_value * 0.60);
354 }
355 if (data.has("equipment-type")) {
356 definition.equipmentType = EquipmentType.valueOf(data.get("equipment-type").getAsString());
357 }
358 }
359 }.run();
360
361 return definitions;
362 }
363
364 public static void merge(String clientDumpFilePath, String wikiDumpPath, String dumpPath) {
365 new GsonParser(wikiDumpPath) {
366 LinkedListMultimap<String, JsonObject> multimap = LinkedListMultimap.create();
367
368 @Override
369 protected void parse(JsonObject data) {
370 String name = data.get("name").getAsString();
371
372 if (name.isEmpty())
373 return;
374
375 multimap.put(name, data);
376 }
377
378 @Override
379 protected void onEnd() {
380 ItemDefinition[] definitions = fromClientDump(clientDumpFilePath);
381
382 for (ItemDefinition definition : definitions) {
383 if (definition == null || definition.name.equals("null") || definition.name.isEmpty())
384 continue;
385
386 if (!multimap.containsKey(definition.name))
387 continue;
388
389 List<JsonObject> value = multimap.get(definition.name);
390 JsonObject object = value.get(value.size() - 1);
391
392 if (value.size() > 1)
393 multimap.remove(definition.name, object);
394
395 if (object.has("destroy-message"))
396 definition.destroyMessage = object.get("destroy-message").getAsString();
397
398 if (object.has("tradable"))
399 definition.tradeable = object.get("tradable").getAsBoolean();
400
401 if (object.has("weight"))
402 definition.weight = object.get("weight").getAsDouble();
403
404 if (definition.isNoted()) {
405 continue;
406 }
407
408 if (object.has("two-handed"))
409 definition.twoHanded = object.get("two-handed").getAsBoolean();
410
411 if (object.has("equipment-type"))
412 definition.equipmentType = EquipmentType.valueOf(object.get("equipment-type").getAsString());
413
414 for (int index = 0; index < BONUS_CONFIG_FIELD_NAMES.length; index++) {
415 String bonusName = BONUS_CONFIG_FIELD_NAMES[index];
416 if (object.has(bonusName)) {
417 if (definition.bonuses == EMPTY_BONUSES) {
418 definition.bonuses = new int[EMPTY_BONUSES.length];
419 }
420 definition.bonuses[index] = object.get(bonusName).getAsInt();
421 }
422 }
423 }
424
425 DEFINITIONS = definitions;
426 dump(dumpPath);
427 }
428
429 }.run();
430 }
431
432 public static void dump(ItemDefinition[] definitions, String path) {
433 JsonSaver saver = new JsonSaver();
434
435 for (ItemDefinition definition : definitions) {
436 if (definition == null) continue;
437 if (definition.name.equals("null")) continue;
438
439 saver.current().addProperty("id", definition.id);
440 saver.current().addProperty("name", definition.name);
441
442 if (definition.destroyMessage != null) {
443 saver.current().addProperty("destroy-message", definition.destroyMessage);
444 } else if (definition.destroyable) {
445 saver.current().addProperty("destroyable", true);
446 }
447
448 if (definition.stackable) {
449 saver.current().addProperty("stackable", true);
450 }
451
452 if (!definition.tradeable) {
453 saver.current().addProperty("tradeable", false);
454 }
455
456 if (definition.twoHanded) {
457 saver.current().addProperty("two-handed", true);
458 }
459
460 if (definition.unnotedId != definition.id) {
461 saver.current().addProperty("unnoted-id", definition.unnotedId);
462 }
463
464 if (definition.notedId != definition.id) {
465 saver.current().addProperty("noted-id", definition.notedId);
466 }
467
468 if (definition.lowAlch > 1) {
469 saver.current().addProperty("low-alch", definition.lowAlch);
470 }
471
472 if (definition.highAlch > 1) {
473 saver.current().addProperty("high-alch", definition.highAlch);
474 }
475
476 if (definition.base_value > 1) {
477 saver.current().addProperty("base-value", definition.base_value);
478 }
479
480 if (definition.street_value > 1) {
481 saver.current().addProperty("street-value", definition.street_value);
482 }
483
484 if (definition.weight != 0) {
485 saver.current().addProperty("weight", definition.weight);
486 }
487
488 if (definition.stand_animation != MobAnimation.PLAYER_STAND) {
489 saver.current().addProperty("stand-animation", definition.stand_animation);
490 }
491
492 if (definition.walk_animation != MobAnimation.PLAYER_WALK) {
493 saver.current().addProperty("walk-animation", definition.walk_animation);
494 }
495
496 if (definition.run_animation != MobAnimation.PLAYER_RUN) {
497 saver.current().addProperty("run-animation", definition.run_animation);
498 }
499
500 if (definition.attack_animations != EMPTY) {
501 saver.current().add("attack-animations", saver.serializer().toJsonTree(definition.attack_animations));
502 }
503
504 if (definition.block_animation != -1) {
505 saver.current().addProperty("block-animation", definition.block_animation);
506 }
507
508 if (definition.equipmentType != EquipmentType.NOT_WIELDABLE) {
509 saver.current().addProperty("equipment-slot", definition.equipmentType.name());
510 }
511
512 if (definition.weaponInterface != null && definition.weaponInterface != WeaponInterface.UNARMED) {
513 saver.current().addProperty("weapon-interface", definition.weaponInterface.name());
514 }
515
516 for (int index = 0; index < SKILL_REQUIREMENT_CONFIG_FIELD_NAMES.length; index++) {
517 if (definition.requirements[index] > 0)
518 saver.current().addProperty(SKILL_REQUIREMENT_CONFIG_FIELD_NAMES[index], definition.requirements[index]);
519 }
520
521 for (int index = 0; index < BONUS_CONFIG_FIELD_NAMES.length; index++) {
522 if (definition.bonuses[index] != 0)
523 saver.current().addProperty(BONUS_CONFIG_FIELD_NAMES[index], definition.bonuses[index]);
524 }
525
526 if (definition.rangedDefinition != null) {
527 saver.current().addProperty("ranged-type", definition.rangedDefinition.getType().name());
528 saver.current().add("allowed", saver.serializer().toJsonTree(definition.rangedDefinition.getAllowed()));
529 }
530
531 saver.split();
532 }
533
534 saver.publish("./data/" + path + ".json");
535 }
536
537 public static void dump(String path) {
538 JsonSaver saver = new JsonSaver();
539
540 for (ItemDefinition definition : DEFINITIONS) {
541 if (definition == null) continue;
542 if (definition.name.equals("null")) continue;
543
544 saver.current().addProperty("id", definition.id);
545 saver.current().addProperty("name", definition.name);
546
547 if (definition.destroyMessage != null) {
548 saver.current().addProperty("destroy-message", definition.destroyMessage);
549 } else if (definition.destroyable) {
550 saver.current().addProperty("destroyable", true);
551 }
552
553 if (definition.stackable) {
554 saver.current().addProperty("stackable", true);
555 }
556
557 if (!definition.tradeable) {
558 saver.current().addProperty("tradeable", false);
559 }
560
561 if (definition.twoHanded) {
562 saver.current().addProperty("two-handed", true);
563 }
564
565 if (definition.unnotedId != definition.id) {
566 saver.current().addProperty("unnoted-id", definition.unnotedId);
567 }
568
569 if (definition.notedId != definition.id) {
570 saver.current().addProperty("noted-id", definition.notedId);
571 }
572
573 if (definition.lowAlch > 1) {
574 saver.current().addProperty("low-alch", definition.lowAlch);
575 }
576
577 if (definition.highAlch > 1) {
578 saver.current().addProperty("high-alch", definition.highAlch);
579 }
580
581 if (definition.base_value > 1) {
582 saver.current().addProperty("base-value", definition.base_value);
583 }
584
585 if (definition.street_value > 1) {
586 saver.current().addProperty("street-value", definition.street_value);
587 }
588
589 if (definition.weight != 0) {
590 saver.current().addProperty("weight", definition.weight);
591 }
592
593 if (definition.stand_animation != MobAnimation.PLAYER_STAND) {
594 saver.current().addProperty("stand-animation", definition.stand_animation);
595 }
596
597 if (definition.walk_animation != MobAnimation.PLAYER_WALK) {
598 saver.current().addProperty("walk-animation", definition.walk_animation);
599 }
600
601 if (definition.run_animation != MobAnimation.PLAYER_RUN) {
602 saver.current().addProperty("run-animation", definition.run_animation);
603 }
604
605 if (definition.attack_animations != EMPTY) {
606 saver.current().add("attack-animations", saver.serializer().toJsonTree(definition.attack_animations));
607 }
608
609 if (definition.block_animation != -1) {
610 saver.current().addProperty("block-animation", definition.block_animation);
611 }
612
613 if (definition.equipmentType != EquipmentType.NOT_WIELDABLE) {
614 saver.current().addProperty("equipment-slot", definition.equipmentType.name());
615 }
616
617 if (definition.weaponInterface != null && definition.weaponInterface != WeaponInterface.UNARMED) {
618 saver.current().addProperty("weapon-interface", definition.weaponInterface.name());
619 }
620
621 for (int index = 0; index < SKILL_REQUIREMENT_CONFIG_FIELD_NAMES.length; index++) {
622 if (definition.requirements[index] > 0)
623 saver.current().addProperty(SKILL_REQUIREMENT_CONFIG_FIELD_NAMES[index], definition.requirements[index]);
624 }
625
626 for (int index = 0; index < BONUS_CONFIG_FIELD_NAMES.length; index++) {
627 if (definition.bonuses[index] != 0)
628 saver.current().addProperty(BONUS_CONFIG_FIELD_NAMES[index], definition.bonuses[index]);
629 }
630
631 if (definition.rangedDefinition != null) {
632 saver.current().addProperty("ranged-type", definition.rangedDefinition.getType().name());
633 saver.current().add("allowed", saver.serializer().toJsonTree(definition.rangedDefinition.getAllowed()));
634 }
635
636 saver.split();
637 }
638
639 saver.publish("./data/" + path + ".json");
640 }
641
642 /**
643 * Gets an item definition.
644 *
645 * @param id The definition's item id.
646 * @return The item definition for the item id, or null if the item id is
647 * out of bounds.
648 */
649 public static ItemDefinition get(int id) {
650 if (id < 0 || id >= DEFINITIONS.length) {
651 return DEFAULT;
652 }
653
654 if (DEFINITIONS[id] == null) {
655 return DEFINITIONS[id] = new ItemDefinition(id, "null");
656 }
657
658
659 return DEFINITIONS[id];
660 }
661
662 /**
663 * Gets the item id.
664 *
665 * @return The item id.
666 */
667 public int getId() {
668 return id;
669 }
670
671 /**
672 * Gets the item name.
673 *
674 * @return The item name.
675 */
676 public String getName() {
677 return name;
678 }
679
680 /**
681 * Gets the item destroy message.
682 *
683 * @return The item destroy message.
684 */
685 public String getDestroyMessage() {
686 return destroyMessage;
687 }
688
689 /**
690 * Gets the item note state.
691 *
692 * @return {@code True} if the item is noted;
693 */
694 public boolean isNoted() {
695 return unnotedId != id;
696 }
697
698 /**
699 * Gets the item notability state.
700 *
701 * @return {@code} if the item can be turned into a note.
702 */
703 public boolean isNoteable() {
704 return notedId != id;
705 }
706
707 /**
708 * Gets the noted id.
709 *
710 * @return The noted id of this item if this item is un-noted, or the
711 * original item id if it is already un-noted.
712 */
713 public int getNotedId() {
714 return notedId;
715 }
716
717 /**
718 * Gets the un-noted id.
719 *
720 * @return The un-noted id of this item if this item is noted, or the
721 * original item id if it is already un-noted.
722 */
723 public int getUnnotedId() {
724 return unnotedId;
725 }
726
727 /**
728 * Gets the item stackability state.
729 *
730 * @return {@code True} if the item can be stacked.
731 */
732 public boolean isStackable() {
733 return stackable;
734 }
735
736 /**
737 * Gets the item destroyable state.
738 *
739 * @return {@code true} if the item can be destroyed
740 */
741 public boolean isDestroyable() {
742 return destroyMessage != null;
743 }
744
745 /**
746 * Gets the item tradability state.
747 *
748 * @return {@code True} if the item is tradable.
749 */
750 public boolean isTradeable() {
751 return tradeable;
752 }
753
754 /**
755 * Gets the item value.
756 *
757 * @return The value.
758 */
759 public int getStreetValue() {
760 return street_value;
761 }
762
763 /**
764 * Gets the item value.
765 *
766 * @return The value.
767 */
768 public int getBaseValue() {
769 return base_value;
770 }
771
772 /**
773 * Gets the item value.
774 *
775 * @return The value.
776 */
777 public int getValue() {
778 return street_value > 0 ? street_value : base_value;
779 }
780
781 /**
782 * Gets the high alchemy item value.
783 *
784 * @return The value.
785 */
786 public int getHighAlch() {
787 return getValue() / 2;
788 }
789
790 /**
791 * Gets the low alchemy item value.
792 *
793 * @return The value.
794 */
795 public int getLowAlch() {
796 return getValue() / 5;
797// return lowAlch;
798 }
799
800 public EquipmentType getEquipmentType() {
801 return equipmentType;
802 }
803
804 public int[] getRequirements() {
805 return requirements;
806 }
807
808 public int[] getBonuses() {
809 return bonuses;
810 }
811
812 /**
813 * Gets the item equipability state.
814 *
815 * @return {@code True} if the item is equipable.
816 */
817 public boolean isEquipable() {
818 return equipmentType != EquipmentType.NOT_WIELDABLE;
819 }
820
821 public boolean isTwoHanded() {
822 return twoHanded;
823 }
824
825 /**
826 * Gets the item weapon state.
827 *
828 * @return {@code True} if the item is a weapon.
829 */
830 public boolean isWeapon() {
831 return EquipmentType.WEAPON.equals(equipmentType);
832 }
833
834 /**
835 * Gets the item's weight.
836 *
837 * @return The item weight.
838 */
839 public double getWeight() {
840 return weight;
841 }
842
843 public int getStandAnimation() {
844 return stand_animation;
845 }
846
847 public int getWalkAnimation() {
848 return walk_animation;
849 }
850
851 public int getRunAnimation() {
852 return run_animation;
853 }
854
855 public OptionalInt getAttackAnimation(FightType fightType) {
856 if (attack_animations == EMPTY) {
857 return OptionalInt.empty();
858 }
859
860 return OptionalInt.of(attack_animations.get(fightType));
861 }
862
863 public OptionalInt getBlockAnimation() {
864 return block_animation == -1 ? OptionalInt.empty() : OptionalInt.of(block_animation);
865 }
866
867 public Optional<RangedWeaponDefinition> getRangedDefinition() {
868 return Optional.ofNullable(rangedDefinition);
869 }
870
871 public WeaponInterface getWeaponInterface() {
872 return weaponInterface;
873 }
874
875 public void setEquipmentType(EquipmentType equipmentType) {
876 this.equipmentType = equipmentType;
877 }
878
879 public boolean isPotion() {
880 return this.name != null && (this.name.toLowerCase().contains("potion") || this.name.toLowerCase().contains("brew") || this.name.toLowerCase().contains("sanfew") || this.name.toLowerCase().contains("restore"));
881 }
882
883 public static ItemDefinition[] getDEFINITIONS() {
884 return DEFINITIONS;
885 }
886
887 public static void setDEFINITIONS(ItemDefinition[] DEFINITIONS) {
888 ItemDefinition.DEFINITIONS = DEFINITIONS;
889 }
890
891 public void setDestroyMessage(String destroyMessage) {
892 this.destroyMessage = destroyMessage;
893 }
894
895 public void setDestroyable(boolean destroyable) {
896 this.destroyable = destroyable;
897 }
898
899 public void setStackable(boolean stackable) {
900 this.stackable = stackable;
901 }
902
903 public void setTwoHanded(boolean twoHanded) {
904 this.twoHanded = twoHanded;
905 }
906
907 public void setTradeable(boolean tradeable) {
908 this.tradeable = tradeable;
909 }
910
911 public int getStand_animation() {
912 return stand_animation;
913 }
914
915 public void setStand_animation(int stand_animation) {
916 this.stand_animation = stand_animation;
917 }
918
919 public int getAttack_anim() {
920 return attack_anim;
921 }
922
923 public void setAttack_anim(int attack_anim) {
924 this.attack_anim = attack_anim;
925 }
926
927 public int getWalk_animation() {
928 return walk_animation;
929 }
930
931 public void setWalk_animation(int walk_animation) {
932 this.walk_animation = walk_animation;
933 }
934
935 public int getRun_animation() {
936 return run_animation;
937 }
938
939 public void setRun_animation(int run_animation) {
940 this.run_animation = run_animation;
941 }
942
943 public Map<FightType, Integer> getAttack_animations() {
944 return attack_animations;
945 }
946
947 public void setAttack_animations(Map<FightType, Integer> attack_animations) {
948 this.attack_animations = attack_animations;
949 }
950
951 public int getBlock_animation() {
952 return block_animation;
953 }
954
955 public void setBlock_animation(int block_animation) {
956 this.block_animation = block_animation;
957 }
958
959 public void setUnnotedId(int unnotedId) {
960 this.unnotedId = unnotedId;
961 }
962
963 public void setNotedId(int notedId) {
964 this.notedId = notedId;
965 }
966
967 public int getStreet_value() {
968 return street_value;
969 }
970
971 public void setStreet_value(int street_value) {
972 this.street_value = street_value;
973 }
974
975 public int getBase_value() {
976 return base_value;
977 }
978
979 public void setBase_value(int base_value) {
980 this.base_value = base_value;
981 }
982
983 public void setHighAlch(int highAlch) {
984 this.highAlch = highAlch;
985 }
986
987 public void setLowAlch(int lowAlch) {
988 this.lowAlch = lowAlch;
989 }
990
991 public void setWeight(double weight) {
992 this.weight = weight;
993 }
994
995 public void setWeaponInterface(WeaponInterface weaponInterface) {
996 this.weaponInterface = weaponInterface;
997 }
998
999 public void setRangedDefinition(RangedWeaponDefinition rangedDefinition) {
1000 this.rangedDefinition = rangedDefinition;
1001 }
1002
1003 public void setRequirements(int[] requirements) {
1004 this.requirements = requirements;
1005 }
1006
1007 public void setBonuses(int[] bonuses) {
1008 this.bonuses = bonuses;
1009 }
1010}
The class that contains setting-related constants for the server.
Definition Config.java:24
static final int ITEM_DEFINITION_LIMIT
The limit of the item identification.
Definition Config.java:181
boolean isNoted()
Gets the item note state.
static void dump(ItemDefinition[] definitions, String path)
static ItemDefinition[] create(String path)
String getDestroyMessage()
Gets the item destroy message.
static ItemDefinition[] fromClientDump(String path)
static final Map< FightType, Integer > EMPTY
static void merge(String clientDumpFilePath, String wikiDumpPath, String dumpPath)
static ItemDefinition[] DEFINITIONS
An array of item definitions.
This class provides an easy to use google gson parser specifically designed for parsing JSON files.
A util class used for constructing and writing JSON files.
void split()
Adds the data within currentWriter to the internal JsonArray then instantiates a new writer,...
void publish(String path)
Publishes the contents of this JsonSaver to the file at path.
final Gson serializer
A gson builder, allows us to turn Objects into JSON format and vice-versa.
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.
override fun getAttackAnimation(attacker:Npc, defender:Mob)