diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index 43a7e40e862..ac274b8a5dd 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -17,6 +17,7 @@ import forge.game.card.CardLists; import forge.game.card.CardUtil; import forge.game.cost.Cost; import forge.game.cost.CostPayment; +import forge.game.mana.Mana; import forge.game.mana.ManaCostBeingPaid; import forge.game.mana.ManaPool; import forge.game.player.Player; @@ -31,6 +32,7 @@ import forge.util.maps.EnumMapOfLists; import forge.util.maps.MapOfLists; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.Pair; import java.util.*; import java.util.Map.Entry; @@ -96,7 +98,19 @@ public class ComputerUtilMana { Collections.sort(unpaidShards); // most difficult shards must come first for (ManaCostShard part : unpaidShards) { if (part != ManaCostShard.X) { - manapool.payManaFromPool(sa, cost, part); + if (cost.isPaid()) { + continue; + } + + // get a mana of this type from floating, bail if none available + final Mana mana = getMana(ai, part, sa, cost.getSourceRestriction()); + if (mana == null) { + continue; // no matching mana in the pool + } + else { + if ( ai.getManaPool().tryPayCostWithMana(sa, cost, mana) && !test) + sa.getManaPaid().add(mana); + } } } @@ -249,6 +263,97 @@ public class ComputerUtilMana { return true; } // payManaCost() + /** + *
+ * getManaFrom. + *
+ * + * @param saBeingPaidFor + * a {@link forge.game.spellability.SpellAbility} object. + * @return a {@link forge.game.mana.Mana} object. + */ + private static Mana getMana(final Player ai, final ManaCostShard shard, final SpellAbility saBeingPaidFor, String restriction) { + final List- * getManaFrom. - *
- * - * @param saBeingPaidFor - * a {@link forge.game.spellability.SpellAbility} object. - * @return a {@link forge.game.mana.Mana} object. - */ - private Mana getMana(final ManaCostShard shard, final SpellAbility saBeingPaidFor, String restriction) { - final List* removeManaFrom. @@ -248,22 +150,7 @@ public class ManaPool { owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Removed, mana)); } } - - public final void payManaFromPool(final SpellAbility saBeingPaidFor, final ManaCostBeingPaid manaCost, final ManaCostShard manaShard) { - if (manaCost.isPaid()) { - return; - } - - // get a mana of this type from floating, bail if none available - final Mana mana = this.getMana(manaShard, saBeingPaidFor, manaCost.getSourceRestriction()); - if (mana == null) { - return; // no matching mana in the pool - } - else { - tryPayCostWithMana(saBeingPaidFor, manaCost, mana); - } - } - + /** *
* subtractManaFromAbility.
@@ -283,7 +170,8 @@ public class ManaPool {
paidAbs.add(saPayment); // assumes some part on the mana produced by the ability will get used
for (final Mana mana : abManaPart.getLastManaProduced()) {
- tryPayCostWithMana(saPaidFor, manaCost, mana);
+ if( tryPayCostWithMana(saPaidFor, manaCost, mana) )
+ saPaidFor.getManaPaid().add(mana);
}
}
@@ -306,7 +194,10 @@ public class ManaPool {
}
- return manaFound != null && tryPayCostWithMana(saPaidFor, manaCost, manaFound);
+ boolean result = manaFound != null && tryPayCostWithMana(saPaidFor, manaCost, manaFound);
+ if(result)
+ saPaidFor.getManaPaid().add(manaFound);
+ return result;
}
@@ -329,7 +220,6 @@ public class ManaPool {
mana.getManaAbility().createETBCounters(sa.getHostCard());
}
}
- sa.getManaPaid().add(mana);
return true;
}
@@ -480,4 +370,9 @@ public class ManaPool {
}
return shard.canBePaidWithManaOfColor((byte)0);
}
+
+ @Override
+ public Iterator