RuneHive-Game
Loading...
Searching...
No Matches
NpcSpawnParser.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.Direction;
5import com.runehive.game.world.entity.mob.Mob;
6import com.runehive.game.world.entity.mob.npc.Npc;
7import com.runehive.game.world.position.Position;
8import com.runehive.util.parser.GsonParser;
9import org.jire.runehiveps.OldToNew;
10
11/**
12 * Parses through the npc spawn file and creates {@link Npc}s on startup.
13 *
14 * @author Daniel | Obey
15 */
16public class NpcSpawnParser extends GsonParser {
17
18 public NpcSpawnParser() {
19 super("def/npc/npc_spawns");
20 }
21
22 @Override
23 protected void parse(JsonObject data) {
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 }
48
49}
Handles the mob class.
Definition Mob.java:66
Represents a non-player character in the in-game world.
Definition Npc.java:29
void register()
Registers an entity to the World.
Definition Npc.java:112
Represents a single tile on the game world.
Definition Position.java:14
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.
Represents the enumerated directions an entity can walk or face.