RuneHive-Game
Loading...
Searching...
No Matches
CombatProjectileParser.java
Go to the documentation of this file.
1package com.runehive.util.parser.impl;
2
3import com.google.gson.JsonObject;
4import com.runehive.game.Animation;
5import com.runehive.game.Graphic;
6import com.runehive.game.Projectile;
7import com.runehive.game.world.entity.combat.CombatImpact;
8import com.runehive.game.world.entity.combat.magic.MagicImpact;
9import com.runehive.game.world.entity.combat.projectile.CombatProjectile;
10import com.runehive.game.world.entity.combat.ranged.RangedEffects;
11import com.runehive.util.parser.GsonParser;
12
13public class CombatProjectileParser extends GsonParser {
14
16 super("def/combat/projectile_definitions", false);
17 }
18
19 @Override
20 public void parse(JsonObject reader){
21 String name = reader.get("name").getAsString();
22
23 int hitDelay = -1;
24 if (reader.has("hit-delay")) {
25 hitDelay = reader.get("hit-delay").getAsInt();
26 }
27
28 int hitsplatDelay = -1;
29 if (reader.has("hitsplat-delay")) {
30 hitsplatDelay = reader.get("hitsplat-delay").getAsInt();
31 }
32
33 int maxHit = -1;
34 if (reader.has("max-hit")) {
35 maxHit = reader.get("max-hit").getAsInt();
36 }
37
38 CombatImpact effect = null;
39 if (reader.has("magic-effect")) {
40 String effectName = reader.get("magic-effect").getAsString();
41 effect = MagicImpact.valueOf(effectName).getEffect();
42 } else if (reader.has("ranged-effect")) {
43 String effectName = reader.get("ranged-effect").getAsString();
44 effect = RangedEffects.valueOf(effectName).getEffect();
45 }
46
47 Animation animation = null;
48 if (reader.has("animation")) {
49 animation = builder.fromJson(reader.get("animation"), Animation.class);
50 }
51
52 Graphic start = null;
53 if (reader.has("start")) {
54 start = builder.fromJson(reader.get("start"), Graphic.class);
55 }
56
57 Graphic end = null;
58 if (reader.has("end")) {
59 end = builder.fromJson(reader.get("end"), Graphic.class);
60 }
61
62 Projectile projectile = null;
63 if (reader.has("projectile")) {
64 projectile = builder.fromJson(reader.get("projectile"), Projectile.class);
65 }
66
67 CombatProjectile.definitions.put(name, new CombatProjectile(name, maxHit, effect, animation, start, end, projectile, hitDelay, hitsplatDelay));
68 }
69
70}
Class that models a single animation used by an entity.
Represents a single graphic that can be used by entities.
Definition Graphic.java:10
GsonParser(String path)
Creates a new GsonParser.
transient Gson builder
The Gson object.
void parse(JsonObject reader)
The method allows a user to modify the data as its being parsed.
Represents a combat impact hit effect.