RuneHive-Game
Loading...
Searching...
No Matches
com.runehive.util.parser.impl.NpcDropParser Class Reference

Loads npc drops on startup. More...

Inheritance diagram for com.runehive.util.parser.impl.NpcDropParser:
Collaboration diagram for com.runehive.util.parser.impl.NpcDropParser:

Public Member Functions

 NpcDropParser ()
Public Member Functions inherited from com.runehive.util.parser.GsonParser
final void deserialize ()
 The method that deserializes the file information.
 GsonParser (String path)
 Creates a new GsonParser.
 GsonParser (String path, boolean log)
 Creates a new GsonParser.
void initialize (int size)
Public Member Functions inherited from com.runehive.util.parser.GenericParser
 GenericParser (String path, String extension, boolean log)
 Creates a new GenericParser.
final int getIndex ()
 Gets the current index of the line being parsed.
void onRead ()
 The method called after all the data has been parsed.
void run ()
String toString ()

Protected Member Functions

void parse (JsonObject data)
 The method allows a user to modify the data as its being parsed.
Protected Member Functions inherited from com.runehive.util.parser.GsonParser
void onEnd ()
 This method handles what happens after the parser has ended.

Additional Inherited Members

Protected Attributes inherited from com.runehive.util.parser.GsonParser
transient Gson builder
 The Gson object.
Protected Attributes inherited from com.runehive.util.parser.GenericParser
int index
 The index of the current line being parsed.
final Path path
 The path of the file to parse.

Detailed Description

Loads npc drops on startup.

Author
Daniel

Definition at line 23 of file NpcDropParser.java.

Constructor & Destructor Documentation

◆ NpcDropParser()

com.runehive.util.parser.impl.NpcDropParser.NpcDropParser ( )

Definition at line 25 of file NpcDropParser.java.

25 {
26 super("def/npc/npc_drops", false);
27 }

Member Function Documentation

◆ parse()

void com.runehive.util.parser.impl.NpcDropParser.parse ( JsonObject data)
protected

The method allows a user to modify the data as its being parsed.

Parameters
dataThe JsonObject that contains all serialized information.

Reimplemented from com.runehive.util.parser.GsonParser.

Definition at line 30 of file NpcDropParser.java.

30 {
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 }

References com.runehive.game.world.entity.mob.npc.drop.NpcDropChance.ALWAYS, com.runehive.util.parser.GsonParser.builder, com.runehive.game.world.entity.mob.npc.drop.NpcDropChance.COMMON, com.runehive.game.world.items.ItemDefinition.get(), com.runehive.game.world.entity.mob.npc.drop.NpcDropManager.NPC_DROPS, com.runehive.game.world.entity.mob.npc.drop.NpcDropChance.RARE, com.runehive.game.world.entity.mob.npc.drop.NpcDropTable.setRollData(), com.runehive.game.world.entity.mob.npc.drop.NpcDropChance.UNCOMMON, and com.runehive.game.world.entity.mob.npc.drop.NpcDropChance.VERY_RARE.

Here is the call graph for this function:

The documentation for this class was generated from the following file: