From 488dd92893a5d786949ca6f0ba88cbe74f00f5ad Mon Sep 17 00:00:00 2001 From: OMGeeky Date: Mon, 23 Jun 2025 17:25:39 +0200 Subject: [PATCH] extract actorConditionElementChanged + some parse stuff --- .../model/gamedata/Common.java | 12 +++++ .../atcontentstudio/model/gamedata/Item.java | 40 ++++------------ .../atcontentstudio/model/gamedata/NPC.java | 47 ++----------------- 3 files changed, 25 insertions(+), 74 deletions(-) diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java index b8ee41e..c85d383 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Common.java @@ -10,6 +10,18 @@ import java.util.Map; public final class Common { + public static void actorConditionElementChanged(List list, GameDataElement oldOne, GameDataElement newOne,GameDataElement backlink){ + if (list != null) { + for (T c : list) { + if (c.condition == oldOne) { + oldOne.removeBacklink(backlink); + c.condition = (ActorCondition) newOne; + if (newOne != null) newOne.addBacklink(backlink); + } + } + } + + } //region link common stuff public static void linkConditions(List conditions, Project proj, GameDataElement backlink) { if (conditions != null) { diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java index 5f44f59..30b9480 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/Item.java @@ -308,42 +308,18 @@ public class Item extends JSONElement { this.category = (ItemCategory) newOne; if (newOne != null) newOne.addBacklink(this); } else { - if (this.equip_effect != null && this.equip_effect.conditions != null) { - for (ActorConditionEffect c : this.equip_effect.conditions) { - if (c.condition == oldOne) { - oldOne.removeBacklink(this); - c.condition = (ActorCondition) newOne; - if (newOne != null) newOne.addBacklink(this); - } + if (this.equip_effect != null) { + if (this.equip_effect.conditions != null) { + actorConditionElementChanged(this.equip_effect.conditions, oldOne, newOne, this); } } - if (this.hit_effect != null && this.hit_effect.conditions_source != null) { - for (TimedActorConditionEffect c : this.hit_effect.conditions_source) { - if (c.condition == oldOne) { - oldOne.removeBacklink(this); - c.condition = (ActorCondition) newOne; - if (newOne != null) newOne.addBacklink(this); - } - } - } - if (this.hit_effect != null && this.hit_effect.conditions_target != null) { - for (TimedActorConditionEffect c : this.hit_effect.conditions_target) { - if (c.condition == oldOne) { - oldOne.removeBacklink(this); - c.condition = (ActorCondition) newOne; - if (newOne != null) newOne.addBacklink(this); - } - } + if (this.hit_effect != null) { + actorConditionElementChanged(this.hit_effect.conditions_source, oldOne, newOne, this); + actorConditionElementChanged(this.hit_effect.conditions_target, oldOne, newOne, this); } - if (this.kill_effect != null && this.kill_effect.conditions_source != null) { - for (TimedActorConditionEffect c : this.kill_effect.conditions_source) { - if (c.condition == oldOne) { - oldOne.removeBacklink(this); - c.condition = (ActorCondition) newOne; - if (newOne != null) newOne.addBacklink(this); - } - } + if (this.kill_effect != null) { + actorConditionElementChanged(this.kill_effect.conditions_source, oldOne, newOne, this); } } } diff --git a/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java b/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java index 4d9e424..3dec0fe 100644 --- a/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java +++ b/src/com/gpl/rpg/atcontentstudio/model/gamedata/NPC.java @@ -171,19 +171,7 @@ public class NPC extends JSONElement { Map hitEffect = (Map) npcJson.get("hitEffect"); if (hitEffect != null) { - this.hit_effect = new HitEffect(); - if (hitEffect.get("increaseCurrentHP") != null) { - this.hit_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map) hitEffect.get("increaseCurrentHP")).get("max"))); - this.hit_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map) hitEffect.get("increaseCurrentHP")).get("min"))); - } - if (hitEffect.get("increaseCurrentAP") != null) { - this.hit_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map) hitEffect.get("increaseCurrentAP")).get("max"))); - this.hit_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map) hitEffect.get("increaseCurrentAP")).get("min"))); - } - List conditionsSourceJson = (List) hitEffect.get("conditionsSource"); - this.hit_effect.conditions_source = parseTimedConditionEffects(conditionsSourceJson); - List conditionsTargetJson = (List) hitEffect.get("conditionsTarget"); - this.hit_effect.conditions_target = parseTimedConditionEffects(conditionsTargetJson); + this.hit_effect = parseHitEffect(hitEffect); } Map hitReceivedEffect = (Map) npcJson.get("hitReceivedEffect"); @@ -193,19 +181,8 @@ public class NPC extends JSONElement { Map deathEffect = (Map) npcJson.get("deathEffect"); if (deathEffect != null) { - this.death_effect = new HitEffect(); - if (deathEffect.get("increaseCurrentHP") != null) { - this.death_effect.hp_boost_max = JSONElement.getInteger((Number) (((Map) deathEffect.get("increaseCurrentHP")).get("max"))); - this.death_effect.hp_boost_min = JSONElement.getInteger((Number) (((Map) deathEffect.get("increaseCurrentHP")).get("min"))); - } - if (deathEffect.get("increaseCurrentAP") != null) { - this.death_effect.ap_boost_max = JSONElement.getInteger((Number) (((Map) deathEffect.get("increaseCurrentAP")).get("max"))); - this.death_effect.ap_boost_min = JSONElement.getInteger((Number) (((Map) deathEffect.get("increaseCurrentAP")).get("min"))); - } - List conditionsSourceJson = (List) deathEffect.get("conditionsSource"); - this.death_effect.conditions_source = parseTimedConditionEffects(conditionsSourceJson); + this.death_effect = parseDeathEffect(deathEffect); } - } @Override @@ -302,23 +279,9 @@ public class NPC extends JSONElement { this.droplist = (Droplist) newOne; if (newOne != null) newOne.addBacklink(this); } else { - if (this.hit_effect != null && this.hit_effect.conditions_source != null) { - for (TimedActorConditionEffect tce : this.hit_effect.conditions_source) { - if (tce.condition == oldOne) { - oldOne.removeBacklink(this); - tce.condition = (ActorCondition) newOne; - if (newOne != null) newOne.addBacklink(this); - } - } - } - if (this.hit_effect != null && this.hit_effect.conditions_target != null) { - for (TimedActorConditionEffect tce : this.hit_effect.conditions_target) { - if (tce.condition == oldOne) { - oldOne.removeBacklink(this); - tce.condition = (ActorCondition) newOne; - if (newOne != null) newOne.addBacklink(this); - } - } + if (this.hit_effect != null) { + actorConditionElementChanged(this.hit_effect.conditions_source, oldOne, newOne, this); + actorConditionElementChanged(this.hit_effect.conditions_target, oldOne, newOne, this); } } }