Advertisement
Guest User

Untitled

a guest
Oct 15th, 2019
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 25.84 KB | None | 0 0
  1. package ethos.model.npcs.drops;
  2.  
  3. import ethos.Server;
  4. import ethos.model.content.godwars.Godwars;
  5. import ethos.model.items.GameItem;
  6. import ethos.model.items.Item;
  7. import ethos.model.items.ItemAssistant;
  8. import ethos.model.npcs.NPC;
  9. import ethos.model.npcs.NPCDefinitions;
  10. import ethos.model.npcs.NPCHandler;
  11. import ethos.model.players.Boundary;
  12. import ethos.model.players.Player;
  13. import ethos.model.players.PlayerHandler;
  14. import ethos.model.players.Right;
  15. import ethos.model.players.skills.slayer.SlayerMaster;
  16. import ethos.model.players.skills.slayer.Task;
  17. import ethos.util.Location3D;
  18. import ethos.util.Misc;
  19. import org.apache.commons.lang3.ArrayUtils;
  20. import org.apache.commons.lang3.StringUtils;
  21. import org.json.simple.JSONArray;
  22. import org.json.simple.JSONObject;
  23. import org.json.simple.parser.JSONParser;
  24. import org.json.simple.parser.ParseException;
  25.  
  26. import java.io.FileReader;
  27. import java.io.IOException;
  28. import java.util.*;
  29. import java.util.concurrent.TimeUnit;
  30. import java.util.stream.Collectors;
  31. import java.util.stream.IntStream;
  32.  
  33. public class DropManager {
  34.  
  35.  
  36. public static int AMOUNT_OF_TABLES = 0;
  37.  
  38. private static final Comparator<Integer> COMPARE_NAMES =(o1, o2) -> {
  39. String name1 = NPCDefinitions.get(o1).getNpcName();
  40. String name2 = NPCDefinitions.get(o2).getNpcName();
  41. return name1.compareToIgnoreCase(name2);
  42. };
  43.  
  44. private Map<List<Integer>, TableGroup> groups = new HashMap<>();
  45.  
  46. private List<Integer> ordered = new ArrayList<>();
  47.  
  48. @SuppressWarnings("unchecked")
  49. public void read() {
  50. JSONParser parser = new JSONParser();
  51. try {
  52. fileReader = new FileReader("./Data/json/npc_droptable.json");
  53. JSONArray data = (JSONArray) parser.parse(fileReader);
  54. for (Object aData : data) {
  55. JSONObject drop=(JSONObject) aData;
  56. List<Integer> npcIds=new ArrayList<>();
  57. if (drop.get("npc_id") instanceof JSONArray) {
  58. JSONArray idArray=(JSONArray) drop.get("npc_id");
  59. idArray.forEach(id -> npcIds.add(((Long) id).intValue()));
  60. } else {
  61. npcIds.add(((Long) drop.get("npc_id")).intValue());
  62. }
  63. TableGroup group=new TableGroup(npcIds);
  64. for (TablePolicy policy : TablePolicy.POLICIES) {
  65. if (!drop.containsKey(policy.name().toLowerCase())) {
  66. continue;
  67. }
  68. JSONObject dropTable=(JSONObject) drop.get(policy.name().toLowerCase());
  69. Table table=new Table(policy, ((Long) dropTable.get("accessibility")).intValue());
  70. JSONArray tableItems=(JSONArray) dropTable.get("items");
  71. for (Object tableItem : tableItems) {
  72. JSONObject item=(JSONObject) tableItem;
  73. int id=((Long) item.get("item")).intValue();
  74. int minimumAmount=((Long) item.get("minimum")).intValue();
  75. int maximumAmount=((Long) item.get("maximum")).intValue();
  76. table.add(new Drop(npcIds, id, minimumAmount, maximumAmount));
  77. }
  78. group.add(table);
  79. }
  80. groups.put(npcIds, group);
  81. }
  82. ordered.clear();
  83.  
  84. for (TableGroup group : groups.values()) {
  85. if (group.getNpcIds().size() == 1) {
  86. ordered.add(group.getNpcIds().get(0));
  87. continue;
  88. }
  89. for (int id : group.getNpcIds()) {
  90. String name = NPCDefinitions.get(id).getNpcName();
  91. if (ordered.stream().noneMatch(i -> NPCDefinitions.get(i).getNpcName().equals(name))) {
  92. ordered.add(id);
  93. }
  94. }
  95. }
  96.  
  97. ordered.sort(COMPARE_NAMES);
  98. Misc.println("Loaded " + ordered.size() + " drop tables.");
  99. AMOUNT_OF_TABLES = ordered.size();
  100. } catch (IOException | ParseException e) {
  101. e.printStackTrace();
  102. }
  103. }
  104.  
  105. /**
  106. * Attempts to create a drop for a player after killing a non-playable character
  107. *
  108. * @param player the player receiving a possible drop
  109. * @param npc the npc dropping the items
  110. */
  111. static boolean test = false;
  112.  
  113. static int[] bosses = {
  114. /* Misc bosses */
  115. 6619, 6618, 6615, 6766, 963, 965, 5890, 6609, 319, 6610, 6611, 5779, 6342, 2205, 2215, 3129, 3162, 2054, 2265, 2266, 2267,
  116. 7544, 7604, 7605, 7606,
  117. /* Godwars minions */
  118. 2206, 2207, 2208, 3130, 3131, 3132, 2216, 2217, 2218, 3163, 3164, 3165,
  119. //gwd2 bosses
  120. 7000, 7001, 7002, 7003, 7011, 7012, 7014, 7010, 777, 785
  121. };
  122.  
  123. public void testOpen(Player player) {
  124. for(int i = 0; i < 100; i++) {
  125. player.getPA().sendFrame126("", (33008 + i));
  126. }
  127. for (int index = 0; index < ordered.size(); index++) {
  128. player.getPA().sendFrame126(StringUtils.capitalize(NPCDefinitions.get(ordered.get(index)).getNpcName().toLowerCase().replaceAll("_", " ")), 33008 + index);
  129. }
  130.  
  131. player.getPA().showInterface(33000);
  132. }
  133.  
  134. public void create(Player player, NPC npc, Location3D location, int repeats) {
  135. Optional<TableGroup> group = groups.values().stream().filter(g -> g.getNpcIds().contains(npc.npcType)).findFirst();
  136.  
  137. group.ifPresent(g -> {
  138. double modifier = getModifier(player);
  139. List<GameItem> drops = g.access(player, modifier, repeats);
  140. for (GameItem item : drops) {
  141. if (item.getId() == 536) {
  142. if (player.getRechargeItems().hasItem(13111) && player.inWild()) {
  143. item.changeDrop(537, item.getAmount());
  144. }
  145. }
  146. if (item.getId() == 6529) {
  147. if (player.getRechargeItems().hasItem(11136)) {
  148. item.changeDrop(6529, (int) (item.getAmount() * 1.20));
  149. }
  150. if (player.getRechargeItems().hasItem(11138)) {
  151. item.changeDrop(6529, (int) (item.getAmount() * 1.50));
  152. }
  153. if (player.getRechargeItems().hasItem(11140)) {
  154. item.changeDrop(6529, (int) (item.getAmount() * 1.70));
  155. }
  156. if (player.getRechargeItems().hasItem(13103)) {
  157. item.changeDrop(6529, (int) (item.getAmount() * 1.90));
  158. }
  159. }
  160. if (item.getId() == 6729 && player.getRechargeItems().hasItem(13132)) {
  161. item.changeDrop(6730, item.getAmount());
  162. }
  163. if (item.getId() == 13233 && !Boundary.isIn(player, Boundary.CERBERUS_BOSSROOMS)) {
  164. //player.sendMessage("@red@Something hot drops from the body of your vanquished foe");
  165. }
  166. if (!(player.playerEquipment[player.playerRing] == 773) || IntStream.of(bosses).anyMatch(id -> id == npc.npcType)) {
  167. PlayerHandler.nonNullStream()
  168. .filter(p -> p.distanceToPoint(player.absX, player.absY) < 10 && p.heightLevel == player.heightLevel)
  169. .forEach(p -> {
  170. if (item.getAmount() > 1)
  171. p.sendMessage("@red@" + Misc.formatPlayerName(player.playerName) + " received a drop: " + Misc.format(item.getAmount()) + " x " + Item.getItemName(item.getId()) + ".");
  172. else
  173. p.sendMessage("@red@" + Misc.formatPlayerName(player.playerName) + " received a drop: " + Item.getItemName(item.getId()) + ".");
  174. });
  175. }
  176. Server.itemHandler.createGroundItem(player, item.getId(), location.getX(), location.getY(),
  177. location.getZ(), item.getAmount(), player.getIndex());
  178. }
  179.  
  180. /**
  181. * Looting bag and rune pouch
  182. */
  183. if (npc.inWild()) {
  184. switch (Misc.random(60)) {
  185. case 2:
  186. if (player.getItems().getItemCount(11941, true) < 1) {
  187. Server.itemHandler.createGroundItem(player, 11941, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  188. }
  189. break;
  190.  
  191. case 8:
  192. if (player.getItems().getItemCount(12791, true) < 1) {
  193. Server.itemHandler.createGroundItem(player, 12791, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  194. }
  195. break;
  196. }
  197. }
  198. /**
  199. * Slayer's staff enchantment and Emblems
  200. */
  201. Optional<Task> task = player.getSlayer().getTask();
  202. Optional<SlayerMaster> myMaster = SlayerMaster.get(player.getSlayer().getMaster());
  203. task.ifPresent(t -> {
  204. String name = npc.getDefinition().getNpcName().toLowerCase().replaceAll("_", " ");
  205.  
  206. if (name.equals(t.getPrimaryName()) || ArrayUtils.contains(t.getNames(), name)) {
  207. myMaster.ifPresent(m -> {
  208. if (npc.inWild() && m.getId() == 7663) {
  209. int slayerChance = 650;
  210. int emblemChance = 100;
  211. if (Misc.random(emblemChance) == 1) {
  212. Server.itemHandler.createGroundItem(player, 12746, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  213. //player.sendMessage("@red@A mysterious emblem has dropped from your foe!");
  214. }
  215. if (Misc.random(slayerChance) == 1) {
  216. Server.itemHandler.createGroundItem(player, 21257, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  217. //player.sendMessage("@red@A slayer's enchantment has dropped from your foe!");
  218. //PlayerHandler.executeGlobalMessage(
  219. //"@red@" + Misc.capitalize(player.playerName) + " received a drop: Slayer's Enchantment.</col>.");
  220. //PlayerHandler.executeGlobalMessage("<col=FF0000>[Lootations] @cr19@ </col><col=255>"+ Misc.capitalize(player.playerName) + "</col> received a <col=255>Slayer's Enchantment</col>.");
  221. }
  222. }
  223. });
  224. }
  225. });
  226.  
  227. /**
  228. * Clue scrolls
  229. */
  230. int chance = player.getRechargeItems().hasItem(13118) ? 142 : player.getRechargeItems().hasItem(13119) ? 135 : player.getRechargeItems().hasItem(13120) ? 120 : 150;
  231. if (Misc.random(chance) == 1) {
  232. player.sendMessage("@pur@You sense a @red@clue scroll @pur@being dropped to the ground.");
  233. if (npc.getDefinition().getNpcCombat() > 0 && npc.getDefinition().getNpcCombat() <= 70) {
  234. Server.itemHandler.createGroundItem(player, 2677, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  235. }
  236. if (npc.getDefinition().getNpcCombat() > 70 && npc.getDefinition().getNpcCombat() <= 110) {
  237. Server.itemHandler.createGroundItem(player, 2801, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  238. }
  239. if (npc.getDefinition().getNpcCombat() > 110) {
  240. Server.itemHandler.createGroundItem(player, 2722, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  241. }
  242. }
  243.  
  244.  
  245. /**
  246. * Runecrafting pouches
  247. */
  248. if (Misc.random(100) == 10) {
  249. if (npc.getDefinition().getNpcCombat() >= 70 && npc.getDefinition().getNpcCombat() <= 100 && player.getItems().getItemCount(5509, true) == 1 && player.getItems().getItemCount(5510, true) != 1) {
  250. Server.itemHandler.createGroundItem(player, 5510, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  251. //player.sendMessage("@pur@You sense an upgraded Runecrafting Pouch!");
  252. } else if (npc.getDefinition().getNpcCombat() > 100 && player.getItems().getItemCount(5510, true) == 1 && player.getItems().getItemCount(5512, true) != 1) {
  253. Server.itemHandler.createGroundItem(player, 5512, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  254. //player.sendMessage("@pur@You sense an upgraded Runecrafting Pouch!");
  255. }
  256. }
  257.  
  258. /**
  259. * Crystal keys
  260. */
  261. if (Misc.random(115) == 1) {
  262. player.sendMessage("@pur@You sense a @red@crystal key @pur@being dropped to the ground.");
  263. Server.itemHandler.createGroundItem(player, 989, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  264. }
  265.  
  266. /**
  267. * Ecumenical Keys
  268. */
  269. if (Boundary.isIn(npc, Boundary.NEX)) {
  270. if (Misc.random(60 + 10 * player.getItems().getItemCount(Godwars.KEY_ID, true)) == 1) {
  271. /**
  272. * Key will not drop if player owns more than 3 keys already
  273. */
  274. int key_amount = player.getDiaryManager().getWildernessDiary().hasCompleted("ELITE") ? 6 : 3;
  275. if (player.getItems().getItemCount(Godwars.KEY_ID, true) > key_amount) {
  276. return;
  277. }
  278. Server.itemHandler.createGroundItem(player, Godwars.KEY_ID, npc.getX(), npc.getY(), player.heightLevel, 1, player.getIndex());
  279. //player.sendMessage("@pur@An Ecumenical Key drops from your foe.");
  280. }
  281. }
  282.  
  283. /**
  284. * Dark Light
  285. */
  286. if (Boundary.isIn(npc, Boundary.CATACOMBS)) {
  287. if (Misc.random(1000) == 1) {
  288.  
  289. //PlayerHandler.executeGlobalMessage("<col=FF0000>[Lootations] @cr19@ </col><col=255>"+ Misc.capitalize(player.playerName) + "</col> received a <col=255>Darklight!</col>.");
  290. Server.itemHandler.createGroundItem(player, 6746, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  291. }
  292. }
  293.  
  294. /**
  295. * Dark totem Pieces
  296. */
  297. if (Boundary.isIn(npc, Boundary.CATACOMBS)) {
  298. switch (Misc.random(25)) {
  299. case 1:
  300. if (player.getItems().getItemCount(19679, false) < 1) {
  301. Server.itemHandler.createGroundItem(player, 19679, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  302. player.sendMessage("@red@A surge of dark energy fills your body as you notice something on the ground.");
  303. }
  304. break;
  305.  
  306. case 2:
  307. if (player.getItems().getItemCount(19681, false) < 1) {
  308. Server.itemHandler.createGroundItem(player, 19681, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  309. player.sendMessage("@red@A surge of dark energy fills your body as you notice something on the ground.");
  310. }
  311. break;
  312.  
  313.  
  314. case 3:
  315. if (player.getItems().getItemCount(19683, false) < 1) {
  316. Server.itemHandler.createGroundItem(player, 19683, location.getX(), location.getY(), location.getZ(), 1, player.getIndex());
  317. player.sendMessage("@red@A surge of dark energy fills your body as you notice something on the ground.");
  318. }
  319. break;
  320. }
  321. }
  322. });
  323. }
  324.  
  325. public double getModifier(Player player) {
  326. double modifier = 1.0;
  327. if (player.getMode().isOsrs() || player.getMode().isHardcoreIronman()) {
  328. modifier -= .15;
  329. if (player.getItems().isWearingItem(2572)) {
  330. modifier -= .03;
  331. } else if (player.getItems().isWearingItem(12785)) {
  332. modifier -= .10;
  333. } if (player.getItems().isWearingItem(9096)) {
  334. modifier -= .01;
  335. } if (player.getItems().isWearingItem(9097)) {
  336. modifier -= .01;
  337. } if (player.getItems().isWearingItem(9098)) {
  338. modifier -= .01;
  339. } if (player.getItems().isWearingItem(9099)) {
  340. modifier -= .01;
  341. } if (player.getItems().isWearingItem(9100)) {
  342. modifier -= .01;
  343. } if (player.getItems().isWearingItem(9101)) {
  344. modifier -= .01;
  345. } if (player.getItems().isWearingItem(9084)) {
  346. modifier -= .05;
  347. } if (player.getItems().isWearingItem(5521) && player.getItems().isWearingItem(9104)) {
  348. modifier -= .18;
  349. } else if (player.getItems().isWearingItem(9104)) {
  350. modifier -= .06;
  351. } else if (player.getItems().isWearingItem(5521)) {
  352. modifier -= .06;
  353. }
  354. if(player.getMode().isOsrs() || player.getMode().isHardcoreIronman()) {
  355. modifier -= .15;
  356. }
  357. if (player.summonId == 9959) {
  358. modifier -= .15;
  359. }else if (player.summonId == 13326) {
  360. modifier -= .10;
  361. } if (player.summonId == 9958) {
  362. modifier -= .40;
  363. }
  364. if (player.getRights().contains(Right.UBER_DONATOR)) {
  365. modifier -= .20;
  366. } else if (player.getRights().contains(Right.LEGENDARY)) {
  367. modifier -= .16;
  368. } else if (player.getRights().contains(Right.EXTREME_DONATOR)) {
  369. modifier -= .15;
  370. } else if (player.getRights().contains(Right.SUPER_DONATOR)) {
  371. modifier -= .12;
  372. } else if (player.getRights().contains(Right.DONATOR)) {
  373. modifier -= .10;
  374. } else if (player.getRights().contains(Right.SUPPORTER)) {
  375. modifier -= .07;
  376. } else if (player.getRights().contains(Right.SPONSOR)) {
  377. modifier -= .05;
  378. } else if (player.getRights().contains(Right.CONTRIBUTOR)) {
  379. modifier -= .03;
  380. }
  381. if (modifier < 0) {
  382. modifier = 0;
  383. }
  384. }
  385. return modifier;
  386. }
  387. public static double getModifier1(Player player) {
  388. int modifier = 0;
  389. if (player.getItems().isWearingItem(2572)) {
  390. modifier += 3;
  391. } else if (player.getItems().isWearingItem(12785)) {
  392. modifier += 10;
  393. } if (player.getItems().isWearingItem(9096)) {
  394. modifier += 1;
  395. } if (player.getItems().isWearingItem(9097)) {
  396. modifier += 1;
  397. } if (player.getItems().isWearingItem(9098)) {
  398. modifier += 1;
  399. } if (player.getItems().isWearingItem(9099)) {
  400. modifier += 1;
  401. } if (player.getItems().isWearingItem(9100)) {
  402. modifier += 1;
  403. } if (player.getItems().isWearingItem(9101)) {
  404. modifier += 1;
  405. } if (player.getItems().isWearingItem(9084)) {
  406. modifier += 5;
  407. } if (player.getItems().isWearingItem(5521) && player.getItems().isWearingItem(9104)) {
  408. modifier += 18;
  409. } else if (player.getItems().isWearingItem(9104)) {
  410. modifier += 6;
  411. } else if (player.getItems().isWearingItem(5521)) {
  412. modifier += 6;
  413. }
  414. if(player.getMode().isOsrs() || player.getMode().isHardcoreIronman()) {
  415. modifier += 15;
  416. }
  417. if (player.summonId == 9959) {
  418. modifier += 15;
  419. }else if (player.summonId == 13326) {
  420. modifier += 10;
  421. } if (player.summonId == 9958) {
  422. modifier += 40;
  423. }
  424. if (player.getRights().contains(Right.UBER_DONATOR)) {
  425. modifier += 20;
  426. } else if (player.getRights().contains(Right.LEGENDARY)) {
  427. modifier += 16;
  428. } else if (player.getRights().contains(Right.EXTREME_DONATOR)) {
  429. modifier += 15;
  430. } else if (player.getRights().contains(Right.SUPER_DONATOR)) {
  431. modifier += 12;
  432. } else if (player.getRights().contains(Right.DONATOR)) {
  433. modifier += 10;
  434. } else if (player.getRights().contains(Right.SUPPORTER)) {
  435. modifier += 7;
  436. } else if (player.getRights().contains(Right.SPONSOR)) {
  437. modifier += 5;
  438. } else if (player.getRights().contains(Right.CONTRIBUTOR)) {
  439. modifier += 3;
  440. }
  441. if (modifier > 100) {
  442. modifier = 100;
  443. }
  444. return modifier;
  445. }
  446. /**
  447. * Clears the interface of all parts.
  448. *
  449. * Used on searching and initial load.
  450. * @param player
  451. */
  452. public void clear(Player player) {
  453. for(int i = 0; i < 150; i++) {
  454. player.getPA().sendFrame126("", 33008 + i);
  455. }
  456.  
  457. player.getPA().sendFrame126("", 43110);
  458. player.getPA().sendFrame126("", 43111);
  459. player.getPA().sendFrame126("", 43112);
  460. player.getPA().sendFrame126("", 43113);
  461.  
  462. for(int i = 0;i<80;i++){
  463. player.getPA().itemOnInterface(-1, 0, 34010+i, 0);
  464. player.getPA().sendString("", 34200+i);
  465. player.getPA().sendString("", 34300+i);
  466. player.getPA().sendString("", 34100+i);
  467. player.getPA().sendString("", 34400+i);
  468. }
  469. player.searchList.clear();
  470. }
  471.  
  472. public void open2(Player player) {
  473. clear(player);
  474.  
  475. for (int index = 0; index < ordered.size(); index++) {
  476. player.getPA().sendFrame126(StringUtils.capitalize(NPCDefinitions.get(ordered.get(index)).getNpcName().toLowerCase().replaceAll("_", " ")), 33008 + index);
  477. }
  478.  
  479. player.getPA().showInterface(33000);
  480. }
  481.  
  482. /**
  483. * Searchers after the player inputs a npc name
  484. * @param player
  485. * @param name
  486. */
  487. public void search(Player player, String name) {
  488. if(name.matches("^(?=.*[A-Z])(?=.*[0-9])[A-Z0-9]+$")) {
  489. player.sendMessage("You may not search for alphabetical and numerical combinations.");
  490. return;
  491. }
  492. if (System.currentTimeMillis() - player.lastDropTableSearch < TimeUnit.SECONDS.toMillis(5)) {
  493. player.sendMessage("You can only do this once every 5 seconds.");
  494. return;
  495. }
  496. player.lastDropTableSearch = System.currentTimeMillis();
  497.  
  498. clear(player);
  499.  
  500. List<Integer> definitions = ordered.stream().filter(Objects::nonNull).filter(def -> NPCDefinitions.get(def).getNpcName() != null).filter(def -> NPCDefinitions.get(def).getNpcName().toLowerCase().contains(name.toLowerCase())).collect(Collectors.toList());
  501.  
  502. if(definitions.isEmpty()) {
  503. definitions = ordered.stream().filter(Objects::nonNull).collect(Collectors.toList());
  504. List<Integer> npcs = new ArrayList<>();
  505. int count = 0;
  506. for(Integer index : definitions) {
  507. Optional<TableGroup> group = groups.values().stream().filter(g -> g.getNpcIds().contains(NPCDefinitions.get(index).getNpcId())).findFirst();
  508. if(group.isPresent()) {
  509. TableGroup g = group.get();
  510.  
  511. for(TablePolicy policy : TablePolicy.values()) {
  512. Optional<Table> table = g.stream().filter(t -> t.getPolicy() == policy).findFirst();
  513. if(table.isPresent()) {
  514. for(Drop drop : table.get()) {
  515. if(drop == null) {
  516. continue;
  517. }
  518.  
  519. if(ItemAssistant.getItemName(drop.getItemId()).toLowerCase().contains(name.toLowerCase())) {
  520. npcs.add(index);
  521. player.getPA().sendFrame126(StringUtils.capitalize(NPCDefinitions.get(NPCDefinitions.get(index).getNpcId()).getNpcName().toLowerCase().replaceAll("_", " ")), 33008 + count);
  522. count++;
  523. }
  524. }
  525. }
  526. }
  527. }
  528.  
  529. }
  530.  
  531. player.searchList = npcs;
  532. return;
  533.  
  534. }
  535.  
  536. for(int index = 0; index < definitions.size(); index++) {
  537. if(index >= 150) {
  538. break;
  539. }
  540. player.getPA().sendFrame126(StringUtils.capitalize(NPCDefinitions.get(definitions.get(index)).getNpcName().toLowerCase().replaceAll("_", " ")), 33008 + index);
  541. }
  542.  
  543. player.searchList = definitions;
  544. }
  545.  
  546. /**
  547. * Loads the selected npc choosen by the player to view their drops
  548. * @param player
  549. * @param button
  550. */
  551. public void select(Player player, int button) {
  552. int listIndex;
  553.  
  554. //So the idiot client dev didn't organize the buttons in a singulatiry order. So i had to shift around the id's
  555. //so if you have 50 npcs in the search you can click them all fine
  556. if(button <= 128255) {
  557. listIndex = button - 128240;
  558. } else {
  559. listIndex = (128255 - 128240) + 1 + button - 129000;
  560. }
  561.  
  562. if (listIndex < 0 || listIndex > ordered.size() - 1) {
  563. return;
  564. }
  565.  
  566. //Finding NPC ID
  567. int npcId = player.searchList.isEmpty() ? ordered.get(listIndex) : player.searchList.get(listIndex);
  568.  
  569. Optional<TableGroup> group = groups.values().stream().filter(g -> g.getNpcIds().contains(npcId)).findFirst();
  570.  
  571. //If the group in the search area contains this NPC
  572. group.ifPresent(g -> {
  573. if (System.currentTimeMillis() - player.lastDropTableSelected < TimeUnit.SECONDS.toMillis(5)) {
  574. player.sendMessage("You can only do this once every 5 seconds.");
  575. return;
  576. }
  577.  
  578. //Loads the definition and maxhit/aggressiveness to display
  579. NPCDefinitions npcDef = NPCDefinitions.get(npcId);
  580.  
  581. player.getPA().sendFrame126("Health: @whi@" + npcDef.getNpcHealth(), 43110);
  582. player.getPA().sendFrame126("Combat Level: @whi@" + npcDef.getNpcCombat(), 43111);
  583. if(NPCHandler.getNpc(npcId) != null){
  584. player.getPA().sendFrame126("Max Hit: @whi@" + NPCHandler.getNpc(npcId).maxHit, 43112);
  585. } else {
  586. player.getPA().sendFrame126("Max Hit: @whi@?", 43112);
  587. }
  588. player.getPA().sendFrame126("Aggressive: @whi@" + (Server.npcHandler.isAggressive(npcId, true) ? "true" : "false"), 43113);
  589.  
  590. player.lastDropTableSelected = System.currentTimeMillis();
  591.  
  592. double modifier = getModifier(player);
  593. //Iterates through all 5 drop table's (Found in TablePolicy -> Enum)
  594. for (TablePolicy policy : TablePolicy.POLICIES) {
  595. Optional<Table> table = g.stream().filter(t -> t.getPolicy() == policy).findFirst();
  596. if (table.isPresent()) {
  597. double chance = (1.0 /(table.get().getAccessibility() * modifier)) * 100D;
  598. int in_kills = (int) (100 / chance);
  599.  
  600.  
  601. if (chance > 100.0) {
  602. chance = 100.0;
  603. }
  604. if (in_kills == 0) {
  605. in_kills = 1;
  606. }
  607.  
  608. //Updates the interface with all new information
  609. updateAmounts(player, policy, table.get(), in_kills);
  610.  
  611. } else {
  612. updateAmounts(player, policy, new ArrayList<>(), -10);
  613. }
  614. }
  615.  
  616. //If the game has displayed all drops and there are empty slots that haven't been filled, clear them
  617. if(player.dropSize < 80) {
  618. for(int i = player.dropSize;i<80;i++){
  619. player.getPA().sendString("", 34200+i);
  620. player.getPA().itemOnInterface(-1, 0, 34010+i, 0);
  621. player.getPA().sendString("", 34300+i);
  622. player.getPA().sendString("", 34100+i);
  623. player.getPA().sendString("", 34400+i);
  624. }
  625. }
  626. player.dropSize = 0;
  627. });
  628. }
  629.  
  630. /**
  631. * Updates the interface for the selected NPC
  632. * @param player
  633. * @param policy
  634. * @param drops
  635. * @param kills
  636. */
  637. private void updateAmounts(Player player, TablePolicy policy, List<Drop> drops, int kills) {
  638.  
  639. //Iterates through all drops in that catagory
  640. for (int index = 0; index < drops.size(); index++) {
  641. Drop drop = drops.get(index);
  642. int minimum = drop.getMinimumAmount();
  643. int maximum = drop.getMaximumAmount();
  644. int frame = (34200 + player.dropSize + index);//collumnOffset + (index * 2);
  645.  
  646. //if max = min, just send the max
  647. if (minimum == maximum) {
  648. player.getPA().sendString(Misc.getValueWithoutRepresentation(drop.getMaximumAmount()), frame);
  649. } else {
  650. player.getPA().sendString(Misc.getValueWithoutRepresentation(drop.getMinimumAmount()) + " - " + Misc.getValueWithoutRepresentation(drop.getMaximumAmount()), frame);
  651. }
  652. player.getPA().itemOnInterface(drop.getItemId(), 1, 34010+player.dropSize + index, 0);
  653. player.getPA().sendString(Misc.optimizeText(policy.name().toLowerCase()), 34300+player.dropSize + index);
  654.  
  655. player.getPA().sendString(Server.itemHandler.getItemList(drop.getItemId()) == null ? "invalid" : Server.itemHandler.getItemList(drop.getItemId()).itemName, 34100 + player.dropSize + index);
  656.  
  657.  
  658. if(kills == -10){
  659. player.getPA().sendString(1 + "/?", 34400 + player.dropSize + index);
  660. } else {
  661. player.getPA().sendString(1 + "/"+kills, 34400 + player.dropSize + index);
  662. }
  663. }
  664.  
  665. player.dropSize += drops.size();
  666. }
  667.  
  668. static int amountt = 0;
  669.  
  670. private FileReader fileReader;
  671.  
  672. /**
  673. * Testing droptables of chosen npcId
  674. * @param player The player who is testing the droptable
  675. * @param npcId The npc who of which the player is testing the droptable from
  676. * @param amount The amount of times the player want to grab a drop from the npc droptable
  677. */
  678. public void test(Player player, int npcId, int amount) {
  679. Optional<TableGroup> group = groups.values().stream().filter(g -> g.getNpcIds().contains(npcId)).findFirst();
  680.  
  681. amountt = amount;
  682.  
  683. while (amount-- > 0) {
  684. group.ifPresent(g -> {
  685. List<GameItem> drops = g.access(player, 1.0, 1);
  686.  
  687. for (GameItem item : drops) {
  688. player.getItems().addItemToBank(item.getId(), item.getAmount());
  689. }
  690. });
  691. }
  692. player.sendMessage("Completed " + amountt + " drops from " + Server.npcHandler.getNpcName(npcId) + ".");
  693. }
  694.  
  695.  
  696. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement