RuneHive-Game
Loading...
Searching...
No Matches
NpcDropParser.java
Go to the documentation of this file.
1package com.runehive.util.parser.impl;
2
3import com.google.gson.JsonObject;
4import com.runehive.game.world.entity.mob.npc.drop.NpcDrop;
5import com.runehive.game.world.entity.mob.npc.drop.NpcDropChance;
6import com.runehive.game.world.entity.mob.npc.drop.NpcDropManager;
7import com.runehive.game.world.entity.mob.npc.drop.NpcDropTable;
8import com.runehive.game.world.items.ItemDefinition;
9import com.runehive.util.parser.GsonParser;
10import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
11import it.unimi.dsi.fastutil.ints.IntSet;
12import org.jire.runehiveps.OldToNew;
13
14import java.util.Arrays;
15import java.util.LinkedList;
16import java.util.List;
17
18/**
19 * Loads npc drops on startup.
20 *
21 * @author Daniel
22 */
23public class NpcDropParser extends GsonParser {
24
25 public NpcDropParser() {
26 super("def/npc/npc_drops", false);
27 }
28
29 @Override
30 protected void parse(JsonObject data) {
31 int[] npcIds = builder.fromJson(data.get("id"), int[].class);
32 IntSet newNpcIds = new IntOpenHashSet(npcIds.length);
33 for (int id : npcIds) {
34 int newId = OldToNew.get(id);
35 if (newId != -1) {
36 newNpcIds.add(newId);
37 } else {
38 newNpcIds.add(id);
39 }
40 }
41 npcIds = newNpcIds.toIntArray();
42
43 boolean rareDropTable = data.get("rare_table").getAsBoolean();
44 NpcDrop[] npcDrops = builder.fromJson(data.get("drops"), NpcDrop[].class);
45
46 List<NpcDrop> always = new LinkedList<>();
47 List<NpcDrop> common = new LinkedList<>();
48 List<NpcDrop> uncommon = new LinkedList<>();
49 List<NpcDrop> rare = new LinkedList<>();
50 List<NpcDrop> veryRare = new LinkedList<>();
51
52 for (NpcDrop drop : npcDrops) {
53 ItemDefinition itemDefinition = ItemDefinition.get(drop.id);
54
55 if (itemDefinition == null)
56 continue;
57
58 if (drop.id == 12073) {// elite clue
59 veryRare.add(drop);
60 drop.setType(NpcDropChance.VERY_RARE);
61 continue;
62 }
63
64 if (drop.id == 2722) {// hard clue
65 rare.add(drop);
66 drop.setType(NpcDropChance.RARE);
67 continue;
68 }
69
70 if (drop.id == 2801) {// medium clue
71 uncommon.add(drop);
72 drop.setType(NpcDropChance.UNCOMMON);
73 continue;
74 }
75
76 if (drop.id == 2677) {// easy clue
77 common.add(drop);
78 drop.setType(NpcDropChance.COMMON);
79 continue;
80 }
81
82 if (drop.id == 11942) {// ecu key
83 veryRare.add(drop);
84 drop.setType(NpcDropChance.VERY_RARE);
85 continue;
86 }
87
88 if (drop.id == 1436) {
89 drop.id = 7936;
90 }
91
92 if (drop.id == 1437) {
93 drop.id = 7937;
94 }
95
96 if (drop.type == NpcDropChance.ALWAYS) {
97 always.add(drop);
98 } else if (drop.type == NpcDropChance.COMMON) {
99 common.add(drop);
100 } else if (drop.type == NpcDropChance.UNCOMMON) {
101 uncommon.add(drop);
102 } else if (drop.type == NpcDropChance.RARE) {
103 rare.add(drop);
104 } else if (drop.type == NpcDropChance.VERY_RARE) {
105 veryRare.add(drop);
106 }
107 }
108
109 //Custom drops
110// for (int npc : npcIds) {
111// if (NpcDefinition.get(npc).getCombatLevel() > 10) {
112// uncommon.add(new NpcDrop(985, NpcDropChance.UNCOMMON, 1, 1, 1));
113// uncommon.add(new NpcDrop(987, NpcDropChance.UNCOMMON, 1, 1, 1));
114// rare.add(new NpcDrop(405, NpcDropChance.RARE, 1, 1, 1));
115// }
116// }
117
118
119 Arrays.sort(npcDrops);
120
121 NpcDropTable table = new NpcDropTable(npcIds, rareDropTable, npcDrops, always.toArray(new NpcDrop[0]), common.toArray(new NpcDrop[0]), uncommon.toArray(new NpcDrop[0]), rare.toArray(new NpcDrop[0]), veryRare.toArray(new NpcDrop[0]));
122
123 if (data.has("roll-data")) {
124 int[] rollData = builder.fromJson(data.get("roll-data"), int[].class);
125 table.setRollData(rollData);
126 }
127
128 for (int id : npcIds) {
129 NpcDropManager.NPC_DROPS.put(id, table);
130 }
131 }
132}
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.
The class which represents a npc drop table.
Represents all of an in-game Item's attributes.
static ItemDefinition get(int id)
Gets an item definition.
GsonParser(String path)
Creates a new GsonParser.
transient Gson builder
The Gson object.
void parse(JsonObject data)
The method allows a user to modify the data as its being parsed.
The enumerated type whose elements represent a set of constants used to differ between NpcDrop rariti...