From b69228e28bcdc77133fc13d4d54888b5d81c907f Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Tue, 18 Feb 2014 01:12:37 +0000 Subject: [PATCH] I believe this would break ai's mana payment --- .../main/java/forge/ai/ComputerUtilMana.java | 45 ++++++++++++------- .../java/forge/game/cost/CostPartMana.java | 2 +- .../main/java/forge/game/mana/ManaPool.java | 27 +---------- .../forge/game/spellability/SpellAbility.java | 4 ++ .../forge/gui/input/InputPayManaSimple.java | 2 - .../main/java/forge/gui/player/HumanPlay.java | 2 +- 6 files changed, 36 insertions(+), 46 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index f994de0f8db..814d998b9d4 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -46,11 +46,11 @@ public class ComputerUtilMana { public static boolean canPayManaCost(ManaCostBeingPaid cost, final SpellAbility sa, final Player ai) { cost = new ManaCostBeingPaid(cost); //check copy of cost so it doesn't modify the exist cost being paid - return payManaCost(cost, sa, ai, true, 0, true, true); + return payManaCost(cost, sa, ai, true, 0, true); } public static boolean payManaCost(ManaCostBeingPaid cost, final SpellAbility sa, final Player ai) { - return payManaCost(cost, sa, ai, false, 0, true, false); + return payManaCost(cost, sa, ai, false, 0, true); } public static boolean canPayManaCost(final SpellAbility sa, final Player ai, final int extraMana) { @@ -67,6 +67,17 @@ public class ComputerUtilMana { return payManaCost(sa, ai, false, 0, true); } + private static void refundMana(List manaSpent, Player ai, SpellAbility sa) { + if (sa.getHostCard() != null) { + sa.getHostCard().setCanCounter(true); + } + for (final Mana m : manaSpent) { + ai.getManaPool().addMana(m); + } + manaSpent.clear(); + } + + /** *

* payManaCost. @@ -87,12 +98,13 @@ public class ComputerUtilMana { */ private static boolean payManaCost(final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) { ManaCostBeingPaid cost = ComputerUtilMana.calculateManaCost(sa, test, extraMana); - return payManaCost(cost, sa, ai, test, extraMana, checkPlayable, true); + return payManaCost(cost, sa, ai, test, extraMana, checkPlayable); } - private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable, boolean clearManaPaid) { + private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable) { adjustManaCostToAvoidNegEffects(cost, sa.getHostCard(), ai); - + List manaSpentToPay = test ? new ArrayList() : sa.getPayingMana(); + final ManaPool manapool = ai.getManaPool(); List unpaidShards = cost.getUnpaidShards(); Collections.sort(unpaidShards); // most difficult shards must come first @@ -108,17 +120,18 @@ public class ComputerUtilMana { continue; // no matching mana in the pool } else { - if ( ai.getManaPool().tryPayCostWithMana(sa, cost, mana) && !test) - sa.getPayingMana().add(mana); + if (ai.getManaPool().tryPayCostWithMana(sa, cost, mana)) { + manaSpentToPay.add(mana); + } } } } if (cost.isPaid()) { // refund any mana taken from mana pool when test - if (clearManaPaid) { - manapool.clearManaPaid(sa, test); - } + if(test) + refundMana(manaSpentToPay, ai, sa); + handleOfferingsAI(sa, test, cost.isPaid()); return true; } @@ -126,9 +139,8 @@ public class ComputerUtilMana { // arrange all mana abilities by color produced. final Multimap manaAbilityMap = ComputerUtilMana.groupSourcesByManaColor(ai, checkPlayable); if (manaAbilityMap.isEmpty()) { - if (clearManaPaid) { - manapool.clearManaPaid(sa, test); - } + refundMana(manaSpentToPay, ai, sa); + handleOfferingsAI(sa, test, cost.isPaid()); return false; } @@ -236,9 +248,6 @@ public class ComputerUtilMana { } } - if (clearManaPaid) { - manapool.clearManaPaid(sa, test); - } handleOfferingsAI(sa, test, cost.isPaid()); // if (DEBUG_MANA_PAYMENT) { @@ -248,6 +257,7 @@ public class ComputerUtilMana { // } if (!cost.isPaid()) { + refundMana(manaSpentToPay, ai, sa); if (test) { return false; } @@ -257,6 +267,9 @@ public class ComputerUtilMana { } } + if (test) + refundMana(manaSpentToPay, ai, sa); + sa.getHostCard().setColorsPaid(cost.getColorsPaid()); // if (sa instanceof Spell_Permanent) // should probably add this sa.getHostCard().setSunburstValue(cost.getSunburst()); diff --git a/forge-game/src/main/java/forge/game/cost/CostPartMana.java b/forge-game/src/main/java/forge/game/cost/CostPartMana.java index 4638560519d..665535c3419 100644 --- a/forge-game/src/main/java/forge/game/cost/CostPartMana.java +++ b/forge-game/src/main/java/forge/game/cost/CostPartMana.java @@ -125,7 +125,7 @@ public class CostPartMana extends CostPart { @Override public boolean payAsDecided(Player payer, PaymentDecision pd, SpellAbility sa) { // TODO Auto-generated method stub - payer.getManaPool().clearManaPaid(sa, false); + sa.clearManaPaid(); // decision not used here, the whole payment is interactive! return payer.getController().payManaCost(this, sa); diff --git a/forge-game/src/main/java/forge/game/mana/ManaPool.java b/forge-game/src/main/java/forge/game/mana/ManaPool.java index fd69bff05ed..5eb8e3f329c 100644 --- a/forge-game/src/main/java/forge/game/mana/ManaPool.java +++ b/forge-game/src/main/java/forge/game/mana/ManaPool.java @@ -73,7 +73,7 @@ public class ManaPool implements Iterable { return ofColor == null ? 0 : ofColor.size(); } - private void addMana(final Mana mana) { + public void addMana(final Mana mana) { floatingMana.put(mana.getColor(), mana); owner.getGame().fireEvent(new GameEventManaPool(owner, EventValueChangeType.Added, mana)); } @@ -233,31 +233,6 @@ public class ManaPool implements Iterable { return floatingMana.values().size(); } - /** - *

- * clearPay. - *

- * - * @param ability - * a {@link forge.game.spellability.SpellAbility} object. - * @param refund - * a boolean. - */ - public final void clearManaPaid(final SpellAbility ability, final boolean refund) { - final List manaPaid = ability.getPayingMana(); - ability.getPayingManaAbilities().clear(); - // move non-undoable paying mana back to floating - if (refund) { - if (ability.getHostCard() != null) { - ability.getHostCard().setCanCounter(true); - } - for (final Mana m : manaPaid) { - this.addMana(m); - } - } - manaPaid.clear(); - } - //Account for mana part of ability when undoing it public boolean accountFor(final AbilityManaPart ma) { if (ma == null) { diff --git a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java index 8e6143e2151..92f363762e5 100644 --- a/forge-game/src/main/java/forge/game/spellability/SpellAbility.java +++ b/forge-game/src/main/java/forge/game/spellability/SpellAbility.java @@ -480,6 +480,10 @@ public abstract class SpellAbility extends CardTraitBase implements ISpellAbilit return this.payingMana; } + public final void clearManaPaid() { + payingMana.clear(); + } + /** *

* getPayingManaAbilities. diff --git a/forge-gui/src/main/java/forge/gui/input/InputPayManaSimple.java b/forge-gui/src/main/java/forge/gui/input/InputPayManaSimple.java index 8c1776c19b9..98a357ebcd0 100644 --- a/forge-gui/src/main/java/forge/gui/input/InputPayManaSimple.java +++ b/forge-gui/src/main/java/forge/gui/input/InputPayManaSimple.java @@ -82,8 +82,6 @@ public class InputPayManaSimple extends InputPayMana { player.payLife(this.phyLifeToLose, this.originalCard); } if (!this.saPaidFor.getHostCard().isCopiedSpell()) { - player.getManaPool().clearManaPaid(this.saPaidFor, false); - if (this.saPaidFor.isSpell()) { this.saPaidFor.setHostCard(game.getAction().moveToStack(this.originalCard)); } diff --git a/forge-gui/src/main/java/forge/gui/player/HumanPlay.java b/forge-gui/src/main/java/forge/gui/player/HumanPlay.java index 3111ce69b36..231d2c93d91 100644 --- a/forge-gui/src/main/java/forge/gui/player/HumanPlay.java +++ b/forge-gui/src/main/java/forge/gui/player/HumanPlay.java @@ -627,7 +627,7 @@ public class HumanPlay { prompt = source + "\n" + promptCurrent; } - p.getManaPool().clearManaPaid(sourceAbility, false); + sourceAbility.clearManaPaid(); boolean paid = p.getController().payManaCost(cost.getCostMana(), sourceAbility); if (!paid) { p.getManaPool().refundManaPaid(sourceAbility);