package com.github.maxopoly.tcgdex; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.Objects; import org.json.JSONArray; import org.json.JSONObject; /** * Describes a single attack of a pokemon, for example 'Confuse Ray' * */ public class Attack { static List parse(JSONArray array) { if (array == null) { return Collections.emptyList(); } List result = new ArrayList<>(); for (int i = 0; i < array.length(); i++) { result.add(new Attack(array.getJSONObject(i))); } return result; } private final List cost; private final String name; private final String effect; private final String damage; Attack(List cost, String name, String effect, String damage) { super(); this.cost = cost; this.name = name; this.effect = effect; this.damage = damage; } Attack(JSONObject json) { this(Types.parse(json.getJSONArray("cost")), json.getString("name"), json.optString("effect"), json.optString("damage")); } public boolean equals(Object o) { if (!(o instanceof Attack)) { return false; } Attack other = (Attack) o; return Objects.deepEquals(new Object[] { this.cost, this.name, this.effect, this.damage }, new Object[] { other.cost, other.name, other.effect, other.damage }); } public int hashCode() { return Objects.hash(this.cost, this.name, this.effect, this.damage); } /** * @return Cost of the attack in the same order as listed on the card */ public List getCost() { return cost; } /** * @return Name of the attack */ public String getName() { return name; } /** * @return Effect/Description of the attack, may be null for attacks without text */ public String getEffect() { return effect; } /** * @return Damage the attack deals. May just be a number like '30', but can also * be a multiplier like 'x20' */ public String getDamage() { return damage; } }