1package com.runehive.util.tools.wiki.impl;
3import com.google.gson.JsonArray;
4import com.google.gson.JsonElement;
5import com.google.gson.JsonObject;
6import com.runehive.game.world.items.ItemDefinition;
7import com.runehive.game.world.items.containers.equipment.Equipment;
8import com.runehive.util.tools.wiki.parser.WikiTable;
9import com.runehive.util.tools.wiki.parser.WikiTableParser;
10import org.jsoup.nodes.Document;
11import org.jsoup.nodes.Element;
12import org.jsoup.select.Elements;
20 "http://oldschoolrunescape.wikia.com/wiki/Ammunition_slot_table",
21 "http://oldschoolrunescape.wikia.com/wiki/Body_slot_table",
22 "http://oldschoolrunescape.wikia.com/wiki/Cape_slot_table",
23 "http://oldschoolrunescape.wikia.com/wiki/Feet_slot_table",
24 "http://oldschoolrunescape.wikia.com/wiki/Hand_slot_table",
25 "http://oldschoolrunescape.wikia.com/wiki/Head_slot_table",
26 "http://oldschoolrunescape.wikia.com/wiki/Legwear_slot_table",
27 "http://oldschoolrunescape.wikia.com/wiki/Neck_slot_table",
28 "http://oldschoolrunescape.wikia.com/wiki/Ring_slot_table",
29 "http://oldschoolrunescape.wikia.com/wiki/Shield_slot_table",
30 "http://oldschoolrunescape.wikia.com/wiki/Two-handed_slot_table",
31 "http://oldschoolrunescape.wikia.com/wiki/Weapons_table"
39 LinkedList<WikiTable>
tables =
new LinkedList<>();
44 public void parseDocument(Document document) {
45 for (Element wikiTable : document.select(
".wikitable")) {
46 for (Element children : wikiTable.children()) {
47 Iterator<Element> iterator = children.children().iterator();
49 while (iterator.hasNext()) {
50 Element child = iterator.next();
51 Elements bonuses = child.children();
52 String name = bonuses.remove(0).text();
54 JsonObject
object =
new JsonObject();
55 object.addProperty(
"name", name);
59 for (Element data : bonuses) {
61 if (data.text().isEmpty()) {
66 if (data.text().contains(
"trimmed"))
69 if (idx >= bonusArray.length)
72 if ((link.contains(
"Neck") || link.contains(
"Body") || link.contains(
"Leg") || link.contains(
"Feet") || link.contains(
"Head") || link.contains(
"Cape") || link.contains(
"Ammu") || link.contains(
"Hand")) && idx ==
Equipment.
RANGED_STRENGTH) {
75 bonusArray[idx++] = Integer.parseInt(data.text());
78 object.add(
"bonuses",
GSON.toJsonTree(bonusArray));
80 }
catch (Exception e) {
81 System.err.println(
"Failed to parse " + name +
" --- " + e.toString());
95 Map<String, Integer[]> bonusMap =
new HashMap<>(
tables.size());
96 JsonArray array =
new JsonArray();
99 JsonArray tableData = table.getTable();
100 array.addAll(tableData);
102 for (JsonElement data : tableData) {
103 JsonObject next = (JsonObject) data;
104 String name = next.get(
"name").getAsString();
105 Integer[] bonuses =
GSON.fromJson(next.get(
"bonuses"), Integer[].class);
106 if (bonusMap.containsKey(name)) {
107 System.err.println(
"Conflicting item: " + name);
108 System.err.println(Arrays.toString(bonuses));
109 System.err.println(Arrays.toString(bonusMap.get(name)));
110 System.err.println();
112 bonusMap.put(name, bonuses);
121 if (definition ==
null)
continue;
122 Integer[] bonuses = bonusMap.get(definition.
getName());
123 if (bonuses !=
null) {
124 Arrays.setAll(definition.getBonuses(), index -> bonuses[index]);
126 Arrays.setAll(definition.getBonuses(), index -> 0);
132 public static void main(String[] args)
throws InterruptedException {
Represents all of an in-game Item's attributes.
static void dump(ItemDefinition[] definitions, String path)
static GsonParser createParser()
String getName()
Gets the item name.
static ItemDefinition[] DEFINITIONS
An array of item definitions.
The container that manages the equipment for a player.
static final int PRAYER_BONUS
static final int SIZE
The size of all equipment instances.
static final int RANGED_STRENGTH