1package com.runehive.util.tools.wiki.impl;
3import com.google.common.collect.LinkedListMultimap;
4import com.google.gson.JsonArray;
5import com.google.gson.JsonObject;
6import com.runehive.game.world.entity.mob.npc.definition.NpcDefinition;
7import com.runehive.game.world.entity.mob.npc.drop.NpcDropManager;
8import com.runehive.game.world.items.ItemDefinition;
9import com.runehive.util.parser.impl.NpcDropParser;
10import com.runehive.util.tools.wiki.parser.WikiTable;
11import com.runehive.util.tools.wiki.parser.WikiTableParser;
12import org.jsoup.nodes.Document;
13import org.jsoup.nodes.Element;
14import org.jsoup.select.Elements;
20 private static final Map<String, ItemDefinition>
itemByName =
new HashMap<>();
36 LinkedListMultimap<String, NpcDefinition> byName = LinkedListMultimap.create();
41 if (definition ==
null || definition.
getName() ==
null || definition.
getName().equals(
"null")) {
45 if (!definition.isAttackable()) {
53 byName.put(definition.
getName(), definition);
56 LinkedList<WikiTable>
tables =
new LinkedList<>();
59 for (Map.Entry<String, Collection<NpcDefinition>> entry : byName.asMap().entrySet()) {
60 String name = entry.getKey();
61 name = name.replaceAll(
" ",
"_");
62 int idx = name.indexOf(
"(");
64 name = name.substring(0, idx);
72 JsonArray array =
new JsonArray();
74 array.addAll(table.getTable());
79 public static void main(String[] args)
throws InterruptedException {
94 Elements dropTable = document.select(
".wikitable.sortable.dropstable");
95 Elements td = dropTable.select(
"td");
96 Iterator<Element> iterator = td.iterator();
98 List<DropItem> drops =
new LinkedList<>();
99 boolean rareDropTable =
false;
101 while (iterator.hasNext()) {
103 String name = iterator.next().text();
104 String amount = iterator.next().text().replaceAll(
",",
"");
105 String rarity = iterator.next().text().toLowerCase();
109 log(
"missing item: " + name);
110 if (name.contains(
"Rare drop table")) {
111 rareDropTable =
true;
116 if (amount.contains(
"Unknown")) {
117 log(
"unknown drop amount: " + name);
124 int notedIndex = amount.indexOf(
"(noted)");
125 if (notedIndex > -1) {
126 amount = amount.substring(0, notedIndex - 1).trim();
133 if (rarity.startsWith(
"very rare")) {
135 }
else if (rarity.startsWith(
"rare")) {
137 }
else if (rarity.startsWith(
"uncommon")) {
139 }
else if (rarity.startsWith(
"common")) {
141 }
else if (rarity.startsWith(
"always")) {
144 log(
"unknown drop rarity: " + rarity);
148 if (amount.contains(
";")) {
149 String[] amounts = amount.split(
"; ");
150 for (String s : amounts) {
151 int hyphen = s.indexOf(
"–");
153 min = Integer.valueOf(s.substring(0, hyphen));
154 max = Integer.valueOf(s.substring(hyphen + 1));
156 min = max = Integer.valueOf(s);
158 drops.add(
new DropItem(
id, min, max, rate));
161 int hyphen = amount.indexOf(
"–");
163 min = Integer.valueOf(amount.substring(0, hyphen));
164 max = Integer.valueOf(amount.substring(hyphen + 1));
166 min = max = Integer.valueOf(amount);
168 drops.add(
new DropItem(
id, min, max, rate));
170 }
catch (Exception e) {
175 if (drops.isEmpty()) {
179 JsonObject
object =
new JsonObject();
180 JsonArray array =
new JsonArray();
183 array.add(definition.getId());
186 drops.sort(Comparator.comparing(drop -> drop.rarity));
188 object.add(
"ids", array);
189 object.addProperty(
"rare_table", rareDropTable);
195 JsonArray items =
new JsonArray();
198 JsonObject dropItem =
new JsonObject();
200 dropItem.addProperty(
"id", item.id);
201 dropItem.addProperty(
"minimum", item.min);
202 dropItem.addProperty(
"maximum", item.max);
203 dropItem.addProperty(
"type", item.rarity.name());
210 private void log(String message) {
212 System.out.println(
"[name=" + name +
"] -- " + message);
218 private final int id;
237 if (obj ==
this)
return true;
240 return other.id ==
id && other.min ==
min && other.max ==
max && other.
rarity.equals(
rarity);
Contains the npc definitions.
static final NpcDefinition[] DEFINITIONS
The array of npc definitions.
static GsonParser createParser()
The manager class which holds the static entries of drop tables and has a method to execute a drop ta...
static final Map< Integer, NpcDropTable > NPC_DROPS
The collection of npc ids by their representative drop tables.
Represents all of an in-game Item's attributes.
int getId()
Gets the item id.
static GsonParser createParser()
String getName()
Gets the item name.
static ItemDefinition[] DEFINITIONS
An array of item definitions.
Loads npc drops on startup.