Advertisement
Guest User

Untitled

a guest
Jan 24th, 2020
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 13.47 KB | None | 0 0
  1. package com.rs.tools;
  2.  
  3. import java.io.File;
  4. import java.io.IOException;
  5. import java.net.SocketTimeoutException;
  6. import java.util.ArrayList;
  7. import java.util.Comparator;
  8. import java.util.HashMap;
  9. import java.util.List;
  10. import java.util.Map;
  11.  
  12. import com.rs.cache.Cache;
  13. import com.rs.cache.loaders.ItemDefinitions;
  14. import com.rs.tools.old.WebPage;
  15. import com.rs.utils.Utils;
  16. import com.rs.utils.drop.DropSet;
  17. import com.rs.utils.drop.DropTable;
  18. import com.rs.utils.json.JsonFileManager;
  19.  
  20. public class NPCDropDumper {
  21.  
  22. // private static Set<String> DUMPED = new HashSet<>();
  23.  
  24. public static void main(String[] args) {
  25. try {
  26. Cache.init();
  27. dumpNPC("Cave horror");
  28. // for (int npcId = 0;npcId < Utils.getNPCDefinitionsSize();npcId++) {
  29. // NPCDefinitions defs = NPCDefinitions.getDefs(npcId);
  30. // if (!DUMPED.contains(defs.getName()) && defs.hasAttackOption()) {
  31. // DUMPED.add(defs.getName());
  32. // if (dumpNPC(defs.getName().replace(" ", " ")))
  33. // System.out.println("Successfully dumped " + defs.getName());
  34. //// else
  35. //// System.out.println("Failed to dump " + defs.getName());
  36. // }
  37. // }
  38. } catch (IOException e) {
  39. e.printStackTrace();
  40. }
  41. }
  42.  
  43. private static Map<String, Integer> CUSTOM_NAME_MAP = new HashMap<>();
  44.  
  45. static {
  46. CUSTOM_NAME_MAP.put("Coins", 995);
  47. CUSTOM_NAME_MAP.put("Tinderbox", 590);
  48. CUSTOM_NAME_MAP.put("Mystic hat (dark)", 4099);
  49. CUSTOM_NAME_MAP.put("Blue wizard robe", 577);
  50. CUSTOM_NAME_MAP.put("Blue wizard hat", 579);
  51. CUSTOM_NAME_MAP.put("Mystic robe top (dark)", 4101);
  52. CUSTOM_NAME_MAP.put("Mystic robe bottom (dark)", 4103);
  53. CUSTOM_NAME_MAP.put("Mystic gloves (dark)", 4105);
  54. CUSTOM_NAME_MAP.put("Mystic boots (dark)", 4107);
  55. CUSTOM_NAME_MAP.put("Mystic hat (light)", 4109);
  56. CUSTOM_NAME_MAP.put("Mystic robe top (light)", 4111);
  57. CUSTOM_NAME_MAP.put("Mystic robe bottom (light)", 4113);
  58. CUSTOM_NAME_MAP.put("Mystic gloves (light)", 4115);
  59. CUSTOM_NAME_MAP.put("Mystic boots (light)", 4117);
  60. CUSTOM_NAME_MAP.put("Adamantite bar", 2361);
  61. CUSTOM_NAME_MAP.put("Runite bar", 2363);
  62.  
  63. CUSTOM_NAME_MAP.put("Grimy ranarr weed", 207);
  64. CUSTOM_NAME_MAP.put("Seers ring", 6731);
  65. CUSTOM_NAME_MAP.put("Archers ring", 6733);
  66.  
  67. CUSTOM_NAME_MAP.put("Black cape", 1019);
  68. CUSTOM_NAME_MAP.put("Black robe", 581);
  69. CUSTOM_NAME_MAP.put("Zamorak monk bottom", 1033);
  70. CUSTOM_NAME_MAP.put("Zamorak monk top", 1035);
  71. CUSTOM_NAME_MAP.put("Pot", 1931);
  72. CUSTOM_NAME_MAP.put("Raw beef (undead)", 4287);
  73. CUSTOM_NAME_MAP.put("Raw chicken (undead)", 4289);
  74. CUSTOM_NAME_MAP.put("Right eye patch", 1025);
  75. CUSTOM_NAME_MAP.put("Gold amulet (u)", 1673);
  76. CUSTOM_NAME_MAP.put("Sapphire amulet (u)", 1675);
  77. CUSTOM_NAME_MAP.put("Emerald amulet (u)", 1677);
  78. CUSTOM_NAME_MAP.put("Ruby amulet (u)", 1679);
  79. CUSTOM_NAME_MAP.put("Diamond amulet (u)", 1681);
  80.  
  81. CUSTOM_NAME_MAP.put("Gold amulet", 1692);
  82. CUSTOM_NAME_MAP.put("Sapphire amulet", 1694);
  83. CUSTOM_NAME_MAP.put("Emerald amulet", 1696);
  84. CUSTOM_NAME_MAP.put("Ruby amulet", 1698);
  85. CUSTOM_NAME_MAP.put("Diamond amulet", 1700);
  86. CUSTOM_NAME_MAP.put("Dragon chainbody", 3140);
  87. CUSTOM_NAME_MAP.put("Purple gloves", 2942);
  88. CUSTOM_NAME_MAP.put("Yellow gloves", 2922);
  89. CUSTOM_NAME_MAP.put("Red gloves", 2912);
  90. CUSTOM_NAME_MAP.put("Teal gloves", 2932);
  91. CUSTOM_NAME_MAP.put("Grain", 1947);
  92. CUSTOM_NAME_MAP.put("Red cape", 1007);
  93. CUSTOM_NAME_MAP.put("Blue cape", 1021);
  94. CUSTOM_NAME_MAP.put("", 00000);
  95. CUSTOM_NAME_MAP.put("", 00000);
  96. CUSTOM_NAME_MAP.put("", 00000);
  97. CUSTOM_NAME_MAP.put("", 00000);
  98. CUSTOM_NAME_MAP.put("", 00000);
  99. CUSTOM_NAME_MAP.put("", 00000);
  100. CUSTOM_NAME_MAP.put("", 00000);
  101. CUSTOM_NAME_MAP.put("", 00000);
  102. CUSTOM_NAME_MAP.put("", 00000);
  103. CUSTOM_NAME_MAP.put("", 00000);
  104. CUSTOM_NAME_MAP.put("", 00000);
  105.  
  106. CUSTOM_NAME_MAP.put("Dragon pickaxe", -2);
  107. CUSTOM_NAME_MAP.put("Dragon arrowtips", -2);
  108. CUSTOM_NAME_MAP.put("Dragon javelin heads", -2);
  109. CUSTOM_NAME_MAP.put("Dark fishing bait", -2);
  110. CUSTOM_NAME_MAP.put("Smouldering stone", -2);
  111. CUSTOM_NAME_MAP.put("Giant key", -2);
  112. CUSTOM_NAME_MAP.put("Looting bag", -2);
  113. CUSTOM_NAME_MAP.put("Ancient shard", -2);
  114. CUSTOM_NAME_MAP.put("Brimstone key", -2);
  115. CUSTOM_NAME_MAP.put("Dark totem base", -2);
  116. CUSTOM_NAME_MAP.put("Dark totem middle", -2);
  117. CUSTOM_NAME_MAP.put("Dark totem top", -2);
  118. CUSTOM_NAME_MAP.put("", -2);
  119. CUSTOM_NAME_MAP.put("", -2);
  120. CUSTOM_NAME_MAP.put("", -2);
  121. CUSTOM_NAME_MAP.put("", -2);
  122. CUSTOM_NAME_MAP.put("", -2);
  123. CUSTOM_NAME_MAP.put("", -2);
  124. CUSTOM_NAME_MAP.put("", -2);
  125. CUSTOM_NAME_MAP.put("", -2);
  126. CUSTOM_NAME_MAP.put("", -2);
  127. }
  128.  
  129. public static boolean dumpNPC(String pageName) {
  130. try {
  131. WebPage page = new WebPage("https://oldschool.runescape.wiki/w/"+pageName+"?action=raw");
  132. try {
  133. page.load();
  134. } catch (SocketTimeoutException e) {
  135. return dumpNPC(pageName);
  136. } catch (Exception e) {
  137. return false;
  138. }
  139. boolean accurate = false;
  140. String lastDesc = "";
  141. String subName = "";
  142. for (String line : page.getLines()) {
  143. if (line.contains("DropLogProject"))
  144. accurate = true;
  145. }
  146. if (!accurate)
  147. return false;
  148. boolean skipping = false;
  149. int tableNum = 1;
  150. ArrayList<DropTable> drops = new ArrayList<DropTable>();
  151. for (String line : page.getLines()) {
  152. line = line.replace("{", "").replace("}", "");
  153. if (line.contains("=="))
  154. lastDesc = line.toLowerCase().replace("=", "").replace(" ", "_").replace("drops ", "");
  155. if (line.contains("DropLogProject|jagex=yes")) {
  156. if (drops.isEmpty())
  157. subName = lastDesc;
  158. else
  159. finalizeDrops(pageName, subName.isEmpty() ? (pageName+"_sub"+tableNum) : (pageName+"_"+subName), drops);
  160. subName = lastDesc;
  161.  
  162. }
  163. if (line.contains("Deadman mode") || line.contains("Pickpocketing"))
  164. skipping = true;
  165. if (line.contains("DropsTableBottom"))
  166. skipping = false;
  167. if (skipping)
  168. continue;
  169. int itemId = -1;
  170. int min = -1;
  171. int max = -1;
  172. double num = -1;
  173. double den = -1;
  174. String name = "";
  175. if (line.contains("RareDropTable/Sandbox|")) {
  176. String[] rdt = line.split("\\|");
  177. if (rdt[1].toLowerCase().contains("/")) {
  178. String[] frac = rdt[1].replace("~", "").replace(" ", "").split("/");
  179. num = Double.valueOf(frac[0].trim());
  180. den = Double.valueOf(frac[1].trim());
  181. }
  182. if (num != -1 && den != -1)
  183. drops.add(new DropTable(num, den, "rdt_standard"));
  184. else
  185. System.out.println("Failed parsing drop: RareDropTable/Sandbox: " + itemId + ", " + min + ", " + max + ", " + num + "/" + den);
  186. if (rdt[2].toLowerCase().contains("/")) {
  187. String[] frac = rdt[2].replace("~", "").replace(" ", "").split("/");
  188. num = Double.valueOf(frac[0].trim());
  189. den = Double.valueOf(frac[1].trim());
  190. }
  191. if (num != -1 && den != -1)
  192. drops.add(new DropTable(num, den, "rdt_gem"));
  193. else
  194. System.out.println("Failed parsing drop: " + name + ", " + itemId + ", " + min + ", " + max + ", " + num + "/" + den);
  195. } else if (line.equals("GWDRDT") || line.contains("VariableAllotmentSeedDropTable|") || line.contains("FixedAllotmentSeedDropTable|") || line.contains("HerbDropTable|") || line.contains("GemDropTable|") || line.contains("ManySeedDropTable|") || line.contains("RareSeedDropTable|")) {
  196. addDropTable(line, drops);
  197. } else if (line.contains("Ensouled") || line.contains("Curved bone") || line.contains("Long bone") || line.contains("Rag and Bone") || line.contains("Clue scroll") || line.contains("Only dropped") || line.contains("f2p=yes") || line.contains("name=\"f2")) {
  198. continue;
  199. } else if (line.contains("DropsLine|") && (line.contains("/") || line.toLowerCase().contains("always"))) {
  200. String[] memes = line.split("\\|");
  201. for (int k = 0;k < memes.length;k++) {
  202. String[] key = memes[k].split("=");
  203. if (key[0].equals("Name")) {
  204. name = key[1].replace("(", " (").replace(" (", " (");
  205. name = name.replace(" axe", " hatchet");
  206. name = name.replace("med helm", "helm");
  207. name = name.replace("dueling", "duelling");
  208. name = name.replace(" leaf", "");
  209. name = name.replace("d'hide vamb", "d'hide vambraces");
  210. name = name.replace("crossbow (u)", "c'bow (u)");
  211. if (name.contains("mix ("))
  212. name = name.replace("str.", "strength").replace("Superattack", "Super attack").replace("def.", "defence");
  213. for (int i = 0;i < Utils.getItemDefinitionsSize();i++) {
  214. if (ItemDefinitions.getDefs(i).getName().equalsIgnoreCase(name)) {
  215. itemId = i;
  216. break;
  217. }
  218. }
  219. if (CUSTOM_NAME_MAP.get(name) != null) {
  220. itemId = CUSTOM_NAME_MAP.get(name);
  221. }
  222. } else if (key[0].equals("Quantity")) {
  223. if (key[1].toLowerCase().contains("(noted)")) {
  224. key[1] = key[1].toLowerCase().replace(" (noted)", "").replace("(noted)", "");
  225. itemId = ItemDefinitions.getDefs(itemId).getCertId();
  226. }
  227. if (key[1].contains(",")) {
  228. key[1] = key[1].replace(" ", "");
  229. String[] minMax = key[1].split(",");
  230. min = Integer.valueOf(minMax[0].trim());
  231. max = Integer.valueOf(minMax[1].trim());
  232. } else if (key[1].contains("-")) {
  233. String[] minMax = key[1].split("-");
  234. min = Integer.valueOf(minMax[0].trim());
  235. max = Integer.valueOf(minMax[1].trim());
  236. } else {
  237. min = Integer.valueOf(key[1].replace(" ", "").trim());
  238. max = min;
  239. }
  240. } else if (key[0].equals("Rarity")) {
  241. if (key[1].toLowerCase().contains("always")) {
  242. num = 0;
  243. den = 0;
  244. }
  245. if (key[1].toLowerCase().contains("/")) {
  246. String[] frac = key[1].replace("~", "").replace(" ", "").split("/");
  247. num = Double.valueOf(frac[0].trim());
  248. den = Double.valueOf(frac[1].trim());
  249. }
  250. } else if (key[0].equals("AltRarity")) {
  251. if (key[1].toLowerCase().contains("always")) {
  252. num = 0;
  253. den = 0;
  254. }
  255. if (key[1].toLowerCase().contains("/")) {
  256. String[] frac = key[1].replace("~", "").replace(" ", "").split("/");
  257. num = Double.valueOf(frac[0].trim());
  258. den = Double.valueOf(frac[1].trim());
  259. }
  260. }
  261. }
  262. if (itemId >= 0 && min != -1 && max != -1 && num != -1 && den != -1) {
  263. drops.add(new DropTable(num, den, itemId, min, max));
  264. } else {
  265. if (itemId == -1) {
  266. System.out.println(pageName + " Error -> Unknown item: " + name);
  267. }
  268. if (min == -1 || max == -1) {
  269. System.out.println(pageName + " Error -> Failed to parse min/max of "+name+": " + min + ", " + max);
  270. }
  271. if (num == -1 || den == -1) {
  272. System.out.println(pageName + " Error -> Failed to parse rate of "+name+": " + num + ", " + den);
  273. }
  274. }
  275. }
  276. }
  277. finalizeDrops(pageName, subName.isEmpty() ? pageName : (pageName + "_" + subName), drops);
  278. return true;
  279. } catch (Exception e) {
  280. e.printStackTrace();
  281. }
  282. return false;
  283. }
  284.  
  285. private static void addDropTable(String line, List<DropTable> drops) {
  286. String[] memes = line.split("\\|");
  287. double num = -1, den = -1;
  288. String tableName = "";
  289.  
  290. if (line.contains("ManySeedDropTable|"))
  291. tableName = "common_seeds";
  292. else if (line.contains("FixedAllotmentSeedDropTable|"))
  293. tableName = "fixed_allotment";
  294. else if (line.contains("RareSeedDropTable|"))
  295. tableName = "rare_seeds";
  296. else if (line.contains("VariableAllotmentSeedDropTable|"))
  297. tableName = "variable_allotment";
  298. else if (line.contains("HerbDropTable|"))
  299. tableName = "herb";
  300. else if (line.contains("GemDropTable|"))
  301. tableName = "rdt_gem";
  302. else if (line.contains("GWDRDT")) {
  303. drops.add(new DropTable(8, 127, "rdt_standard_gwd"));
  304. drops.add(new DropTable(2, 127, "rdt_gem_gwd"));
  305. return;
  306. }
  307.  
  308. if (memes[1].toLowerCase().contains("/")) {
  309. String[] frac = memes[1].replace("~", "").replace(" ", "").split("/");
  310. num = Double.valueOf(frac[0].trim());
  311. den = Double.valueOf(frac[1].trim());
  312. }
  313. if (num != -1 && den != -1 && !tableName.isEmpty())
  314. drops.add(new DropTable(num, den, tableName));
  315. else
  316. System.out.println("Failed parsing drop: table:" + tableName + ", " + num + "/" + den);
  317. }
  318.  
  319. public static void finalizeDrops(String pageName, String name, List<DropTable> drops) {
  320. System.out.println("Finalizing drop: " + name + " " + drops.size());
  321. drops.sort(new Comparator<DropTable>() {
  322. @Override
  323. public int compare(DropTable o1, DropTable o2) {
  324. return Double.compare(o2.getRate() == 0.0 ? 100.0 : o2.getRate(), o1.getRate() == 0.0 ? 100.0 : o1.getRate());
  325. }
  326. });
  327.  
  328. try {
  329. DropTable[] dropArr = new DropTable[drops.size()];
  330. for (int i = 0;i < drops.size();i++)
  331. dropArr[i] = drops.get(i);
  332. DropSet table = new DropSet(null, new String[] { pageName.replace("_", " ") }, dropArr);
  333. table.createDropList();
  334. if (table.getDropList() == null) {
  335. System.out.println("Empty drop list for " + name);
  336. return;
  337. }
  338. if (table.isOverflowed())
  339. System.out.println("Overflowed: " + name.toLowerCase());
  340. if (name.toLowerCase().contains("revenant") || name.toLowerCase().contains("kourend"))
  341. return;
  342. JsonFileManager.saveJsonFile(table, new File("./dumps/"+(table.isOverflowed() ? "overflowed" : "success")+"/"+name.toLowerCase().replace(" ", "_").replace("_drops", "")+".json"));
  343. } catch (Exception e) {
  344. e.printStackTrace();
  345. }
  346. drops.clear();
  347. }
  348. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement