From cf035dedac223af54a78643f7ae32e3968bad54a Mon Sep 17 00:00:00 2001 From: punchready Date: Wed, 11 Aug 2021 00:31:49 +0200 Subject: [PATCH] fix: correctly set maximum values when parsing entities --- .../gamelibrary/entities/Character.java | 31 +++++++++++++++++++ .../deserialize/EntityDeserializer.java | 3 ++ 2 files changed, 34 insertions(+) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java index aed8b37..ea05be9 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/entities/Character.java @@ -58,6 +58,37 @@ public class Character extends Entity { this.meleeDamage = meleeDamage; } + /** + * Constructs a new {@link Character} with an empty inventory. + * @param id The {@link EntityID} of the character + * @param position The position of the character + * @param name The name of the character + * @param maxHp The maximum hp of the character + * @param maxMp The maximum mp of the character + * @param maxAp The maximum ap of the character + * @param hp The current hp of the character + * @param mp The current mp of the character + * @param ap The current ap of the character + * @param attackRange The ranged attack range of the character + * @param rangedDamage The ranged damage of the character + * @param meleeDamage The melee damage of the character + */ + public Character(EntityID id, IntVector2 position, String name, int maxHp, int maxMp, int maxAp, int hp, int mp, int ap, int attackRange, int rangedDamage, int meleeDamage) { + super(id, position); + solid = false; + opaque = true; + if(id.type == EntityType.NPC && id.id == NPCType.Thanos.getID()) { + solid = true; //characters cannot walk into thanos + } + this.name = name; + this.hp = new Stat(StatType.HP, hp, maxHp); + this.mp = new Stat(StatType.MP, mp, maxMp); + this.ap = new Stat(StatType.AP, ap, maxAp); + this.attackRange = attackRange; + this.rangedDamage = rangedDamage; + this.meleeDamage = meleeDamage; + } + /** * Checks if the character is still alive. * @return Whether or not the characters hp is greater than 0 diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java index f9473b7..6362674 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/ingame/deserialize/EntityDeserializer.java @@ -43,6 +43,9 @@ public class EntityDeserializer extends JsonDeserializer { id, codec.treeToValue(node.get("position"), IntVector2.class), characterName, + properties.HP, + properties.MP, + properties.AP, node.get("HP").asInt(), node.get("MP").asInt(), node.get("AP").asInt(),