1package com.runehive.game.world.items;
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;
20import static com.runehive.game.world.entity.combat.CombatConstants.*;
34 private static final Map<FightType, Integer>
EMPTY =
new HashMap<>();
66 this.destroyMessage =
null;
67 this.destroyable =
false;
68 this.stackable =
false;
69 this.tradeable =
true;
70 this.twoHanded =
false;
73 this.street_value = 0;
81 this.attack_animations =
EMPTY;
82 this.block_animation = -1;
84 this.weaponInterface =
null;
85 this.rangedDefinition =
null;
86 this.requirements = EMPTY_REQUIREMENTS;
87 this.bonuses = EMPTY_BONUSES;
91 return new GsonParser(
"def/item/item_definitions",
false) {
94 public void initialize(
int size) {
99 protected void parse(JsonObject data) {
100 int id = data.get(
"id").getAsInt();
101 String
name = data.get(
"name").getAsString();
105 if (data.has(
"destroyable")) {
106 definition.destroyable = data.get(
"destroyable").getAsBoolean();
109 if (data.has(
"destroy-message")) {
110 definition.destroyable =
true;
111 definition.destroyMessage = data.get(
"destroy-message").getAsString();
114 if (data.has(
"stackable")) {
115 definition.stackable = data.get(
"stackable").getAsBoolean();
118 if (data.has(
"tradeable")) {
119 definition.tradeable = data.get(
"tradeable").getAsBoolean();
122 if (data.has(
"two-handed")) {
123 definition.twoHanded = data.get(
"two-handed").getAsBoolean();
126 if (data.has(
"noted-id")) {
127 definition.notedId = data.get(
"noted-id").getAsInt();
130 if (data.has(
"unnoted-id")) {
131 definition.unnotedId = data.get(
"unnoted-id").getAsInt();
134 if (data.has(
"street-value")) {
135 definition.street_value = data.get(
"street-value").getAsInt();
138 if (data.has(
"base-value")) {
139 definition.base_value = data.get(
"base-value").getAsInt();
142 if (data.has(
"high-alch")) {
143 definition.highAlch = data.get(
"high-alch").getAsInt();
146 if (data.has(
"low-alch")) {
147 definition.lowAlch = data.get(
"low-alch").getAsInt();
150 if (data.has(
"weight")) {
151 definition.weight = data.get(
"weight").getAsDouble();
154 if (data.has(
"equipment-slot")) {
155 definition.equipmentType =
EquipmentType.valueOf(data.get(
"equipment-slot").getAsString());
158 if (data.has(
"weapon-interface")) {
159 definition.weaponInterface =
WeaponInterface.valueOf(data.get(
"weapon-interface").getAsString());
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)) {
166 definition.requirements =
new int[EMPTY_REQUIREMENTS.length];
168 definition.
requirements[index] = data.get(skillRequirement).getAsInt();
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];
178 definition.
bonuses[index] = data.get(bonusName).getAsInt();
182 if (data.has(
"ranged-type") && data.has(
"allowed")) {
188 if (data.has(
"stand-animation")) {
189 definition.stand_animation = data.get(
"stand-animation").getAsInt();
192 if (data.has(
"walk-animation")) {
193 definition.walk_animation = data.get(
"walk-animation").getAsInt();
196 if (data.has(
"run-animation")) {
197 definition.run_animation = data.get(
"run-animation").getAsInt();
200 if (data.has(
"attack-animations")) {
201 JsonObject
object = (JsonObject) data.get(
"attack-animations");
202 definition.attack_animations =
new HashMap<>(
object.entrySet().size());
204 for (Map.Entry<String, JsonElement> entry :
object.entrySet()) {
206 int animation = entry.getValue().getAsInt();
212 if (data.has(
"block-animation")) {
213 definition.block_animation = data.get(
"block-animation").getAsInt();
220 protected void onEnd() {
232 public void initialize(
int size) {
237 protected void parse(JsonObject data) {
238 int id = data.get(
"id").getAsInt();
239 String
name = data.get(
"name").getAsString();
244 if (data.has(
"destroyable")) {
245 definition.destroyable = data.get(
"destroyable").getAsBoolean();
248 if (data.has(
"destroy-message")) {
249 definition.destroyable =
true;
250 definition.destroyMessage = data.get(
"destroy-message").getAsString();
253 if (data.has(
"stackable")) {
254 definition.stackable = data.get(
"stackable").getAsBoolean();
257 if (data.has(
"tradeable")) {
258 definition.tradeable = data.get(
"tradeable").getAsBoolean();
261 if (data.has(
"two-handed")) {
262 definition.twoHanded = data.get(
"two-handed").getAsBoolean();
265 if (data.has(
"noted-id")) {
266 definition.notedId = data.get(
"noted-id").getAsInt();
269 if (data.has(
"unnoted-id")) {
270 definition.unnotedId = data.get(
"unnoted-id").getAsInt();
273 if (data.has(
"street-value")) {
274 definition.street_value = data.get(
"street-value").getAsInt();
275 }
else if (old !=
null) {
279 if (data.has(
"base-value")) {
280 definition.base_value = data.get(
"base-value").getAsInt();
283 if (data.has(
"high-alch")) {
284 definition.highAlch = data.get(
"high-alch").getAsInt();
287 if (data.has(
"low-alch")) {
288 definition.lowAlch = data.get(
"low-alch").getAsInt();
291 if (data.has(
"weight")) {
292 definition.weight = data.get(
"weight").getAsDouble();
297 }
else if (data.has(
"equipment-slot")) {
298 definition.equipmentType =
EquipmentType.valueOf(data.get(
"equipment-slot").getAsString());
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];
307 definition.
bonuses[index] = data.get(bonusName).getAsInt();
332 protected void parse(JsonObject data) {
333 int id = data.get(
"id").getAsInt();
334 String
name = data.get(
"name").getAsString();
338 if (data.has(
"stackable")) {
339 definition.stackable = data.get(
"stackable").getAsBoolean();
341 if (data.has(
"destroyable")) {
342 definition.destroyable = data.get(
"destroyable").getAsBoolean();
344 if (data.has(
"noted-id")) {
345 definition.notedId = data.get(
"noted-id").getAsInt();
347 if (data.has(
"unnoted-id")) {
348 definition.unnotedId = data.get(
"unnoted-id").getAsInt();
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);
355 if (data.has(
"equipment-type")) {
356 definition.equipmentType =
EquipmentType.valueOf(data.get(
"equipment-type").getAsString());
364 public static void merge(String clientDumpFilePath, String wikiDumpPath, String dumpPath) {
366 LinkedListMultimap<String, JsonObject> multimap = LinkedListMultimap.create();
369 protected void parse(JsonObject data) {
370 String
name = data.get(
"name").getAsString();
375 multimap.put(
name, data);
379 protected void onEnd() {
383 if (definition ==
null || definition.name.equals(
"null") || definition.name.isEmpty())
386 if (!multimap.containsKey(definition.name))
389 List<JsonObject> value = multimap.get(definition.name);
390 JsonObject
object = value.get(value.size() - 1);
392 if (value.size() > 1)
393 multimap.remove(definition.name,
object);
395 if (
object.has(
"destroy-message"))
396 definition.destroyMessage =
object.get(
"destroy-message").getAsString();
398 if (
object.has(
"tradable"))
399 definition.tradeable =
object.get(
"tradable").getAsBoolean();
401 if (
object.has(
"weight"))
402 definition.weight =
object.get(
"weight").getAsDouble();
404 if (definition.isNoted()) {
408 if (
object.has(
"two-handed"))
409 definition.twoHanded =
object.get(
"two-handed").getAsBoolean();
411 if (
object.has(
"equipment-type"))
412 definition.equipmentType =
EquipmentType.valueOf(
object.
get(
"equipment-type").getAsString());
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];
420 definition.bonuses[index] =
object.get(bonusName).getAsInt();
436 if (definition ==
null)
continue;
437 if (definition.name.equals(
"null"))
continue;
439 saver.
current().addProperty(
"id", definition.id);
440 saver.
current().addProperty(
"name", definition.name);
442 if (definition.destroyMessage !=
null) {
443 saver.
current().addProperty(
"destroy-message", definition.destroyMessage);
444 }
else if (definition.destroyable) {
445 saver.
current().addProperty(
"destroyable",
true);
448 if (definition.stackable) {
449 saver.
current().addProperty(
"stackable",
true);
452 if (!definition.tradeable) {
453 saver.
current().addProperty(
"tradeable",
false);
456 if (definition.twoHanded) {
457 saver.
current().addProperty(
"two-handed",
true);
460 if (definition.unnotedId != definition.id) {
461 saver.
current().addProperty(
"unnoted-id", definition.unnotedId);
464 if (definition.notedId != definition.id) {
465 saver.
current().addProperty(
"noted-id", definition.notedId);
468 if (definition.lowAlch > 1) {
469 saver.
current().addProperty(
"low-alch", definition.lowAlch);
472 if (definition.highAlch > 1) {
473 saver.
current().addProperty(
"high-alch", definition.highAlch);
476 if (definition.base_value > 1) {
477 saver.
current().addProperty(
"base-value", definition.base_value);
480 if (definition.street_value > 1) {
481 saver.
current().addProperty(
"street-value", definition.street_value);
484 if (definition.weight != 0) {
485 saver.
current().addProperty(
"weight", definition.weight);
489 saver.
current().addProperty(
"stand-animation", definition.stand_animation);
493 saver.
current().addProperty(
"walk-animation", definition.walk_animation);
497 saver.
current().addProperty(
"run-animation", definition.run_animation);
500 if (definition.attack_animations !=
EMPTY) {
501 saver.
current().add(
"attack-animations", saver.
serializer().toJsonTree(definition.attack_animations));
504 if (definition.block_animation != -1) {
505 saver.
current().addProperty(
"block-animation", definition.block_animation);
509 saver.
current().addProperty(
"equipment-slot", definition.equipmentType.name());
513 saver.
current().addProperty(
"weapon-interface", definition.weaponInterface.name());
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]);
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]);
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()));
534 saver.
publish(
"./data/" + path +
".json");
537 public static void dump(String path) {
541 if (definition ==
null)
continue;
542 if (definition.name.equals(
"null"))
continue;
544 saver.
current().addProperty(
"id", definition.id);
545 saver.
current().addProperty(
"name", definition.name);
547 if (definition.destroyMessage !=
null) {
548 saver.
current().addProperty(
"destroy-message", definition.destroyMessage);
549 }
else if (definition.destroyable) {
550 saver.
current().addProperty(
"destroyable",
true);
553 if (definition.stackable) {
554 saver.
current().addProperty(
"stackable",
true);
557 if (!definition.tradeable) {
558 saver.
current().addProperty(
"tradeable",
false);
561 if (definition.twoHanded) {
562 saver.
current().addProperty(
"two-handed",
true);
565 if (definition.unnotedId != definition.id) {
566 saver.
current().addProperty(
"unnoted-id", definition.unnotedId);
569 if (definition.notedId != definition.id) {
570 saver.
current().addProperty(
"noted-id", definition.notedId);
573 if (definition.lowAlch > 1) {
574 saver.
current().addProperty(
"low-alch", definition.lowAlch);
577 if (definition.highAlch > 1) {
578 saver.
current().addProperty(
"high-alch", definition.highAlch);
581 if (definition.base_value > 1) {
582 saver.
current().addProperty(
"base-value", definition.base_value);
585 if (definition.street_value > 1) {
586 saver.
current().addProperty(
"street-value", definition.street_value);
589 if (definition.weight != 0) {
590 saver.
current().addProperty(
"weight", definition.weight);
594 saver.
current().addProperty(
"stand-animation", definition.stand_animation);
598 saver.
current().addProperty(
"walk-animation", definition.walk_animation);
602 saver.
current().addProperty(
"run-animation", definition.run_animation);
605 if (definition.attack_animations !=
EMPTY) {
606 saver.
current().add(
"attack-animations", saver.
serializer().toJsonTree(definition.attack_animations));
609 if (definition.block_animation != -1) {
610 saver.
current().addProperty(
"block-animation", definition.block_animation);
614 saver.
current().addProperty(
"equipment-slot", definition.equipmentType.name());
618 saver.
current().addProperty(
"weapon-interface", definition.weaponInterface.name());
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]);
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]);
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()));
639 saver.
publish(
"./data/" + path +
".json");
703 public boolean isNoteable() {
713 public int getNotedId() {
723 public int getUnnotedId() {
732 public boolean isStackable() {
741 public boolean isDestroyable() {
750 public boolean isTradeable() {
759 public int getStreetValue() {
768 public int getBaseValue() {
777 public int getValue() {
786 public int getHighAlch() {
787 return getValue() / 2;
795 public int getLowAlch() {
796 return getValue() / 5;
800 public EquipmentType getEquipmentType() {
804 public int[] getRequirements() {
808 public int[] getBonuses() {
817 public boolean isEquipable() {
821 public boolean isTwoHanded() {
830 public boolean isWeapon() {
839 public double getWeight() {
843 public int getStandAnimation() {
847 public int getWalkAnimation() {
851 public int getRunAnimation() {
857 return OptionalInt.empty();
863 public OptionalInt getBlockAnimation() {
867 public Optional<RangedWeaponDefinition> getRangedDefinition() {
871 public WeaponInterface getWeaponInterface() {
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"));
899 public void setStackable(
boolean stackable) {
903 public void setTwoHanded(
boolean twoHanded) {
907 public void setTradeable(
boolean tradeable) {
911 public int getStand_animation() {
919 public int getAttack_anim() {
927 public int getWalk_animation() {
935 public int getRun_animation() {
943 public Map<FightType, Integer> getAttack_animations() {
951 public int getBlock_animation() {
959 public void setUnnotedId(
int unnotedId) {
963 public void setNotedId(
int notedId) {
967 public int getStreet_value() {
975 public int getBase_value() {
983 public void setHighAlch(
int highAlch) {
987 public void setLowAlch(
int lowAlch) {
991 public void setWeight(
double weight) {
1007 public void setBonuses(
int[]
bonuses) {
The class that contains setting-related constants for the server.
static final int ITEM_DEFINITION_LIMIT
The limit of the item identification.
static final int PLAYER_RUN
static final int PLAYER_STAND
static final int PLAYER_WALK
boolean isNoted()
Gets the item note state.
static void dump(String path)
static void dump(ItemDefinition[] definitions, String path)
static ItemDefinition[] create(String path)
Map< FightType, Integer > attack_animations
int getId()
Gets the item id.
static final ItemDefinition DEFAULT
ItemDefinition(int id, String name)
String getDestroyMessage()
Gets the item destroy message.
static ItemDefinition[] fromClientDump(String path)
static GsonParser createParser()
String getName()
Gets the item name.
WeaponInterface weaponInterface
EquipmentType equipmentType
static final Map< FightType, Integer > EMPTY
static void merge(String clientDumpFilePath, String wikiDumpPath, String dumpPath)
RangedWeaponDefinition rangedDefinition
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)