diff --git a/forge-game/src/main/java/forge/game/cost/Cost.java b/forge-game/src/main/java/forge/game/cost/Cost.java index ce00e0acdc3..f7ca0f0be1b 100644 --- a/forge-game/src/main/java/forge/game/cost/Cost.java +++ b/forge-game/src/main/java/forge/game/cost/Cost.java @@ -134,6 +134,10 @@ public class Cost { return manapart == null ? ManaCost.ZERO : manapart.getManaToPay(); } + private Cost() { + + } + private Cost(int genericMana) { costParts.add(new CostPartMana(ManaCost.get(genericMana), null)); } @@ -447,12 +451,21 @@ public class Cost { return splitStr; } + public final Cost copy() { + Cost toRet = new Cost(); + toRet.isAbility = this.isAbility; + for (CostPart cp : this.costParts) { + toRet.costParts.add(cp.copy()); + } + return toRet; + } + public final Cost copyWithNoMana() { Cost toRet = new Cost(0); toRet.isAbility = this.isAbility; for (CostPart cp : this.costParts) { if (!(cp instanceof CostPartMana)) - toRet.costParts.add(cp); + toRet.costParts.add(cp.copy()); } return toRet; } @@ -773,7 +786,8 @@ public class Cost { } else { costParts.add(0, new CostPartMana(oldManaCost.toManaCost(), r)); } - } else if (part instanceof CostDiscard || part instanceof CostTapType) { + } else if (part instanceof CostDiscard || part instanceof CostTapType || + part instanceof CostAddMana) { boolean alreadyAdded = false; for (final CostPart other : costParts) { if (other.getClass().equals(part.getClass()) && @@ -786,6 +800,8 @@ public class Cost { } else if (part instanceof CostTapType) { CostTapType tappart = (CostTapType)part; costParts.add(new CostTapType(amount, part.getType(), part.getTypeDescription(), !tappart.canTapSource)); + } else if (part instanceof CostAddMana) { + costParts.add(new CostAddMana(amount, part.getType(), part.getTypeDescription())); } toRemove.add(other); alreadyAdded = true; diff --git a/forge-game/src/main/java/forge/game/cost/CostAddMana.java b/forge-game/src/main/java/forge/game/cost/CostAddMana.java index cfb20868e97..53d4603ce57 100644 --- a/forge-game/src/main/java/forge/game/cost/CostAddMana.java +++ b/forge-game/src/main/java/forge/game/cost/CostAddMana.java @@ -70,11 +70,7 @@ public class CostAddMana extends CostPart { @Override public boolean payAsDecided(Player ai, PaymentDecision decision, SpellAbility sa) { Card source = sa.getHostCard(); - - /*ColorSet cid = null; - if (ai.getGame().getRules().hasCommander()) { - cid = ai.getCommander().getRules().getColorIdentity(); - }*/ + List manaProduced = new ArrayList(); final String type = this.getType(); for (int n = 0; n < decision.c; n++) { diff --git a/forge-game/src/main/java/forge/game/cost/CostAdjustment.java b/forge-game/src/main/java/forge/game/cost/CostAdjustment.java index 93eb3e04301..cd417a2b8bb 100644 --- a/forge-game/src/main/java/forge/game/cost/CostAdjustment.java +++ b/forge-game/src/main/java/forge/game/cost/CostAdjustment.java @@ -1,13 +1,12 @@ package forge.game.cost; -import java.util.ArrayList; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; import org.apache.commons.lang3.StringUtils; +import com.google.common.collect.Lists; import com.google.common.collect.Maps; import forge.card.CardStateName; @@ -44,8 +43,7 @@ public class CostAdjustment { return cost; } - // TODO: find better way to copy Cost object - Cost result = new Cost("0", sa.isAbility()).add(cost); + Cost result = cost.copy(); boolean isStateChangeToFaceDown = false; if (sa.isSpell() && ((Spell) sa).isCastFaceDown()) { @@ -60,7 +58,7 @@ public class CostAdjustment { if (!cardsOnBattlefield.contains(host)) { cardsOnBattlefield.add(host); } - final List raiseAbilities = new ArrayList(); + final List raiseAbilities = Lists.newArrayList(); // Sort abilities to apply them in proper order for (Card c : cardsOnBattlefield) { @@ -166,8 +164,8 @@ public class CostAdjustment { if (!cardsOnBattlefield.contains(originalCard)) { cardsOnBattlefield.add(originalCard); } - final List reduceAbilities = new ArrayList(); - final List setAbilities = new ArrayList(); + final List reduceAbilities = Lists.newArrayList(); + final List setAbilities = Lists.newArrayList(); // Sort abilities to apply them in proper order for (Card c : cardsOnBattlefield) { @@ -216,7 +214,7 @@ public class CostAdjustment { if (!delved.isEmpty()) { final Map triggerList = Maps.newEnumMap(ZoneType.class); triggerList.put(ZoneType.Graveyard, delved); - final HashMap runParams = new HashMap(); + final Map runParams = Maps.newHashMap(); runParams.put("Cards", triggerList); runParams.put("Destination", ZoneType.Exile); game.getTriggerHandler().runTrigger(TriggerType.ChangesZoneAll, runParams, false); diff --git a/forge-game/src/main/java/forge/game/cost/CostPart.java b/forge-game/src/main/java/forge/game/cost/CostPart.java index 2da7c8db74d..9bd3b6de2bb 100644 --- a/forge-game/src/main/java/forge/game/cost/CostPart.java +++ b/forge-game/src/main/java/forge/game/cost/CostPart.java @@ -17,7 +17,6 @@ */ package forge.game.cost; - import forge.game.CardTraitBase; import forge.game.ability.AbilityUtils; import forge.game.card.Card; @@ -29,7 +28,7 @@ import org.apache.commons.lang3.StringUtils; /** * The Class CostPart. */ -public abstract class CostPart implements Comparable { +public abstract class CostPart implements Comparable, Cloneable { private String originalAmount; private String amount; private final String originalType, originalTypeDescription; @@ -186,6 +185,16 @@ public abstract class CostPart implements Comparable { public int paymentOrder() { return 5; } + public CostPart copy() { + CostPart clone = null; + try { + clone = (CostPart) clone(); + } catch (final CloneNotSupportedException e) { + System.err.println(e); + } + return clone; + } + @Override public int compareTo(CostPart o) { return this.paymentOrder() - o.paymentOrder();