From 1e8e1cd2b1d6db629e1eb3995549112003d81ca4 Mon Sep 17 00:00:00 2001 From: mahdi5235 Date: Tue, 7 May 2019 21:48:34 +0430 Subject: [PATCH] target type json bugs fixed not completely --- src/data/JsonParser.java | 13 +++++++++- src/data/spell.json | 36 +++++++++++++------------- src/models/cards/spell/Spell.java | 4 +++ src/models/cards/spell/TargetType.java | 6 +++-- src/models/map/Map.java | 6 +++-- 5 files changed, 42 insertions(+), 23 deletions(-) diff --git a/src/data/JsonParser.java b/src/data/JsonParser.java index 10d4686..846136e 100644 --- a/src/data/JsonParser.java +++ b/src/data/JsonParser.java @@ -7,6 +7,7 @@ import models.cards.buff.*; import models.cards.spell.SpecialPowerActivateTime; import models.cards.spell.Spell; +import models.cards.spell.TargetType; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; @@ -143,6 +144,16 @@ public static List getSpells() throws FileNotFoundException, JSONException (int) spellHashMap.get("manaPoint"), (int) spellHashMap.get("price") ); + TargetType targetType = null; + try { + targetType = TargetType.valueOf( + (String) + spellHashMap.get("targetType") + ); + } catch (Exception e) { + e.printStackTrace(); + } + spell.setTargetType(targetType); List buffs = (List) spellHashMap.get("effect"); for(Object buffObject : buffs) { HashMap buffHashMap = (HashMap) buffObject; @@ -151,7 +162,7 @@ public static List getSpells() throws FileNotFoundException, JSONException public void buffEffect(Card card) {} }; - if(((String) buffHashMap.get("name")).equalsIgnoreCase("DisarmBuff")) { + if(((String) buffHashMap.get("name")).equalsIgnoreCase("DisarmBuffDisarmBuff")) { buff = new DisarmBuff( (int) buffHashMap.get("maxActivateTime"), (boolean) buffHashMap.get("isContinues") diff --git a/src/data/spell.json b/src/data/spell.json index 8037e3e..f5eae1e 100644 --- a/src/data/spell.json +++ b/src/data/spell.json @@ -8,7 +8,7 @@ { "name": "DisarmBuff", "isContinues": true, - "activeTime": 0 + "maxActivateTime": 0 } ] }, @@ -37,7 +37,7 @@ { "name": "PowerBuff", "isContinues": false, - "activeTime": 1, + "maxActivateTime": 1, "powerPoint": 2 } ] @@ -51,7 +51,7 @@ { "name": "PoisonBuff", "isContinues": false, - "activeTime": 1, + "maxActivateTime": 1, "healthPoint": 4 } ] @@ -65,7 +65,7 @@ { "name": "PowerBuff", "isContinues": false, - "activeTime": 1, + "maxActivateTime": 1, "powerPoint": 4 } ] @@ -86,7 +86,7 @@ { "name": "PoisonBuff", "isContinues": false, - "activeTime": 1, + "maxActivateTime": 1, "healthPoint": 8 } ] @@ -108,12 +108,12 @@ "name": "PowerBuff", "isContinues": false, "powerPoint": 4, - "activeTime": 3 + "maxActivateTime": 3 }, { "name": "DisarmBuff", "isContinues": false, - "activeTime": 3 + "maxActivateTime": 3 } ] }, @@ -126,7 +126,7 @@ { "name": "DisarmBuff", "isContinues": false, - "activeTime": 1 + "maxActivateTime": 1 } ] }, @@ -139,7 +139,7 @@ { "name": "PoisonBuff", "isContinues": false, - "activeTime": 4, + "maxActivateTime": 4, "healthPoint": 1 } ] @@ -153,12 +153,12 @@ { "name": "OPPONENT_BUFF_KILLER", "isContinues": false, - "activeTime": 1 + "maxActivateTime": 1 }, { "name": "MY_BUFF_KILLER", "isContinues": false, - "activeTime": 1 + "maxActivateTime": 1 } ] }, @@ -171,19 +171,19 @@ { "name": "PoisonBuff", "isContinues": false, - "activeTime": 1, + "maxActivateTime": 1, "healthPoint": 6 }, { "name": "HolyBuff", "isContinues": false, - "activeTime": 3, + "maxActivateTime": 3, "healthPoint": 1 }, { "name": "HolyBuff", "isContinues": false, - "activeTime": 3, + "maxActivateTime": 3, "healthPoint": 1 } ] @@ -197,7 +197,7 @@ { "name": "PowerBuff", "isContinues": false, - "activeTime": 1, + "maxActivateTime": 1, "powerPoint": 6 } ] @@ -211,7 +211,7 @@ { "name": "PowerBuff", "isContinues": true, - "activeTime": 0, + "maxActivateTime": 0, "powerPoint": 2 } ] @@ -234,7 +234,7 @@ "name": "Weakening", "price": 1000, "manaPoint": 1, - "targetType": "ONE_OPPONENT_MINION", + "targetType": "AN_OPPONENT_MINION", "effect": [ { "name": "WeaknessBuff", @@ -275,7 +275,7 @@ "name": "Shock", "price": 1200, "manaPoint": 9, - "targetType": "AN_OPPONENT_HERO", + "targetType": "OPPONENT_HERO", "effect": [ { "name": "StunBuff", diff --git a/src/models/cards/spell/Spell.java b/src/models/cards/spell/Spell.java index 8e9b320..0c5618e 100644 --- a/src/models/cards/spell/Spell.java +++ b/src/models/cards/spell/Spell.java @@ -22,6 +22,10 @@ public TargetType getTargetType() { return targetType; } + public void setTargetType(TargetType targetType) { + this.targetType = targetType; + } + public Spell(int id, String name, String description, int manaPoint, int price) { super(id, name, description, manaPoint, price); } diff --git a/src/models/cards/spell/TargetType.java b/src/models/cards/spell/TargetType.java index 451f3bb..29f356f 100644 --- a/src/models/cards/spell/TargetType.java +++ b/src/models/cards/spell/TargetType.java @@ -3,15 +3,17 @@ public enum TargetType { AN_OPPONENT_FORCE("attack to one enemy minion."), SQUARE2x2("attack to a 2×2 square in map."), - ALL_OPPONENT_FORCES("attack to all enemy minion."), + ALL_OPPONENT_FORCE("attack to all enemy minion."), MY_FORCE("apply to my force."), MY_HERO("apply to my hero"), + OPPONENT_HERO(""), OPPONENT_FORCE_OR_MY_FORCE(""), SQUARE3x3("attack to a 3×3 square in map."), ALL_MY_FORCE("apply to all attackers."), - ALL_OPPONENT_FORCES_IN_ONE_COLUMN("attack to all opponent attacker in one column."), + ALL_OPPONENT_FORCE_IN_ONE_COLUMN("attack to all opponent attacker in one column."), AN_OPPONENT_MINION(""), MY_MINION(""); + private final String description; TargetType(String description) { diff --git a/src/models/map/Map.java b/src/models/map/Map.java index ca4fd55..9ba59f5 100644 --- a/src/models/map/Map.java +++ b/src/models/map/Map.java @@ -137,7 +137,7 @@ private List getEffectCells(Spell spell, Cell cell) throws InvalidTargetCe return targetCells; } break; - case ALL_OPPONENT_FORCES: + case ALL_OPPONENT_FORCE: Manager.getInActivePlayer().getActiveCards().forEach( card -> targetCells.add(card.getCell()) ); @@ -149,13 +149,15 @@ private List getEffectCells(Spell spell, Cell cell) throws InvalidTargetCe return targetCells; } return targetCells; - case ALL_OPPONENT_FORCES_IN_ONE_COLUMN: + case ALL_OPPONENT_FORCE_IN_ONE_COLUMN: for (int i = 0; i < 5; i++) { if (cells[i][cell.getY()].getAttacker() != null) { targetCells.add(cells[i][cell.getY()]); } } return targetCells; + case OPPONENT_HERO: + } throw new InvalidTargetCellException(); }