diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtil.java b/forge-ai/src/main/java/forge/ai/ComputerUtil.java index 419f3c2a672..c4098f66263 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtil.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtil.java @@ -715,21 +715,19 @@ public class ComputerUtil { } Card c; - if (CardLists.getNotType(remaining, "Creature").size() == 0) { c = ComputerUtilCard.getWorstCreatureAI(remaining); - } else if (CardLists.getNotType(remaining, "Land").size() == 0) { + } + else if (CardLists.getNotType(remaining, "Land").size() == 0) { c = ComputerUtilCard.getWorstLand(CardLists.filter(remaining, CardPredicates.Presets.LANDS)); - } else { + } + else { c = ComputerUtilCard.getWorstPermanentAI(remaining, false, false, false, false); } - final ArrayList auras = c.getEnchantedBy(); - - if (auras.size() > 0) { + if (c.isEnchanted()) { // TODO: choose "worst" controlled enchanting Aura - for (int j = 0; j < auras.size(); j++) { - final Card aura = auras.get(j); + for (Card aura : c.getEnchantedBy(false)) { if (aura.getController().equals(c.getController()) && remaining.contains(aura)) { return aura; } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java index 55be867bc6d..83c17ca8277 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCard.java @@ -716,8 +716,10 @@ public class ComputerUtilCard { int curCMC = card.getCMC(); // Add all cost of all auras with the same controller - final List auras = CardLists.filterControlledBy(card.getEnchantedBy(), card.getController()); - curCMC += Aggregates.sum(auras, CardPredicates.Accessors.fnGetCmc) + auras.size(); + if (card.isEnchanted()) { + final List auras = CardLists.filterControlledBy(card.getEnchantedBy(false), card.getController()); + curCMC += Aggregates.sum(auras, CardPredicates.Accessors.fnGetCmc) + auras.size(); + } if (curCMC >= bigCMC) { bigCMC = curCMC; @@ -1040,7 +1042,7 @@ public class ComputerUtilCard { } if (c.isEnchanted()) { boolean myEnchants = false; - for (Card enc : c.getEnchantedBy()) { + for (Card enc : c.getEnchantedBy(false)) { if (enc.getOwner().equals(ai)) { myEnchants = true; break; diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java index 155c45d6d90..a2f78199157 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java @@ -418,11 +418,13 @@ public class ComputerUtilCombat { */ public static int totalDamageOfBlockers(final Card attacker, final List defenders) { int damage = 0; - - for (Card equipment : attacker.getEquippedBy()) { - if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) { - defenders.remove(0); - } + + if (attacker.isEquipped()) { + for (Card equipment : attacker.getEquippedBy(false)) { + if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) { + defenders.remove(0); + } + } } for (final Card defender : defenders) { @@ -439,7 +441,7 @@ public class ComputerUtilCombat { public static int totalFirstStrikeDamageOfBlockers(final Card attacker, final List defenders) { int damage = 0; - for (Card equipment : attacker.getEquippedBy()) { + for (Card equipment : attacker.getEquippedBy(false)) { if (equipment.getName().equals("Godsend") && !defenders.isEmpty()) { defenders.remove(0); } @@ -1567,10 +1569,12 @@ public class ComputerUtilCombat { return false; } - for (Card equipment : defender.getEquippedBy()) { - if (equipment.getName().equals("Godsend")) { - return true; - } + if (defender.isEquipped()) { + for (Card equipment : defender.getEquippedBy(false)) { + if (equipment.getName().equals("Godsend")) { + return true; + } + } } int flankingMagnitude = 0; @@ -1599,10 +1603,12 @@ public class ComputerUtilCombat { return true; } - for (Card equipment : attacker.getEquippedBy()) { - if (equipment.getName().equals("Godsend")) { - return false; - } + if (attacker.isEquipped()) { + for (Card equipment : attacker.getEquippedBy(false)) { + if (equipment.getName().equals("Godsend")) { + return false; + } + } } if (attacker.hasKeyword("PreventAllDamageBy Creature.blockingSource")) { @@ -1729,10 +1735,12 @@ public class ComputerUtilCombat { final boolean withoutAbilities) { final Game game = ai.getGame(); - for (Card equipment : attacker.getEquippedBy()) { - if (equipment.getName().equals("Godsend")) { - return true; - } + if (attacker.isEquipped()) { + for (Card equipment : attacker.getEquippedBy(false)) { + if (equipment.getName().equals("Godsend")) { + return true; + } + } } int flankingMagnitude = 0; @@ -1761,10 +1769,12 @@ public class ComputerUtilCombat { return true; } - for (Card equipment : defender.getEquippedBy()) { - if (equipment.getName().equals("Godsend")) { - return false; - } + if (defender.isEquipped()) { + for (Card equipment : defender.getEquippedBy(false)) { + if (equipment.getName().equals("Godsend")) { + return false; + } + } } int defenderDamage = defender.getNetAttack() diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java index 70710d3618b..a1248a3b43a 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java @@ -16,7 +16,6 @@ import forge.util.TextUtil; import org.apache.commons.lang3.StringUtils; -import java.util.ArrayList; import java.util.List; /** @@ -244,13 +243,12 @@ public class ComputerUtilCost { final CostSacrifice sac = (CostSacrifice) part; final String type = sac.getType(); - + if (type.equals("CARDNAME")) { if (!important) { return false; } - List auras = new ArrayList(source.getEnchantedBy()); - if (!CardLists.filterControlledBy(auras, source.getController()).isEmpty()) { + if (!CardLists.filterControlledBy(source.getEnchantedBy(false), source.getController()).isEmpty()) { return false; } continue; diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index bde24f0879c..c3407288210 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -1118,7 +1118,7 @@ public class ComputerUtilMana { && replacementEffect.zonesCheck(game.getZoneOf(crd))) { String repType = crd.getSVar(replacementEffect.getMapParams().get("ManaReplacement")); if (repType.contains("Chosen")) { - repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColors().get(0))); + repType = repType.replace("Chosen", MagicColor.toShortString(crd.getChosenColor())); } mp.setManaReplaceType(repType); } diff --git a/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java b/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java index 43f05da4c54..c31fa44dd9e 100644 --- a/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/AnimateAi.java @@ -325,9 +325,9 @@ public class AnimateAi extends SpellAbilityAi { if (sa.hasParam("Colors")) { final String colors = sa.getParam("Colors"); if (colors.equals("ChosenColor")) { - tmpDesc = CardUtil.getShortColorsString(source.getChosenColors()); - } else { + } + else { tmpDesc = CardUtil.getShortColorsString(new ArrayList(Arrays.asList(colors.split(",")))); } } diff --git a/forge-ai/src/main/java/forge/ai/ability/AttachAi.java b/forge-ai/src/main/java/forge/ai/ability/AttachAi.java index 1a877afcbc1..78ecda3d3d7 100644 --- a/forge-ai/src/main/java/forge/ai/ability/AttachAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/AttachAi.java @@ -211,7 +211,7 @@ public class AttachAi extends SpellAbilityAi { return true; } - final ArrayList auras = c.getEnchantedBy(); + final Iterable auras = c.getEnchantedBy(false); final Iterator itr = auras.iterator(); while (itr.hasNext()) { final Card aura = itr.next(); @@ -626,9 +626,10 @@ public class AttachAi extends SpellAbilityAi { prefList = CardLists.filter(prefList, new Predicate() { @Override public boolean apply(final Card c) { - for (Card aura : c.getEnchantedBy()) { - if (aura.getName().equals(attachSource.getName())) + for (Card aura : c.getEnchantedBy(false)) { + if (aura.getName().equals(attachSource.getName())) { return false; + } } return true; } @@ -684,9 +685,10 @@ public class AttachAi extends SpellAbilityAi { } // don't equip creatures that don't gain anything if (card.hasSVar("NonStackingAttachEffect")) { - for (Card equipment : newTarget.getEquippedBy()) { - if (equipment.getName().equals(card.getName())) + for (Card equipment : newTarget.getEquippedBy(false)) { + if (equipment.getName().equals(card.getName())) { return false; + } } } } @@ -907,13 +909,19 @@ public class AttachAi extends SpellAbilityAi { prefList = CardLists.filter(prefList, new Predicate() { @Override public boolean apply(final Card c) { - for (Card equipment : c.getEquippedBy()) { - if (equipment.getName().equals(attachSource.getName())) - return false; + if (c.isEquipped()) { + for (Card equipment : c.getEquippedBy(false)) { + if (equipment.getName().equals(attachSource.getName())) { + return false; + } + } } - for (Card aura : c.getEnchantedBy()) { - if (aura.getName().equals(attachSource.getName())) - return false; + if (c.isEnchanted()) { + for (Card aura : c.getEnchantedBy(false)) { + if (aura.getName().equals(attachSource.getName())) { + return false; + } + } } return true; } diff --git a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java index 70040e7994a..4bdb45e2151 100644 --- a/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/ChangeZoneAi.java @@ -811,7 +811,7 @@ public class ChangeZoneAi extends SpellAbilityAi { list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { - for (Card aura : c.getEnchantedBy()) { + for (Card aura : c.getEnchantedBy(false)) { if (aura.getController().isOpponentOf(ai)) { return true; } else { @@ -885,7 +885,7 @@ public class ChangeZoneAi extends SpellAbilityAi { list = CardLists.filter(list, new Predicate() { @Override public boolean apply(final Card c) { - for (Card aura : c.getEnchantedBy()) { + for (Card aura : c.getEnchantedBy(false)) { if (c.getOwner().isOpponentOf(ai) && aura.getController().equals(ai)) { return false; } diff --git a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java index c1ef996988b..0673950681a 100644 --- a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java @@ -78,7 +78,7 @@ public class CountersPutAi extends SpellAbilityAi { if (sa.hasParam("LevelUp")) { // creatures enchanted by curse auras have low priority if (source.getGame().getPhaseHandler().getPhase().isBefore(PhaseType.MAIN2)) { - for (Card aura : source.getEnchantedBy()) { + for (Card aura : source.getEnchantedBy(false)) { if (aura.getController().isOpponentOf(ai)) { return false; } diff --git a/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java b/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java index 6c3b7be3329..dd6249db80c 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DestroyAi.java @@ -175,7 +175,7 @@ public class DestroyAi extends SpellAbilityAi { } else { // Don't destroy stolen permanents when the stealing aura can be destroyed if (choice.getOwner() == ai) { - for (Card aura : choice.getEnchantedBy()) { + for (Card aura : choice.getEnchantedBy(false)) { SpellAbility sp = aura.getFirstSpellAbility(); if (sp != null && "GainControl".equals(sp.getParam("AILogic")) && aura.getController() != ai && sa.canTarget(aura)) { diff --git a/forge-ai/src/main/java/forge/ai/ability/TokenAi.java b/forge-ai/src/main/java/forge/ai/ability/TokenAi.java index a9e9220929e..3f5b05858c6 100644 --- a/forge-ai/src/main/java/forge/ai/ability/TokenAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/TokenAi.java @@ -296,7 +296,7 @@ public class TokenAi extends SpellAbilityAi { for (int i = 0; i < substitutedColors.length; i++) { if (substitutedColors[i].equals("ChosenColor")) { // this currently only supports 1 chosen color - substitutedColors[i] = host.getChosenColors().get(0); + substitutedColors[i] = host.getChosenColor(); } } String colorDesc = ""; diff --git a/forge-game/src/main/java/forge/game/GameAction.java b/forge-game/src/main/java/forge/game/GameAction.java index 957f968b64f..39f8739f8f1 100644 --- a/forge-game/src/main/java/forge/game/GameAction.java +++ b/forge-game/src/main/java/forge/game/GameAction.java @@ -336,8 +336,7 @@ public class GameAction { private void unattachCardLeavingBattlefield(Card copied) { // Handle unequipping creatures if (copied.isEquipped()) { - final List equipments = new ArrayList(copied.getEquippedBy()); - for (final Card equipment : equipments) { + for (final Card equipment : copied.getEquippedBy(true)) { if (equipment.isInPlay()) { equipment.unEquipCard(copied); } @@ -345,8 +344,7 @@ public class GameAction { } // Handle unfortifying lands if (copied.isFortified()) { - final List fortifications = new ArrayList(copied.getFortifiedBy()); - for (final Card f : fortifications) { + for (final Card f : copied.getFortifiedBy(true)) { if (f.isInPlay()) { f.unFortifyCard(copied); } @@ -368,8 +366,7 @@ public class GameAction { } // remove enchantments from creatures if (copied.isEnchanted()) { - final List auras = new ArrayList(copied.getEnchantedBy()); - for (final Card aura : auras) { + for (final Card aura : copied.getEnchantedBy(true)) { aura.unEnchantEntity(copied); } } @@ -1012,16 +1009,10 @@ public class GameAction { return checkAgain; } - /** - * TODO: Write javadoc for this method. - * @param c - * @return - */ private boolean stateBasedAction704_5p(Card c) { boolean checkAgain = false; if (c.isEquipped()) { - final List equipments = new ArrayList(c.getEquippedBy()); - for (final Card equipment : equipments) { + for (final Card equipment : c.getEquippedBy(true)) { if (!equipment.isInPlay()) { equipment.unEquipCard(c); checkAgain = true; @@ -1030,8 +1021,7 @@ public class GameAction { } // if isEquipped() if (c.isFortified()) { - final List fortifications = new ArrayList(c.getFortifiedBy()); - for (final Card f : fortifications) { + for (final Card f : c.getFortifiedBy(true)) { if (!f.isInPlay()) { f.unFortifyCard(c); checkAgain = true; @@ -1363,7 +1353,7 @@ public class GameAction { } if (c.isEnchanted()) { - for (Card e : c.getEnchantedBy()) { + for (Card e : c.getEnchantedBy(false)) { CardFactoryUtil.refreshTotemArmor(e); } } diff --git a/forge-game/src/main/java/forge/game/GameEntity.java b/forge-game/src/main/java/forge/game/GameEntity.java index 9fe0b94ed28..31c5bb78fc4 100644 --- a/forge-game/src/main/java/forge/game/GameEntity.java +++ b/forge-game/src/main/java/forge/game/GameEntity.java @@ -21,420 +21,186 @@ import forge.game.card.Card; import forge.game.event.GameEventCardAttachment; import forge.game.event.GameEventCardAttachment.AttachMethod; -import java.util.ArrayList; +import java.util.LinkedHashSet; import java.util.Map; import java.util.TreeMap; -/** - *

- * Abstract Player class. - *

- * - * @author Forge - * @version $Id: Player.java 10091 2011-08-30 16:11:21Z Sloth $ - */ + public abstract class GameEntity extends GameObject { private String name = ""; private int preventNextDamage = 0; + private LinkedHashSet enchantedBy; private TreeMap> preventionShieldsWithEffects = new TreeMap>(); - /** The enchanted by. */ - private ArrayList enchantedBy = new ArrayList(); - - /** - *

- * Getter for the field name. - *

- * - * @return a {@link java.lang.String} object. - */ public String getName() { - return this.name; + return name; } - - /** - *

- * Setter for the field name. - *

- * - * @param s - * a {@link java.lang.String} object. - */ public void setName(final String s) { - this.name = s; + name = s; } - // //////////////////////// - // - // methods for handling damage - // - // //////////////////////// - - /** - *

- * addDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @return whether or not damage was dealt - */ public boolean addDamage(final int damage, final Card source) { int damageToDo = damage; - damageToDo = this.replaceDamage(damageToDo, source, false); - damageToDo = this.preventDamage(damageToDo, source, false); + damageToDo = replaceDamage(damageToDo, source, false); + damageToDo = preventDamage(damageToDo, source, false); - return this.addDamageAfterPrevention(damageToDo, source, false); + return addDamageAfterPrevention(damageToDo, source, false); } - /** - *

- * addDamageWithoutPrevention. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @return whether or not damage was dealt - */ public boolean addDamageWithoutPrevention(final int damage, final Card source) { - int damageToDo = damage; - - damageToDo = this.replaceDamage(damageToDo, source, false); - - return this.addDamageAfterPrevention(damageToDo, source, false); + int damageToDo = replaceDamage(damage, source, false); + return addDamageAfterPrevention(damageToDo, source, false); } - // This function handles damage after replacement and prevention effects are - // applied - /** - *

- * addDamageAfterPrevention. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return whether or not damage was dealt - */ + // This function handles damage after replacement and prevention effects are applied public abstract boolean addDamageAfterPrevention(final int damage, final Card source, final boolean isCombat); - // This should be also usable by the AI to forecast an effect (so it must // not change the game state) - /** - *

- * staticDamagePrevention. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ public int staticDamagePrevention(final int damage, final Card source, final boolean isCombat, final boolean isTest) { return 0; } // This should be also usable by the AI to forecast an effect (so it must // not change the game state) - /** - *

- * staticReplaceDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ public int staticReplaceDamage(final int damage, final Card source, final boolean isCombat) { return 0; } - /** - *

- * replaceDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ public abstract int replaceDamage(final int damage, final Card source, final boolean isCombat); - /** - *

- * preventDamage. - *

- * - * @param damage - * a int. - * @param source - * a {@link forge.game.card.Card} object. - * @param isCombat - * a boolean. - * @return a int. - */ public abstract int preventDamage(final int damage, final Card source, final boolean isCombat); - // //////////////////////// - // - // methods for handling Damage Prevention - // - // //////////////////////// - - // PreventNextDamage - /** - *

- * Setter for the field preventNextDamage. - *

- * - * @param n - * a int. - */ - public void setPreventNextDamage(final int n) { - this.preventNextDamage = n; - } - - /** - *

- * Getter for the field preventNextDamage. - *

- * - * @return a int. - */ public int getPreventNextDamage() { - return this.preventNextDamage; + return preventNextDamage; + } + public void setPreventNextDamage(final int n) { + preventNextDamage = n; } - - /** - *

- * addPreventNextDamage. - *

- * - * @param n - * a int. - */ public void addPreventNextDamage(final int n) { - this.preventNextDamage += n; + preventNextDamage += n; } - - /** - *

- * subtractPreventNextDamage. - *

- * - * @param n - * a int. - */ public void subtractPreventNextDamage(final int n) { - this.preventNextDamage -= n; + preventNextDamage -= n; } - - /** - *

- * resetPreventNextDamage. - *

- */ public void resetPreventNextDamage() { - this.preventNextDamage = 0; + preventNextDamage = 0; } // PreventNextDamageWithEffect - /** - *

- * Gets the map of damage prevention shields with effects. - *

- * - * @return the map of damage prevention shields with effects. - */ public TreeMap> getPreventNextDamageWithEffect() { - return this.preventionShieldsWithEffects; + return preventionShieldsWithEffects; } - - /** - *

- * Adds a damage prevention shield with an effect that happens at time of prevention. - *

- * - * @param shieldSource The source card which generated the shield - * @param effectMap A map of the effect occurring with the damage prevention - */ - public void addPreventNextDamageWithEffect(final Card shieldSource, TreeMap effectMap) { - if (this.preventionShieldsWithEffects.containsKey(shieldSource)) { - int currentShields = Integer.valueOf(this.preventionShieldsWithEffects.get(shieldSource).get("ShieldAmount")); - currentShields += Integer.valueOf(effectMap.get("ShieldAmount")); - effectMap.put("ShieldAmount", Integer.toString(currentShields)); - this.preventionShieldsWithEffects.put(shieldSource, effectMap); - } else { - this.preventionShieldsWithEffects.put(shieldSource, effectMap); - } - } - - /** - *

- * subtractPreventNextDamageWithEffect. - *

- * - * @param shieldSource The source card which generated the shield - * @param n The number of shields to remove originating from shieldSource - */ - public void subtractPreventNextDamageWithEffect(final Card shieldSource, final int n) { - int currentShields = Integer.valueOf(this.preventionShieldsWithEffects.get(shieldSource).get("ShieldAmount")); - if (currentShields > n) { - this.preventionShieldsWithEffects.get(shieldSource).put("ShieldAmount", String.valueOf(currentShields - n)); - } else { - this.preventionShieldsWithEffects.remove(shieldSource); - } - } - - /** - *

- * resetPreventNextDamageWithEffect. - *

- */ - public void resetPreventNextDamageWithEffect() { - this.preventionShieldsWithEffects = new TreeMap>(); - } - - /** - *

- * Gets the total amount of damage prevention shields. - *

- * - * @return the number of damage prevention shields with and without effects. - */ public int getPreventNextDamageTotalShields() { - int shields = this.preventNextDamage; - for (final Map value : this.preventionShieldsWithEffects.values()) { + int shields = preventNextDamage; + for (final Map value : preventionShieldsWithEffects.values()) { shields += Integer.valueOf(value.get("ShieldAmount")); } return shields; } - /** - * Checks for keyword. - * - * @param keyword - * the keyword - * @return true, if successful + * Adds a damage prevention shield with an effect that happens at time of prevention. + * @param shieldSource - The source card which generated the shield + * @param effectMap - A map of the effect occurring with the damage prevention */ + public void addPreventNextDamageWithEffect(final Card shieldSource, TreeMap effectMap) { + if (preventionShieldsWithEffects.containsKey(shieldSource)) { + int currentShields = Integer.valueOf(preventionShieldsWithEffects.get(shieldSource).get("ShieldAmount")); + currentShields += Integer.valueOf(effectMap.get("ShieldAmount")); + effectMap.put("ShieldAmount", Integer.toString(currentShields)); + preventionShieldsWithEffects.put(shieldSource, effectMap); + } else { + preventionShieldsWithEffects.put(shieldSource, effectMap); + } + } + public void subtractPreventNextDamageWithEffect(final Card shieldSource, final int n) { + int currentShields = Integer.valueOf(preventionShieldsWithEffects.get(shieldSource).get("ShieldAmount")); + if (currentShields > n) { + preventionShieldsWithEffects.get(shieldSource).put("ShieldAmount", String.valueOf(currentShields - n)); + } else { + preventionShieldsWithEffects.remove(shieldSource); + } + } + public void resetPreventNextDamageWithEffect() { + preventionShieldsWithEffects = new TreeMap>(); + } + public boolean hasKeyword(final String keyword) { return false; } // GameEntities can now be Enchanted - /** - *

- * Getter for the field enchantedBy. - *

- * - * @return a {@link java.util.ArrayList} object. - */ - public final ArrayList getEnchantedBy() { - return this.enchantedBy; + public final Iterable getEnchantedBy(boolean allowModify) { + if (enchantedBy == null) { + return new LinkedHashSet(); + } + if (allowModify) { //create copy to allow modifying original set while iterating + return new LinkedHashSet(enchantedBy); + } + return enchantedBy; } - - /** - *

- * Setter for the field enchantedBy. - *

- * - * @param list - * a {@link java.util.ArrayList} object. - */ - public final void setEnchantedBy(final ArrayList list) { - this.enchantedBy = list; + public final void setEnchantedBy(final LinkedHashSet list) { + enchantedBy = list; + getView().updateEnchantedBy(this); + } + public final void setEnchantedBy(final Iterable list) { + if (list == null) { + enchantedBy = null; + } + else { + enchantedBy = new LinkedHashSet(); + for (Card c : list) { + enchantedBy.add(c); + } + } + getView().updateEnchantedBy(this); } - - /** - *

- * isEnchanted. - *

- * - * @return a boolean. - */ public final boolean isEnchanted() { - return this.enchantedBy.size() != 0; + return enchantedBy != null && !enchantedBy.isEmpty(); + } + public final boolean isEnchantedBy(Card c) { + return enchantedBy != null && enchantedBy.contains(c); + } + public final boolean isEnchantedBy(final String cardName) { + for (final Card aura : getEnchantedBy(false)) { + if (aura.getName().equals(cardName)) { + return true; + } + } + return false; } - - /** - *

- * addEnchantedBy. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void addEnchantedBy(final Card c) { - this.enchantedBy.add(c); + if (enchantedBy == null) { + enchantedBy = new LinkedHashSet(); + } + enchantedBy.add(c); + getView().updateEnchantedBy(this); getGame().fireEvent(new GameEventCardAttachment(c, null, this, AttachMethod.Enchant)); } - - /** - *

- * removeEnchantedBy. - *

- * - * @param c - * a {@link forge.game.card.Card} object. - */ public final void removeEnchantedBy(final Card c) { - this.enchantedBy.remove(c); - getGame().fireEvent(new GameEventCardAttachment(c, this, null, AttachMethod.Enchant)); - } + if (enchantedBy == null) { return; } - /** - *

- * unEnchantAllCards. - *

- */ + if (enchantedBy.remove(c)) { + getView().updateEnchantedBy(this); + getGame().fireEvent(new GameEventCardAttachment(c, this, null, AttachMethod.Enchant)); + } + } public final void unEnchantAllCards() { - for (int i = 0; i < this.enchantedBy.size(); i++) { - this.enchantedBy.get(i).unEnchantEntity(this); + if (isEnchanted()) { + for (Card c : getEnchantedBy(true)) { + c.unEnchantEntity(this); + } } } - /** - * - * hasProtectionFrom. - * - * @param source - * Card - * @return boolean - */ public boolean hasProtectionFrom(final Card source) { return false; } - // ////////////////////////////// - // - // generic Object overrides - // - // /////////////////////////////// - - /** {@inheritDoc} */ @Override public String toString() { - return this.name; + return name; } public abstract Game getGame(); diff --git a/forge-game/src/main/java/forge/game/GameEntityView.java b/forge-game/src/main/java/forge/game/GameEntityView.java index 79dfe283c51..b0b859de9dc 100644 --- a/forge-game/src/main/java/forge/game/GameEntityView.java +++ b/forge-game/src/main/java/forge/game/GameEntityView.java @@ -1,5 +1,6 @@ package forge.game; +import forge.game.card.CardView; import forge.trackable.TrackableObject; public abstract class GameEntityView> extends TrackableObject { @@ -19,4 +20,21 @@ public abstract class GameEntityView> extends TrackableObject< void updatePreventNextDamage(GameEntity e) { set(preventNextDamageProp(), e.getPreventNextDamageTotalShields()); } + + protected abstract E enchantedByProp(); + + public Iterable getEnchantedBy() { + return get(enchantedByProp()); + } + void updateEnchantedBy(GameEntity e) { + if (e.isEnchanted()) { + set(enchantedByProp(), CardView.getCollection(e.getEnchantedBy(false))); + } + else { + set(enchantedByProp(), null); + } + } + public boolean isEnchanted() { + return getEnchantedBy() != null; + } } diff --git a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java index 68f4d241125..228fd89b3be 100644 --- a/forge-game/src/main/java/forge/game/ability/AbilityUtils.java +++ b/forge-game/src/main/java/forge/game/ability/AbilityUtils.java @@ -30,10 +30,7 @@ import java.util.Map.Entry; import java.util.regex.Matcher; import java.util.regex.Pattern; -/** - * TODO: Write javadoc for this type. - * - */ + public class AbilityUtils { public static CounterType getCounterType(String name, SpellAbility sa) throws Exception { @@ -241,7 +238,7 @@ public class AbilityUtils { } } else if (defined.equals("ChosenCard")) { - for (final Card chosen : hostCard.getChosenCard()) { + for (final Card chosen : hostCard.getChosenCards()) { cards.add(game.getCardState(chosen)); } } @@ -1280,10 +1277,11 @@ public class AbilityUtils { } } else if (unlessCost.equals("ChosenManaCost")) { - if (source.getChosenCard().isEmpty()) { + if (!source.hasChosenCard()) { cost = new Cost(ManaCost.ZERO, true); - } else { - cost = new Cost(source.getChosenCard().get(0).getManaCost(), true); + } + else { + cost = new Cost(Iterables.getFirst(source.getChosenCards(), null).getManaCost(), true); } } else if (unlessCost.equals("RememberedCostMinus2")) { diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChooseCardEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChooseCardEffect.java index 9b7e682e9aa..25ab89139fa 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChooseCardEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChooseCardEffect.java @@ -96,7 +96,7 @@ public class ChooseCardEffect extends SpellAbilityEffect { } } } - host.setChosenCard(chosen); + host.setChosenCards(chosen); if (sa.hasParam("RememberChosen")) { for (final Card rem : chosen) { host.addRemembered(rem); diff --git a/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java index 048026dda77..01830c0d61c 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ChooseSourceEffect.java @@ -145,7 +145,7 @@ public class ChooseSourceEffect extends SpellAbilityEffect { chosen.add(o); sourcesToChooseFrom.remove(o); } - host.setChosenCard(chosen); + host.setChosenCards(chosen); if (sa.hasParam("RememberChosen")) { for (final Card rem : chosen) { host.addRemembered(rem); diff --git a/forge-game/src/main/java/forge/game/ability/effects/CleanUpEffect.java b/forge-game/src/main/java/forge/game/ability/effects/CleanUpEffect.java index 2b09dc636a9..7c3c1186447 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/CleanUpEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/CleanUpEffect.java @@ -39,8 +39,7 @@ public class CleanUpEffect extends SpellAbilityEffect { source.clearFlipResult(); } if (sa.hasParam("ClearChosenCard")) { - source.getChosenCard().clear(); + source.setChosenCards(null); } } - } diff --git a/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java b/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java index 1845ac6350b..00b398aaeeb 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/DestroyEffect.java @@ -11,6 +11,8 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; +import com.google.common.collect.Iterables; + public class DestroyEffect extends SpellAbilityEffect { /* (non-Javadoc) * @see forge.card.abilityfactory.SpellEffect#getStackDescription(java.util.Map, forge.card.spellability.SpellAbility) @@ -97,9 +99,9 @@ public class DestroyEffect extends SpellAbilityEffect { boolean destroyed = false; final Card lki = CardUtil.getLKICopy(tgtC); if (remAttached) { - card.getRemembered().addAll(tgtC.getEnchantedBy()); - card.getRemembered().addAll(tgtC.getEquippedBy()); - card.getRemembered().addAll(tgtC.getFortifiedBy()); + Iterables.addAll(card.getRemembered(), tgtC.getEnchantedBy(false)); + Iterables.addAll(card.getRemembered(), tgtC.getEquippedBy(false)); + Iterables.addAll(card.getRemembered(), tgtC.getFortifiedBy(false)); } if (sac) { destroyed = game.getAction().sacrifice(tgtC, sa) != null; diff --git a/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java b/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java index fcf6e384f26..6bbe5fcb79e 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/EffectEffect.java @@ -19,6 +19,8 @@ import forge.game.zone.ZoneType; import java.util.List; +import com.google.common.collect.Lists; + public class EffectEffect extends SpellAbilityEffect { @Override @@ -189,8 +191,8 @@ public class EffectEffect extends SpellAbilityEffect { } // Set Chosen Color(s) - if (!hostCard.getChosenColors().isEmpty()) { - eff.setChosenColors(hostCard.getChosenColors()); + if (hostCard.hasChosenColor()) { + eff.setChosenColors(Lists.newArrayList(hostCard.getChosenColors())); } // Set Chosen name diff --git a/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java b/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java index d733b4a34cc..9f04cccf2c5 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/TokenEffect.java @@ -170,7 +170,7 @@ public class TokenEffect extends SpellAbilityEffect { for (int i = 0; i < substitutedColors.length; i++) { if (substitutedColors[i].equals("ChosenColor")) { // this currently only supports 1 chosen color - substitutedColors[i] = host.getChosenColors().get(0); + substitutedColors[i] = host.getChosenColor(); } } String colorDesc = ""; diff --git a/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java b/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java index e7698add90c..a1abbba529e 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/UnattachAllEffect.java @@ -16,24 +16,23 @@ import java.util.List; public class UnattachAllEffect extends SpellAbilityEffect { private void handleUnattachment(final GameEntity o, final Card cardToUnattach) { - if (o instanceof Card) { final Card c = (Card) o; if (cardToUnattach.isAura()) { //final boolean gainControl = "GainControl".equals(af.parseParams().get("AILogic")); //AbilityFactoryAttach.handleUnattachAura(cardToUnattach, c, gainControl); } else if (cardToUnattach.isEquipment()) { - if (cardToUnattach.isEquipping() && c.getEquippedBy().contains(cardToUnattach)) { + if (cardToUnattach.isEquipping() && c.isEquippedBy(cardToUnattach)) { cardToUnattach.unEquipCard(cardToUnattach.getEquipping()); } } else if (cardToUnattach.isFortification()) { - if (cardToUnattach.isFortifying() && c.getFortifiedBy().contains(cardToUnattach)) { + if (cardToUnattach.isFortifying() && c.isFortifiedBy(cardToUnattach)) { cardToUnattach.unFortifyCard(cardToUnattach.getFortifying()); } } } else if (o instanceof Player) { final Player p = (Player) o; - if (cardToUnattach.isAura() && p.getEnchantedBy().contains(cardToUnattach)) { + if (cardToUnattach.isAura() && p.isEnchantedBy(cardToUnattach)) { //AbilityFactoryAttach.handleUnattachAura(cardToUnattach, p, false); } } diff --git a/forge-game/src/main/java/forge/game/card/Card.java b/forge-game/src/main/java/forge/game/card/Card.java index d6e839c83d3..49435b22f4d 100644 --- a/forge-game/src/main/java/forge/game/card/Card.java +++ b/forge-game/src/main/java/forge/game/card/Card.java @@ -101,12 +101,12 @@ public class Card extends GameEntity implements Comparable, IIdentifiable private final CopyOnWriteArrayList hiddenExtrinsicKeyword = new CopyOnWriteArrayList(); // which equipment cards are equipping this card? - private ArrayList equippedBy = new ArrayList(); + private LinkedHashSet equippedBy; // if this card is of the type equipment, what card is it currently equipping? private Card equipping = null; // which fortification cards are fortifying this card? - private ArrayList fortifiedBy = new ArrayList(); + private LinkedHashSet fortifiedBy; // if this card is of the type fortification, what card is it currently fortifying? private Card fortifying = null; @@ -213,11 +213,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable private String echoCost = ""; private Cost miracleCost = null; private String chosenType = ""; - private List chosenColors = new ArrayList(); + private List chosenColors; private String namedCard = ""; private int chosenNumber; private Player chosenPlayer; - private List chosenCard = new ArrayList(); + private List chosenCards; private Direction chosenDirection = null; private Card cloneOrigin = null; @@ -871,9 +871,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable int newValue = oldValue == null ? 0 : Math.max(oldValue.intValue() - n, 0); final int delta = (oldValue == null ? 0 : oldValue.intValue()) - newValue; - if (delta == 0) { - return; - } + if (delta == 0) { return; } int powerBonusBefore = getPowerBonusFromCounters(); int toughnessBonusBefore = getToughnessBonusFromCounters(); @@ -1016,7 +1014,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable getCharacteristics().setCardColor(colors); } - public final List getColor() { + public final Iterable getColor() { return getCharacteristics().getCardColor(); } @@ -1031,15 +1029,15 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final Player getChosenPlayer() { return chosenPlayer; } - public final void setChosenPlayer(final Player p) { + if (chosenPlayer == p) { return; } chosenPlayer = p; + view.updateChosenPlayer(this); } public final int getChosenNumber() { return chosenNumber; } - public final void setChosenNumber(final int i) { chosenNumber = i; } @@ -1048,31 +1046,59 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final String getChosenType() { return chosenType; } - public final void setChosenType(final String s) { chosenType = s; + view.updateChosenType(this); } - public final List getChosenColors() { + public final String getChosenColor() { + if (hasChosenColor()) { + return chosenColors.get(0); + } + return ""; + } + public final Iterable getChosenColors() { + if (chosenColors == null) { + return new ArrayList(); + } return chosenColors; } - public final void setChosenColors(final List s) { chosenColors = s; + view.updateChosenColors(this); + } + public boolean hasChosenColor() { + return chosenColors != null && !chosenColors.isEmpty(); + } + public boolean hasChosenColor(String s) { + return chosenColors != null && chosenColors.contains(s); } - public final List getChosenCard() { - return chosenCard; + public final Card getChosenCard() { + if (hasChosenCard()) { + return chosenCards.get(0); + } + return null; } - - public final void setChosenCard(final List c) { - chosenCard = c; + public final Iterable getChosenCards() { + if (chosenCards == null) { + return new ArrayList(); + } + return chosenCards; + } + public final void setChosenCards(final List c) { + chosenCards = c; + } + public boolean hasChosenCard() { + return chosenCards != null && !chosenCards.isEmpty(); + } + public boolean hasChosenCard(Card c) { + return chosenCards != null && chosenCards.contains(c); } public Direction getChosenDirection() { return chosenDirection; } - public void setChosenDirection(Direction chosenDirection0) { chosenDirection = chosenDirection0; } @@ -1081,47 +1107,24 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final String getNamedCard() { return namedCard; } - public final void setNamedCard(final String s) { namedCard = s; - } - - public final void setDrawnThisTurn(final boolean b) { - drawnThisTurn = b; + view.updateNamedCard(this); } public final boolean getDrawnThisTurn() { return drawnThisTurn; } - - /** - * get a list of Cards this card has gained control of. - *

- * used primarily with AbilityFactory_GainControl - * - * @return a list of cards this card has gained control of - */ - public final List getGainControlTargets() { - return gainControlTargets; + public final void setDrawnThisTurn(final boolean b) { + drawnThisTurn = b; } - /** - * add a Card to the list of Cards this card has gained control of. - *

- * used primarily with AbilityFactory_GainControl - * - * @param c - * a {@link forge.game.card.Card} object. - */ + public final List getGainControlTargets() { //used primarily with AbilityFactory_GainControl + return gainControlTargets; + } public final void addGainControlTarget(final Card c) { gainControlTargets.add(c); } - - /** - * clear the list of Cards this card has gained control of. - *

- * used primarily with AbilityFactory_GainControl - */ public final void removeGainControlTargets(final Card c) { gainControlTargets.remove(c); } @@ -1229,13 +1232,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable // get the text that does not belong to a cards abilities (and is not really // there rules-wise) - /** - *

- * getNonAbilityText. - *

- * - * @return a {@link java.lang.String} object. - */ public final String getNonAbilityText() { final StringBuilder sb = new StringBuilder(); final ArrayList keyword = getHiddenExtrinsicKeyword(); @@ -1246,15 +1242,6 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // convert a keyword list to the String that should be displayed ingame - /** - *

- * keywordsToText. - *

- * - * @param keywords - * a {@link java.util.ArrayList} object. - * @return a {@link java.lang.String} object. - */ public final String keywordsToText(final ArrayList keywords) { final StringBuilder sb = new StringBuilder(); final StringBuilder sbLong = new StringBuilder(); @@ -2223,31 +2210,77 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } - public final boolean isEquipped() { - return !equippedBy.isEmpty(); - } - public final ArrayList getEquippedBy() { + public final Iterable getEquippedBy(boolean allowModify) { + if (equippedBy == null) { + return new LinkedHashSet(); + } + if (allowModify) { //create copy to allow modifying original set while iterating + return new LinkedHashSet(equippedBy); + } return equippedBy; } - public final void setEquippedBy(final ArrayList list) { + public final void setEquippedBy(final LinkedHashSet list) { equippedBy = list; + view.updateEquippedBy(this); + } + public final void setEquippedBy(final Iterable list) { + if (list == null) { + equippedBy = null; + } + else { + equippedBy = new LinkedHashSet(); + for (Card c : list) { + equippedBy.add(c); + } + } + getView().updateEquippedBy(this); + } + public final boolean isEquipped() { + return equippedBy != null && !equippedBy.isEmpty(); + } + public final boolean isEquippedBy(Card c) { + return equippedBy != null && equippedBy.contains(c); } - public final boolean isFortified() { - return !fortifiedBy.isEmpty(); - } - public final ArrayList getFortifiedBy() { + public final Iterable getFortifiedBy(boolean allowModify) { + if (fortifiedBy == null) { + return new LinkedHashSet(); + } + if (allowModify) { //create copy to allow modifying original set while iterating + return new LinkedHashSet(fortifiedBy); + } return fortifiedBy; } - public final void setFortifiedBy(final ArrayList list) { + public final void setFortifiedBy(final LinkedHashSet list) { fortifiedBy = list; + view.updateFortifiedBy(this); + } + public final void setFortifiedBy(final Iterable list) { + if (list == null) { + fortifiedBy = null; + } + else { + fortifiedBy = new LinkedHashSet(); + for (Card c : list) { + fortifiedBy.add(c); + } + } + getView().updateFortifiedBy(this); + } + public final boolean isFortified() { + return fortifiedBy != null && !fortifiedBy.isEmpty(); + } + public final boolean isFortifiedBy(Card c) { + return fortifiedBy != null && fortifiedBy.contains(c); } public final Card getEquipping() { return equipping; } public final void setEquipping(final Card card) { + if (equipping == card) { return; } equipping = card; + view.updateEquipping(this); } public final boolean isEquipping() { return equipping != null; @@ -2257,7 +2290,9 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return fortifying; } public final void setFortifying(final Card card) { + if (fortifying == card) { return; } fortifying = card; + view.updateFortifying(this); } public final boolean isFortifying() { return fortifying != null; @@ -2286,9 +2321,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } // They use double links... it's doubtful - equipping = c; + setEquipping(c); setTimestamp(getGame().getNextTimestamp()); + if (c.equippedBy == null) { + c.equippedBy = new LinkedHashSet(); + } c.equippedBy.add(this); + view.updateEquippedBy(this); // Play the Equip sound getGame().fireEvent(new GameEventCardAttachment(this, oldTarget, c, AttachMethod.Equip)); @@ -2307,9 +2346,13 @@ public class Card extends GameEntity implements Comparable, IIdentifiable unFortifyCard(oldTarget); } - fortifying = c; + setFortifying(c); setTimestamp(getGame().getNextTimestamp()); + if (c.fortifiedBy == null) { + c.fortifiedBy = new LinkedHashSet(); + } c.fortifiedBy.add(this); + view.updateFortifiedBy(this); // Play the Equip sound getGame().fireEvent(new GameEventCardAttachment(this, oldTarget, c, AttachMethod.Fortify)); @@ -2322,9 +2365,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final void unEquipCard(final Card c) { // equipment.unEquipCard(equippedCard); if (equipping == c) { - equipping = null; + setEquipping(null); + } + if (c.equippedBy != null && c.equippedBy.remove(this)) { + view.updateEquippedBy(this); } - c.equippedBy.remove(this); getGame().fireEvent(new GameEventCardAttachment(this, c, null, AttachMethod.Equip)); @@ -2337,75 +2382,55 @@ public class Card extends GameEntity implements Comparable, IIdentifiable public final void unFortifyCard(final Card c) { // fortification.unEquipCard(fortifiedCard); if (fortifying == c) { - fortifying = null; + setFortifying(null); + } + if (c.fortifiedBy != null && c.fortifiedBy.remove(this)) { + view.updateFortifiedBy(this); } - c.fortifiedBy.remove(this); - getGame().fireEvent(new GameEventCardAttachment(this, c, null, AttachMethod.Fortify)); } public final void unEquipAllCards() { - // while there exists equipment, unequip the first one - while (equippedBy.size() > 0) { - equippedBy.get(0).unEquipCard(this); + if (isEquipped()) { + for (Card c : getEquippedBy(true)) { + c.unEquipCard(this); + } } } public final GameEntity getEnchanting() { return enchanting; } - + public final void setEnchanting(final GameEntity e) { + if (enchanting == e) { return; } + enchanting = e; + view.updateEnchanting(this); + } public final Card getEnchantingCard() { if (enchanting instanceof Card) { return (Card) enchanting; } return null; } - public final Player getEnchantingPlayer() { if (enchanting instanceof Player) { return (Player) enchanting; } return null; } - - public final void setEnchanting(final GameEntity e) { - enchanting = e; - } - public final boolean isEnchanting() { return enchanting != null; } - public final boolean isEnchantingCard() { return getEnchantingCard() != null; } - public final boolean isEnchantingPlayer() { return getEnchantingPlayer() != null; } - /** - * checks to see if this card is enchanted by an aura with a given name. - * - * @param cardName - * the name of the aura - * @return true if this card is enchanted by an aura with the given name, - * false otherwise - */ - public final boolean isEnchantedBy(final String cardName) { - final ArrayList allAuras = getEnchantedBy(); - for (final Card aura : allAuras) { - if (aura.getName().equals(cardName)) { - return true; - } - } - return false; - } - public final void removeEnchanting(final GameEntity e) { - if (enchanting.equals(e)) { - enchanting = null; + if (enchanting == e) { + setEnchanting(null); } } @@ -2416,7 +2441,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable + " but it can't be enchanted."); return; } - enchanting = entity; + setEnchanting(entity); setTimestamp(getGame().getNextTimestamp()); entity.addEnchantedBy(this); @@ -2430,10 +2455,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } public final void unEnchantEntity(final GameEntity entity) { - if (enchanting == null || !enchanting.equals(entity)) + if (enchanting == null || !enchanting.equals(entity)) { return; + } - enchanting = null; + setEnchanting(null); entity.removeEnchantedBy(this); if (isBestowed()) { unanimateBestow(); @@ -3294,21 +3320,25 @@ public class Card extends GameEntity implements Comparable, IIdentifiable setDirectlyPhasedOut(direct); } - for (final Card eq : getEquippedBy()) { - if (eq.isPhasedOut() == phasingIn) { - eq.phase(false); + if (isEquipped()) { + for (final Card eq : getEquippedBy(false)) { + if (eq.isPhasedOut() == phasingIn) { + eq.phase(false); + } } } - - for (final Card f : getFortifiedBy()) { - if (f.isPhasedOut() == phasingIn) { - f.phase(false); + if (isFortified()) { + for (final Card f : getFortifiedBy(false)) { + if (f.isPhasedOut() == phasingIn) { + f.phase(false); + } } } - - for (final Card aura : getEnchantedBy()) { - if (aura.isPhasedOut() == phasingIn) { - aura.phase(false); + if (isEnchanted()) { + for (final Card aura : getEnchantedBy(false)) { + if (aura.isPhasedOut() == phasingIn) { + aura.phase(false); + } } } @@ -3574,11 +3604,11 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } } else if (property.equals("ChosenCard")) { - if (!source.getChosenCard().contains(this)) { + if (!source.hasChosenCard(this)) { return false; } } else if (property.equals("nonChosenCard")) { - if (source.getChosenCard().contains(this)) { + if (source.hasChosenCard(this)) { return false; } } @@ -3601,15 +3631,15 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (property.startsWith("non") == CardUtil.getColors(this).isMonoColor()) return false; } else if (property.equals("ChosenColor")) { - if (source.getChosenColors().isEmpty() || !CardUtil.getColors(this).hasAnyColor(MagicColor.fromName(source.getChosenColors().get(0)))) + if (!source.hasChosenColor() || !CardUtil.getColors(this).hasAnyColor(MagicColor.fromName(source.getChosenColor()))) return false; } else if (property.equals("AllChosenColors")) { - if (source.getChosenColors().isEmpty() || !CardUtil.getColors(this).hasAllColors(ColorSet.fromNames(source.getChosenColors()).getColor())) + if (!source.hasChosenColor() || !CardUtil.getColors(this).hasAllColors(ColorSet.fromNames(source.getChosenColors()).getColor())) return false; } else if (property.equals("AnyChosenColor")) { - if (source.getChosenColors().isEmpty() || !CardUtil.getColors(this).hasAnyColor(ColorSet.fromNames(source.getChosenColors()).getColor())) + if (!source.hasChosenColor() || !CardUtil.getColors(this).hasAnyColor(ColorSet.fromNames(source.getChosenColors()).getColor())) return false; } else if (property.equals("DoubleFaced")) { @@ -3801,7 +3831,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable return false; } } else if (property.startsWith("AttachedBy")) { - if (!equippedBy.contains(source) && !getEnchantedBy().contains(source) && !getFortifiedBy().contains(source)) { + if (!isEquippedBy(source) && !isEnchantedBy(source) && !isFortifiedBy(source)) { return false; } } else if (property.equals("Attached")) { @@ -3844,9 +3874,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable if (enchantedPlayer == null) { return false; } - - List enchanting = enchantedPlayer.getEnchantedBy(); - for (Card c : enchanting) { + for (Card c : enchantedPlayer.getEnchantedBy(false)) { if (getName().equals(c.getName())) { return false; } @@ -3857,14 +3885,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.startsWith("EnchantedBy")) { if (property.equals("EnchantedBy")) { - if (!getEnchantedBy().contains(source) && !equals(source.getEnchanting())) { + if (!isEnchantedBy(source) && !equals(source.getEnchanting())) { return false; } } else { final String restriction = property.split("EnchantedBy ")[1]; if (restriction.equals("Imprinted")) { for (final Card card : source.getImprinted()) { - if (!getEnchantedBy().contains(card) && !equals(card.getEnchanting())) { + if (!isEnchantedBy(card) && !equals(card.getEnchanting())) { return false; } } @@ -3873,14 +3901,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (!getEnchantedBy().contains(c) && !equals(c.getEnchanting())) { + if (!isEnchantedBy(c) && !equals(c.getEnchanting())) { return false; } } } } } else { // EnchantedBy Aura.Other - for (final Card aura : getEnchantedBy()){ + for (final Card aura : getEnchantedBy(false)){ if (aura.isValid(restriction, sourceController, source)) { return true; } @@ -3894,14 +3922,14 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (getEnchantedBy().contains(c)) { + if (isEnchantedBy(c)) { return false; } } } } } else { - if (getEnchantedBy().contains(source)) { + if (isEnchantedBy(source)) { return false; } } @@ -3951,7 +3979,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable final SpellAbility saTargeting = sa.getSATargetingCard(); if (saTargeting != null) { for (final Card c : saTargeting.getTargets().getTargetCards()) { - if (!equippedBy.contains(c)) { + if (!isEquippedBy(c)) { return false; } } @@ -3959,16 +3987,16 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } } else if (property.substring(10).equals("Enchanted")) { if (source.getEnchantingCard() == null || - !equippedBy.contains(source.getEnchantingCard())) { + !isEquippedBy(source.getEnchantingCard())) { return false; } } else { - if (!equippedBy.contains(source)) { + if (!isEquippedBy(source)) { return false; } } } else if (property.startsWith("FortifiedBy")) { - if (!fortifiedBy.contains(source)) { + if (!isFortifiedBy(source)) { return false; } } else if (property.startsWith("CanBeEquippedBy")) { @@ -6081,7 +6109,7 @@ public class Card extends GameEntity implements Comparable, IIdentifiable } if (hasProtectionFrom(aura, checkSBA) - || (hasKeyword("CARDNAME can't be enchanted in the future.") && !getEnchantedBy().contains(aura)) + || (hasKeyword("CARDNAME can't be enchanted in the future.") && !isEnchantedBy(aura)) || (hasKeyword("CARDNAME can't be enchanted.") && !aura.getName().equals("Anti-Magic Aura") && !(aura.getName().equals("Consecrate Land") && aura.isInZone(ZoneType.Battlefield))) || ((tgt != null) && !isValid(tgt.getValidTgts(), aura.getController(), aura))) { diff --git a/forge-game/src/main/java/forge/game/card/CardFactory.java b/forge-game/src/main/java/forge/game/card/CardFactory.java index 1a8c186af46..e555ba3d4ca 100644 --- a/forge-game/src/main/java/forge/game/card/CardFactory.java +++ b/forge-game/src/main/java/forge/game/card/CardFactory.java @@ -94,10 +94,10 @@ public class CardFactory { // I'm not sure if we really should be copying enchant/equip stuff over. out.setEquipping(in.getEquipping()); - out.setEquippedBy(in.getEquippedBy()); + out.setEquippedBy(in.getEquippedBy(false)); out.setFortifying(in.getFortifying()); - out.setFortifiedBy(in.getFortifiedBy()); - out.setEnchantedBy(in.getEnchantedBy()); + out.setFortifiedBy(in.getFortifiedBy(false)); + out.setEnchantedBy(in.getEnchantedBy(false)); out.setEnchanting(in.getEnchanting()); out.setClones(in.getClones()); out.setZone(in.getZone()); diff --git a/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java b/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java index 0ed389c7e4d..bdf0b944354 100644 --- a/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardFactoryUtil.java @@ -1159,7 +1159,7 @@ public class CardFactoryUtil { ZoneType sourceZone = sq[0].contains("ChromaInGrave") ? ZoneType.Graveyard : ZoneType.Battlefield; String colorName = sq[1]; if (colorName.contains("Chosen")) { - colorName = MagicColor.toShortString(c.getChosenColors().get(0)); + colorName = MagicColor.toShortString(c.getChosenColor()); } final List cards; if (sq[0].contains("ChromaSource")) { // Runs Chroma for passed in Source card diff --git a/forge-game/src/main/java/forge/game/card/CardUtil.java b/forge-game/src/main/java/forge/game/card/CardUtil.java index 2520b411d0d..ac60a4f242f 100644 --- a/forge-game/src/main/java/forge/game/card/CardUtil.java +++ b/forge-game/src/main/java/forge/game/card/CardUtil.java @@ -243,11 +243,11 @@ public final class CardUtil { newCopy.setReceivedDamageFromThisTurn(in.getReceivedDamageFromThisTurn()); newCopy.getDamageHistory().setCreatureGotBlockedThisTurn(in.getDamageHistory().getCreatureGotBlockedThisTurn()); newCopy.setEnchanting(in.getEnchanting()); - newCopy.setEnchantedBy(new ArrayList (in.getEnchantedBy())); + newCopy.setEnchantedBy(in.getEnchantedBy(false)); newCopy.setEquipping(in.getEquipping()); - newCopy.setEquippedBy(new ArrayList (in.getEquippedBy())); + newCopy.setEquippedBy(in.getEquippedBy(false)); newCopy.setFortifying(in.getFortifying()); - newCopy.setFortifiedBy(new ArrayList (in.getFortifiedBy())); + newCopy.setFortifiedBy(in.getFortifiedBy(false)); newCopy.setClones(in.getClones()); newCopy.setHaunting(in.getHaunting()); for (final Card haunter : in.getHauntedBy()) { diff --git a/forge-game/src/main/java/forge/game/card/CardView.java b/forge-game/src/main/java/forge/game/card/CardView.java index 2622483948b..3ff1bb9c35e 100644 --- a/forge-game/src/main/java/forge/game/card/CardView.java +++ b/forge-game/src/main/java/forge/game/card/CardView.java @@ -222,7 +222,7 @@ public class CardView extends GameEntityView { return get(CardProp.EquippedBy); } void updateEquippedBy(Card c) { - set(CardProp.EquippedBy, CardView.getCollection(c.getEquippedBy())); + set(CardProp.EquippedBy, CardView.getCollection(c.getEquippedBy(false))); } public boolean isEquipped() { @@ -251,17 +251,6 @@ public class CardView extends GameEntityView { return null; } - public Iterable getEnchantedBy() { - return get(CardProp.EnchantedBy); - } - void updateEnchantedBy(Card c) { - set(CardProp.EnchantedBy, CardView.getCollection(c.getEnchantedBy())); - } - - public boolean isEnchanted() { - return getEnchantedBy() != null; - } - public CardView getFortifying() { return get(CardProp.Fortifying); } @@ -273,7 +262,7 @@ public class CardView extends GameEntityView { return get(CardProp.FortifiedBy); } void updateFortifiedBy(Card c) { - set(CardProp.FortifiedBy, CardView.getCollection(c.getFortifiedBy())); + set(CardProp.FortifiedBy, CardView.getCollection(c.getFortifiedBy(false))); } public boolean isFortified() { @@ -624,4 +613,9 @@ public class CardView extends GameEntityView { protected CardProp preventNextDamageProp() { return CardProp.PreventNextDamage; } + + @Override + protected CardProp enchantedByProp() { + return CardProp.EnchantedBy; + } } diff --git a/forge-game/src/main/java/forge/game/cost/CostUnattach.java b/forge-game/src/main/java/forge/game/cost/CostUnattach.java index 7f00c0ff789..2bc7661e2d6 100644 --- a/forge-game/src/main/java/forge/game/cost/CostUnattach.java +++ b/forge-game/src/main/java/forge/game/cost/CostUnattach.java @@ -77,8 +77,7 @@ public class CostUnattach extends CostPartWithList { return true; } } else { - List equipped = source.getEquippedBy(); - if (CardLists.getValidCards(equipped, type, activator, source).size() > 0) { + if (CardLists.getValidCards(source.getEquippedBy(false), type, activator, source).size() > 0) { return true; } } @@ -97,7 +96,7 @@ public class CostUnattach extends CostPartWithList { return originalEquipment; } } else { - List attachees = CardLists.getValidCards(source.getEquippedBy(), this.getType(), activator, source); + List attachees = CardLists.getValidCards(source.getEquippedBy(false), this.getType(), activator, source); if (attachees.size() > 0) { // Just pick the first one, although maybe give a dialog return attachees.get(0); diff --git a/forge-game/src/main/java/forge/game/player/Player.java b/forge-game/src/main/java/forge/game/player/Player.java index 2410625bcf4..3a6f614bb85 100644 --- a/forge-game/src/main/java/forge/game/player/Player.java +++ b/forge-game/src/main/java/forge/game/player/Player.java @@ -2074,7 +2074,7 @@ public class Player extends GameEntity implements Comparable, IIdentifia return false; } } else if (property.startsWith("EnchantedBy")) { - if (!getEnchantedBy().contains(source)) { + if (!isEnchantedBy(source)) { return false; } } else if (property.startsWith("Chosen")) { diff --git a/forge-game/src/main/java/forge/game/player/PlayerView.java b/forge-game/src/main/java/forge/game/player/PlayerView.java index 1f8914e43a0..c0d19ed3705 100644 --- a/forge-game/src/main/java/forge/game/player/PlayerView.java +++ b/forge-game/src/main/java/forge/game/player/PlayerView.java @@ -204,4 +204,9 @@ public class PlayerView extends GameEntityView { protected PlayerProp preventNextDamageProp() { return PlayerProp.PreventNextDamage; } + + @Override + protected PlayerProp enchantedByProp() { + return PlayerProp.EnchantedBy; + } } \ No newline at end of file diff --git a/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java b/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java index 2eefd5983ce..a156da8a7ac 100644 --- a/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java +++ b/forge-game/src/main/java/forge/game/replacement/ReplacementHandler.java @@ -233,8 +233,8 @@ public class ReplacementHandler implements IGameStateObject { // Replaced mana type final Card repHost = replacementEffect.getHostCard(); String repType = repHost.getSVar(mapParams.get("ManaReplacement")); - if (repType.contains("Chosen") && !repHost.getChosenColors().isEmpty()) { - repType = repType.replace("Chosen", MagicColor.toShortString(repHost.getChosenColors().get(0))); + if (repType.contains("Chosen") && repHost.hasChosenColor()) { + repType = repType.replace("Chosen", MagicColor.toShortString(repHost.getChosenColor())); } manaAb.getManaPart().setManaReplaceType(repType); manaAb.getManaPart().produceMana(rep, player1, manaAb); diff --git a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java index 3cf309eb4e5..8fe0e97503f 100644 --- a/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java +++ b/forge-game/src/main/java/forge/game/spellability/AbilityManaPart.java @@ -29,11 +29,11 @@ import forge.game.replacement.ReplacementHandler; import forge.game.replacement.ReplacementLayer; import forge.game.replacement.ReplacementResult; import forge.game.trigger.TriggerType; + import org.apache.commons.lang3.StringUtils; import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -341,9 +341,8 @@ public class AbilityManaPart implements java.io.Serializable { */ public final String mana() { if (this.getOrigProduced().contains("Chosen")) { - if (this.getSourceCard() != null && !this.getSourceCard().getChosenColors().isEmpty()) { - return MagicColor.toShortString(this.getSourceCard() - .getChosenColors().get(0)); + if (this.getSourceCard() != null && this.getSourceCard().hasChosenColor()) { + return MagicColor.toShortString(this.getSourceCard().getChosenColor()); } } return this.getOrigProduced(); @@ -473,8 +472,7 @@ public class AbilityManaPart implements java.io.Serializable { } if (this.getOrigProduced().contains("Chosen") && sourceCard != null ) { - List chosenCol = this.getSourceCard().getChosenColors(); - if ( !chosenCol.isEmpty() && MagicColor.toShortString(chosenCol.get(0)).contains(s)) { + if (this.getSourceCard().hasChosenColor() && MagicColor.toShortString(this.getSourceCard().getChosenColor()).contains(s)) { return true; } } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java index f9cff06bb4c..3822d3b694b 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityCondition.java @@ -275,7 +275,7 @@ public class SpellAbilityCondition extends SpellAbilityVariables { } if (this.getColorToCheck() != null) { - if (!sa.getHostCard().getChosenColors().contains(this.getColorToCheck())) { + if (!sa.getHostCard().hasChosenColor(this.getColorToCheck())) { return false; } } diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java b/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java index 77475bb9727..fabd33796bd 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbilityRestriction.java @@ -302,7 +302,7 @@ public class SpellAbilityRestriction extends SpellAbilityVariables { } if (this.getColorToCheck() != null) { - if (!sa.getHostCard().getChosenColors().contains(this.getColorToCheck())) { + if (!sa.getHostCard().hasChosenColor(this.getColorToCheck())) { return false; } } diff --git a/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java b/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java index 9fb77feb457..99ddec5e3c8 100644 --- a/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java +++ b/forge-game/src/main/java/forge/game/staticability/StaticAbilityContinuous.java @@ -17,6 +17,7 @@ */ package forge.game.staticability; +import com.google.common.collect.Iterables; import com.google.common.collect.Lists; import forge.GameCommand; @@ -159,7 +160,7 @@ public class StaticAbilityContinuous { if (params.containsKey("AddKeyword")) { addKeywords = params.get("AddKeyword").split(" & "); - final List chosencolors = hostCard.getChosenColors(); + final Iterable chosencolors = hostCard.getChosenColors(); for (final String color : chosencolors) { for (int w = 0; w < addKeywords.length; w++) { addKeywords[w] = addKeywords[w].replaceAll("ChosenColor", color.substring(0, 1).toUpperCase().concat(color.substring(1, color.length()))); @@ -381,8 +382,8 @@ public class StaticAbilityContinuous { if (changeColorWordsTo != null) { final byte color; if (changeColorWordsTo.equals("ChosenColor")) { - if (hostCard.getChosenColors().size() > 0) { - color = MagicColor.fromName(hostCard.getChosenColors().get(0)); + if (hostCard.hasChosenColor()) { + color = MagicColor.fromName(Iterables.getFirst(hostCard.getChosenColors(), null)); } else { color = 0; } diff --git a/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java b/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java index aa2b943d5eb..a01cbf4a2dc 100644 --- a/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java +++ b/forge-game/src/main/java/forge/game/trigger/TriggerTapsForMana.java @@ -22,8 +22,6 @@ import forge.game.card.Card; import forge.game.player.Player; import forge.game.spellability.SpellAbility; -import java.util.List; - /** *

* Trigger_TapsForMana class. @@ -93,8 +91,7 @@ public class TriggerTapsForMana extends Trigger { } String produced = (String) prod; if ("ChosenColor".equals(mapParams.get("Produced"))) { - List colors = this.getHostCard().getChosenColors(); - if (colors.isEmpty() || !produced.contains(MagicColor.toShortString(colors.get(0)))) { + if (!this.getHostCard().hasChosenColor() || !produced.contains(MagicColor.toShortString(this.getHostCard().getChosenColor()))) { return false; } } diff --git a/forge-game/src/main/java/forge/trackable/TrackableObject.java b/forge-game/src/main/java/forge/trackable/TrackableObject.java index 09e44ea18b7..64172b4d55a 100644 --- a/forge-game/src/main/java/forge/trackable/TrackableObject.java +++ b/forge-game/src/main/java/forge/trackable/TrackableObject.java @@ -45,4 +45,12 @@ public abstract class TrackableObject> implements IIdentifiabl protected void flagAsChanged(E key) { changedProps.add(key); } + + public void serialize() { + //TODO + } + + public void deserialize() { + //TODO + } } diff --git a/forge-game/src/main/java/forge/trackable/TrackableProperty.java b/forge-game/src/main/java/forge/trackable/TrackableProperty.java index 8bdd3cd7e9c..8f96851e777 100644 --- a/forge-game/src/main/java/forge/trackable/TrackableProperty.java +++ b/forge-game/src/main/java/forge/trackable/TrackableProperty.java @@ -74,6 +74,7 @@ public class TrackableProperty { HasUnlimitedHandSize, NumDrawnThisTurn, PreventNextDamage, + EnchantedBy, Keywords, CommanderInfo, Ante, diff --git a/forge-gui/src/main/java/forge/view/LocalGameView.java b/forge-gui/src/main/java/forge/view/LocalGameView.java index 96d212177d8..8c640d6031d 100644 --- a/forge-gui/src/main/java/forge/view/LocalGameView.java +++ b/forge-gui/src/main/java/forge/view/LocalGameView.java @@ -478,11 +478,11 @@ public abstract class LocalGameView implements IGameView { view.setBlocking(combat != null && combat.isBlocking(c)); view.setChosenPlayer(getPlayerView(c.getChosenPlayer(), false)); view.setEquipping(getCardView(c.getEquipping(), false)); - view.setEquippedBy(getCardViews(c.getEquippedBy(), false)); + view.setEquippedBy(getCardViews(c.getEquippedBy(false), false)); view.setEnchantingCard(getCardView(c.getEnchantingCard(), false)); view.setEnchantingPlayer(getPlayerView(c.getEnchantingPlayer(), false)); - view.setEnchantedBy(getCardViews(c.getEnchantedBy(), false)); - view.setFortifiedBy(getCardViews(c.getFortifiedBy(), false)); + view.setEnchantedBy(getCardViews(c.getEnchantedBy(false), false)); + view.setFortifiedBy(getCardViews(c.getFortifiedBy(false), false)); view.setGainControlTargets(getCardViews(c.getGainControlTargets(), false)); view.setCloneOrigin(getCardView(c.getCloneOrigin(), false)); view.setImprinted(getCardViews(c.getImprinted(), false)); diff --git a/forge-gui/src/main/java/forge/view/ViewUtil.java b/forge-gui/src/main/java/forge/view/ViewUtil.java index 599bfe7692b..d4551c42ab2 100644 --- a/forge-gui/src/main/java/forge/view/ViewUtil.java +++ b/forge-gui/src/main/java/forge/view/ViewUtil.java @@ -55,7 +55,7 @@ public final class ViewUtil { view.setRegenerationShields(c.getShieldCount()); view.setPreventNextDamage(c.getPreventNextDamageTotalShields()); view.setChosenType(c.getChosenType()); - view.setChosenColors(c.getChosenColors()); + view.setChosenColors(Lists.newArrayList(c.getChosenColors())); view.setNamedCard(c.getNamedCard()); if (c.isSplitCard()) {