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

Parses through the npc spawn file and creates Npcs on startup. More...

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

Public Member Functions

 NpcSpawnParser ()
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

Parses through the npc spawn file and creates Npcs on startup.

Author
Daniel | Obey

Definition at line 16 of file NpcSpawnParser.java.

Constructor & Destructor Documentation

◆ NpcSpawnParser()

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

Definition at line 18 of file NpcSpawnParser.java.

18 {
19 super("def/npc/npc_spawns");
20 }

Member Function Documentation

◆ parse()

void com.runehive.util.parser.impl.NpcSpawnParser.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 23 of file NpcSpawnParser.java.

23 {
24 int id = data.get("id").getAsInt();
25 boolean convertId = true;
26 if (data.has("convert-id")) {
27 convertId = data.get("convert-id").getAsBoolean();
28 }
29 if (convertId) {
30 int newId = OldToNew.get(id);
31 if (newId != -1) {
32 id = newId;
33 }
34 }
35
36 final Position position = builder.fromJson(data.get("position"), Position.class);
37 final Direction facing = Direction.valueOf(data.get("facing").getAsString());
38 int radius = 2;
39 if (data.has("radius")) {
40 radius = data.get("radius").getAsInt();
41 }
42 int instance = Mob.DEFAULT_INSTANCE;
43 if (data.has("instance")) {
44 instance = data.get("instance").getAsInt();
45 }
46 new Npc(id, position, radius, instance, facing).register();
47 }

References com.runehive.util.parser.GsonParser.builder, com.runehive.game.world.entity.Entity.DEFAULT_INSTANCE, and com.runehive.game.world.entity.mob.npc.Npc.register().

Here is the call graph for this function:

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