From c5a791f3613d2c86ed771279cb18cd8755498066 Mon Sep 17 00:00:00 2001 From: Maxmtg Date: Sat, 8 Feb 2014 11:33:17 +0000 Subject: [PATCH] more paths require manapool --- .../main/java/forge/ai/ComputerUtilMana.java | 22 +++++++++---------- .../forge/game/mana/ManaCostBeingPaid.java | 18 ++++++--------- .../java/forge/gui/input/InputPayMana.java | 6 ++--- .../gui/input/InputSelectCardsForConvoke.java | 2 +- 4 files changed, 22 insertions(+), 26 deletions(-) diff --git a/forge-game/src/main/java/forge/ai/ComputerUtilMana.java b/forge-game/src/main/java/forge/ai/ComputerUtilMana.java index 09ec5c05c32..2c1d51573bf 100644 --- a/forge-game/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-game/src/main/java/forge/ai/ComputerUtilMana.java @@ -96,7 +96,7 @@ public class ComputerUtilMana { } private static boolean payManaCost(final ManaCostBeingPaid cost, final SpellAbility sa, final Player ai, final boolean test, final int extraMana, boolean checkPlayable, boolean clearManaPaid) { - adjustManaCostToAvoidNegEffects(cost, sa.getSourceCard()); + adjustManaCostToAvoidNegEffects(cost, sa.getSourceCard(), ai); final ManaPool manapool = ai.getManaPool(); List unpaidShards = cost.getUnpaidShards(); @@ -194,7 +194,7 @@ public class ComputerUtilMana { String manaProduced = toPay.isSnow() ? "S" : GameActionUtil.generatedMana(saPayment); manaProduced = AbilityManaPart.applyManaReplacement(saPayment, manaProduced); //System.out.println(manaProduced); - payMultipleMana(cost, manaProduced); + payMultipleMana(cost, manaProduced, ai); // remove from available lists for (Collection kv : sourcesForShards.values()) { @@ -346,14 +346,14 @@ public class ComputerUtilMana { return null; } - private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card) { + private static void adjustManaCostToAvoidNegEffects(ManaCostBeingPaid cost, final Card card, Player ai) { // Make mana needed to avoid negative effect a mandatory cost for the AI for (String manaPart : card.getSVar("ManaNeededToAvoidNegativeEffect").split(",")) { // convert long color strings to short color strings byte mask = MagicColor.fromName(manaPart); // make mana mandatory for AI - if (!cost.needsColor(mask) && cost.getColorlessManaAmount() > 0) { + if (!cost.needsColor(mask, ai.getManaPool()) && cost.getColorlessManaAmount() > 0) { ManaCostShard shard = ManaCostShard.valueOf(mask); cost.increaseShard(shard, 1); cost.decreaseColorlessMana(1); @@ -390,9 +390,9 @@ public class ComputerUtilMana { choice = abMana.getExpressChoice(); abMana.clearExpressChoice(); byte colorMask = MagicColor.fromName(choice); - if (abMana.canProduce(choice, manaAb) && testCost.isAnyPartPayableWith(colorMask)) { + if (abMana.canProduce(choice, manaAb) && testCost.isAnyPartPayableWith(colorMask, ai.getManaPool())) { choiceString.append(choice); - payMultipleMana(testCost, choice); + payMultipleMana(testCost, choice, ai); continue; } } @@ -400,8 +400,8 @@ public class ComputerUtilMana { if (!testCost.isPaid()) { // Loop over combo colors for (String color : comboColors) { - if (testCost.isAnyPartPayableWith(MagicColor.fromName(color))) { - payMultipleMana(testCost, color); + if (testCost.isAnyPartPayableWith(MagicColor.fromName(color), ai.getManaPool())) { + payMultipleMana(testCost, color, ai); if (nMana != 1) { choiceString.append(" "); } @@ -447,12 +447,12 @@ public class ComputerUtilMana { * a {@link java.lang.String} object. * @return a boolean. */ - private final static String payMultipleMana(ManaCostBeingPaid testCost, String mana) { + private final static String payMultipleMana(ManaCostBeingPaid testCost, String mana, final Player p) { List unused = new ArrayList(4); for (String manaPart : TextUtil.split(mana, ' ')) { if (StringUtils.isNumeric(manaPart)) { for (int i = Integer.parseInt(manaPart); i > 0; i--) { - boolean wasNeeded = testCost.ai_payMana("1"); + boolean wasNeeded = testCost.ai_payMana("1", p.getManaPool()); if (!wasNeeded) { unused.add(Integer.toString(i)); break; @@ -461,7 +461,7 @@ public class ComputerUtilMana { } else { String color = MagicColor.toShortString(manaPart); - boolean wasNeeded = testCost.ai_payMana(color); + boolean wasNeeded = testCost.ai_payMana(color, p.getManaPool()); if (!wasNeeded) { unused.add(color); } diff --git a/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java b/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java index 95b49a2afba..c8c5d6f9550 100644 --- a/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java +++ b/forge-game/src/main/java/forge/game/mana/ManaCostBeingPaid.java @@ -187,7 +187,7 @@ public class ManaCostBeingPaid { // takes a Short Color and returns true if it exists in the mana cost. // Easier for split costs - public final boolean needsColor(final byte colorMask) { + public final boolean needsColor(final byte colorMask, final ManaPool pool) { for (ManaCostShard shard : unpaidShards.keySet()) { if (shard == ManaCostShard.COLORLESS) { continue; @@ -197,7 +197,7 @@ public class ManaCostBeingPaid { return true; } } - else if (shardCanBePaidWithColor(shard, colorMask)) { + else if (pool.canPayForShardWithColor(shard, colorMask)) { return true; } } @@ -205,9 +205,9 @@ public class ManaCostBeingPaid { } // isNeeded(String) still used by the Computer, might have problems activating Snow abilities - public final boolean isAnyPartPayableWith(byte colorMask) { + public final boolean isAnyPartPayableWith(byte colorMask, final ManaPool pool) { for (ManaCostShard shard : unpaidShards.keySet()) { - if (shardCanBePaidWithColor(shard, colorMask)) { + if (pool.canPayForShardWithColor(shard, colorMask)) { return true; } } @@ -264,9 +264,9 @@ public class ManaCostBeingPaid { * a {@link java.lang.String} object. * @return a boolean. */ - public final boolean ai_payMana(final String mana) { + public final boolean ai_payMana(final String mana, final ManaPool pool) { final byte colorMask = MagicColor.fromName(mana); - if (!this.isAnyPartPayableWith(colorMask)) { + if (!this.isAnyPartPayableWith(colorMask, pool)) { //System.out.println("ManaCost : addMana() error, mana not needed - " + mana); return false; //throw new RuntimeException("ManaCost : addMana() error, mana not needed - " + mana); @@ -275,7 +275,7 @@ public class ManaCostBeingPaid { Predicate predCanBePaid = new Predicate() { @Override public boolean apply(ManaCostShard ms) { - return shardCanBePaidWithColor(ms, colorMask); + return pool.canPayForShardWithColor(ms, colorMask); } }; @@ -361,10 +361,6 @@ public class ManaCostBeingPaid { return pool.canPayForShardWithColor(shard, color); } - private boolean shardCanBePaidWithColor(ManaCostShard shard, byte manaColor) { - // add color changing matrix here to support Daxos of Melethis - return shard.canBePaidWithManaOfColor(manaColor); - } public final void combineManaCost(final ManaCost extra) { for (ManaCostShard shard : extra) { diff --git a/forge-gui/src/main/java/forge/gui/input/InputPayMana.java b/forge-gui/src/main/java/forge/gui/input/InputPayMana.java index 310f6346dcb..9d3f622cfcf 100644 --- a/forge-gui/src/main/java/forge/gui/input/InputPayMana.java +++ b/forge-gui/src/main/java/forge/gui/input/InputPayMana.java @@ -107,10 +107,10 @@ public abstract class InputPayMana extends InputSyncronizedBase { byte colorNeeded = 0; for (final byte color : MagicColor.WUBRG) { - if (manaCost.isAnyPartPayableWith(color)) { colorCanUse |= color; } - if (manaCost.needsColor(color)) { colorNeeded |= color; } + if (manaCost.isAnyPartPayableWith(color, player.getManaPool())) { colorCanUse |= color; } + if (manaCost.needsColor(color, player.getManaPool())) { colorNeeded |= color; } } - boolean canUseColorless = manaCost.isAnyPartPayableWith((byte)0); + boolean canUseColorless = manaCost.isAnyPartPayableWith((byte)0, player.getManaPool()); List abilities = new ArrayList(); // you can't remove unneeded abilities inside a for (am:abilities) loop :( diff --git a/forge-gui/src/main/java/forge/gui/input/InputSelectCardsForConvoke.java b/forge-gui/src/main/java/forge/gui/input/InputSelectCardsForConvoke.java index d2efa0eb2c6..bebe52e91e4 100644 --- a/forge-gui/src/main/java/forge/gui/input/InputSelectCardsForConvoke.java +++ b/forge-gui/src/main/java/forge/gui/input/InputSelectCardsForConvoke.java @@ -52,7 +52,7 @@ public final class InputSelectCardsForConvoke extends InputSelectManyBase byte chosenColor = player.getController().chooseColorAllowColorless("Convoke " + card.toString() + " for which color?", card, CardUtil.getColors(card)); - if (remainingCost.getColorlessManaAmount() > 0 && (chosenColor == 0 || !remainingCost.needsColor(chosenColor))) { + if (remainingCost.getColorlessManaAmount() > 0 && (chosenColor == 0 || !remainingCost.needsColor(chosenColor, player.getManaPool()))) { registerConvoked(card, ManaCostShard.COLORLESS, chosenColor); } else { for (ManaCostShard shard : remainingCost.getDistinctShards()) {