diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index ab2d750c43e..c307662cfa6 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -3,6 +3,7 @@ package forge.ai; import com.google.common.base.Predicate; import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.ListMultimap; +import com.google.common.collect.Lists; import com.google.common.collect.Multimap; import forge.card.ColorSet; @@ -306,6 +307,9 @@ public class ComputerUtilMana { private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, boolean checkPlayable) { adjustManaCostToAvoidNegEffects(cost, sa.getHostCard(), ai); List manaSpentToPay = test ? new ArrayList() : sa.getPayingMana(); + + List paymentList = Lists.newArrayList(); + if (payManaCostFromPool(cost, sa, ai, test, manaSpentToPay)) { return true; // paid all from floating mana } @@ -358,6 +362,7 @@ public class ComputerUtilMana { } continue; } + paymentList.add(saPayment); setExpressColorChoice(sa, ai, cost, toPay, saPayment); @@ -420,6 +425,7 @@ public class ComputerUtilMana { if (!cost.isPaid()) { refundMana(manaSpentToPay, ai, sa); if (test) { + resetPayment(paymentList); return false; } else { @@ -428,18 +434,28 @@ public class ComputerUtilMana { } } - if (test) { - refundMana(manaSpentToPay, ai, sa); - } // Note: manaSpentToPay shouldn't be cleared here, since it needs to remain // on the SpellAbility in order for effects that check mana spent cost to work. sa.getHostCard().setColorsPaid(cost.getColorsPaid()); // if (sa instanceof Spell_Permanent) // should probably add this sa.getHostCard().setSunburstValue(cost.getSunburst()); + + if (test) { + refundMana(manaSpentToPay, ai, sa); + resetPayment(paymentList); + } + return true; } // payManaCost() + private static void resetPayment(List payments) { + for(SpellAbility sa : payments) { + sa.getManaPart().clearExpressChoice(); + } + } + + /** * Creates a mapping between the required mana shards and the available spell abilities to pay for them */ @@ -683,6 +699,8 @@ public class ComputerUtilMana { } else if (sourceCard.isTapped()) { return false; + } else if (ma.getRestrictions() != null && ma.getRestrictions().isInstantSpeed()) { + return false; } } @@ -1246,6 +1264,10 @@ public class ComputerUtilMana { continue; } + if (a.getRestrictions() != null && a.getRestrictions().isInstantSpeed()) { + continue; + } + if (!res.contains(a)) { if (cost.isReusuableResource()) { res.add(0, a);