48 private static final String[] TABLE_LINKS = {
49 "http://oldschoolrunescape.wikia.com/wiki/Ammunition_slot_table",
50 "http://oldschoolrunescape.wikia.com/wiki/Body_slot_table",
51 "http://oldschoolrunescape.wikia.com/wiki/Cape_slot_table",
52 "http://oldschoolrunescape.wikia.com/wiki/Feet_slot_table",
53 "http://oldschoolrunescape.wikia.com/wiki/Hand_slot_table",
54 "http://oldschoolrunescape.wikia.com/wiki/Head_slot_table",
55 "http://oldschoolrunescape.wikia.com/wiki/Legwear_slot_table",
56 "http://oldschoolrunescape.wikia.com/wiki/Neck_slot_table",
57 "http://oldschoolrunescape.wikia.com/wiki/Ring_slot_table",
58 "http://oldschoolrunescape.wikia.com/wiki/Shield_slot_table",
59 "http://oldschoolrunescape.wikia.com/wiki/Two-handed_slot_table",
60 "http://oldschoolrunescape.wikia.com/wiki/Weapons_table"
63 private BonusParser() {
64 super(generateTables());
67 private static LinkedList<WikiTable> generateTables() {
68 LinkedList<WikiTable>
tables =
new LinkedList<>();
70 for (String link : TABLE_LINKS) {
73 public void parseDocument(Document document) {
74 for (Element wikiTable : document.select(
".wikitable")) {
75 for (Element children : wikiTable.children()) {
76 Iterator<Element> iterator = children.children().iterator();
78 while (iterator.hasNext()) {
79 Element child = iterator.next();
80 Elements bonuses = child.children();
81 String name = bonuses.remove(0).text();
83 JsonObject
object =
new JsonObject();
84 object.addProperty(
"name", name);
88 for (Element data : bonuses) {
90 if (data.text().isEmpty()) {
95 if (data.text().contains(
"trimmed"))
98 if (idx >= bonusArray.length)
101 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) {
102 bonusArray[
Equipment.PRAYER_BONUS] = Integer.parseInt(data.text());
104 bonusArray[idx++] = Integer.parseInt(data.text());
107 object.add(
"bonuses",
GSON.toJsonTree(bonusArray));
109 }
catch (Exception e) {
110 System.err.println(
"Failed to parse " + name +
" --- " + e.toString());
123 protected void finish() {
124 Map<String, Integer[]> bonusMap =
new HashMap<>(
tables.size());
125 JsonArray array =
new JsonArray();
128 JsonArray tableData = table.getTable();
129 array.addAll(tableData);
131 for (JsonElement data : tableData) {
132 JsonObject next = (JsonObject) data;
133 String name = next.get(
"name").getAsString();
134 Integer[] bonuses =
GSON.fromJson(next.get(
"bonuses"), Integer[].class);
135 if (bonusMap.containsKey(name)) {
136 System.err.println(
"Conflicting item: " + name);
137 System.err.println(Arrays.toString(bonuses));
138 System.err.println(Arrays.toString(bonusMap.get(name)));
139 System.err.println();
141 bonusMap.put(name, bonuses);
150 if (definition ==
null)
continue;
151 Integer[] bonuses = bonusMap.get(definition.
getName());
152 if (bonuses !=
null) {
153 Arrays.setAll(definition.getBonuses(), index -> bonuses[index]);
155 Arrays.setAll(definition.getBonuses(), index -> 0);
161 public static void main(String[] args)
throws InterruptedException {
162 BonusParser parser =
new BonusParser();