From 2e2e141e917b0d37f7a1544a82bb35e42b26b2ee Mon Sep 17 00:00:00 2001 From: ArsenalNut Date: Mon, 16 Jan 2012 04:53:04 +0000 Subject: [PATCH] Refactored anyChoice to expressChoice. Added logic to make automatic color choices for "Any" keyword mana sources. --- src/main/java/forge/ComputerUtil.java | 2 +- .../abilityfactory/AbilityFactoryMana.java | 38 ++++++++++++---- src/main/java/forge/card/mana/ManaPool.java | 2 +- .../forge/card/spellability/AbilityMana.java | 10 ++--- .../forge/gui/input/InputPayManaCostUtil.java | 44 +++++++++++++++++-- 5 files changed, 78 insertions(+), 18 deletions(-) diff --git a/src/main/java/forge/ComputerUtil.java b/src/main/java/forge/ComputerUtil.java index 132a4330514..e3bbee9f291 100644 --- a/src/main/java/forge/ComputerUtil.java +++ b/src/main/java/forge/ComputerUtil.java @@ -835,7 +835,7 @@ public class ComputerUtil { } } } - m.setAnyChoice(colorChoice); + m.setExpressChoice(colorChoice); } // get produced mana manaProduced = m.getManaProduced(); diff --git a/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java b/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java index a8ebe155302..fd30e1f82d4 100644 --- a/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java +++ b/src/main/java/forge/card/abilityfactory/AbilityFactoryMana.java @@ -299,12 +299,34 @@ public class AbilityFactoryMana { if (tgt == null || p.canBeTargetedBy(sa)) { // AI color choice is set in ComputerUtils so only human players need to make a choice if (sa.getActivatingPlayer().isHuman()) { - Object o = GuiUtils.getChoice("Choose a color", Constant.Color.ONLY_COLORS); - if (null == o) { - return; + String colorsNeeded = abMana.getExpressChoice(); + String choice = ""; + if (colorsNeeded.length() == 1) { + choice = colorsNeeded; } - String choice = (String) o; - abMana.setAnyChoice(InputPayManaCostUtil.getShortColorString(choice)); + else { + String[] colorMenu = null; + if (colorsNeeded.length() > 1 && colorsNeeded.length() < 5) { + colorMenu = new String[colorsNeeded.length()]; + //loop through colors to make menu + for (int nChar = 0; nChar < colorsNeeded.length(); nChar++) { + colorMenu[nChar] = InputPayManaCostUtil.getLongColorString(colorsNeeded.substring(nChar, nChar + 1)); + } + } + else { + colorMenu = Constant.Color.ONLY_COLORS; + } + Object o = GuiUtils.getChoice("Select Mana to Produce", colorMenu); + if (o == null) { + final StringBuilder sb = new StringBuilder(); + sb.append("AbilityFactoryMana::manaResolve() - Human color mana choice is empty for "); + sb.append(sa.getSourceCard().getName()); + throw new RuntimeException(sb.toString()); + } else { + choice = InputPayManaCostUtil.getShortColorString((String) o); + } + } + abMana.setExpressChoice(choice); } else { if (params.containsKey("AILogic")) { @@ -315,9 +337,9 @@ public class AbilityFactoryMana { Zone.Hand)); } GuiUtils.getChoice("Computer picked: ", chosen); - abMana.setAnyChoice(InputPayManaCostUtil.getShortColorString(chosen)); + abMana.setExpressChoice(InputPayManaCostUtil.getShortColorString(chosen)); } - if (abMana.getAnyChoice().isEmpty()) { + if (abMana.getExpressChoice().isEmpty()) { final StringBuilder sb = new StringBuilder(); sb.append("AbilityFactoryMana::manaResolve() - any color mana choice is empty for "); sb.append(sa.getSourceCard().getName()); @@ -372,7 +394,7 @@ public class AbilityFactoryMana { String baseMana; if (abMana.isAnyMana()) { - baseMana = abMana.getAnyChoice(); + baseMana = abMana.getExpressChoice(); if (baseMana.isEmpty()) { baseMana = "Any"; } diff --git a/src/main/java/forge/card/mana/ManaPool.java b/src/main/java/forge/card/mana/ManaPool.java index 88f0982b00b..38ade354da9 100644 --- a/src/main/java/forge/card/mana/ManaPool.java +++ b/src/main/java/forge/card/mana/ManaPool.java @@ -707,7 +707,7 @@ public class ManaPool { String[] cost = null; if (mability.isAnyMana()) { cost = new String[1]; - cost[0] = mability.getAnyChoice(); + cost[0] = mability.getExpressChoice(); } else { cost = formatMana(mability); diff --git a/src/main/java/forge/card/spellability/AbilityMana.java b/src/main/java/forge/card/spellability/AbilityMana.java index b114cde04ae..295b18fddba 100644 --- a/src/main/java/forge/card/spellability/AbilityMana.java +++ b/src/main/java/forge/card/spellability/AbilityMana.java @@ -39,7 +39,7 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se private static final long serialVersionUID = -6816356991224950520L; private String origProduced; - private String lastAnyChoice = ""; + private String lastExpressChoice = ""; private String lastProduced = ""; private int amount = 1; @@ -277,8 +277,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se * * @param s a {@link java.lang.String} object. */ - public void setAnyChoice(String s) { - this.lastAnyChoice = s; + public void setExpressChoice(String s) { + this.lastExpressChoice = s; } /** @@ -288,8 +288,8 @@ public abstract class AbilityMana extends AbilityActivated implements java.io.Se * * @return a {@link java.lang.String} object. */ - public String getAnyChoice() { - return this.lastAnyChoice; + public String getExpressChoice() { + return this.lastExpressChoice; } /** diff --git a/src/main/java/forge/gui/input/InputPayManaCostUtil.java b/src/main/java/forge/gui/input/InputPayManaCostUtil.java index 3417e63e5df..e088da69b76 100644 --- a/src/main/java/forge/gui/input/InputPayManaCostUtil.java +++ b/src/main/java/forge/gui/input/InputPayManaCostUtil.java @@ -66,12 +66,17 @@ public class InputPayManaCostUtil { ArrayList abilities = InputPayManaCostUtil.getManaAbilities(card); final StringBuilder cneeded = new StringBuilder(); + final StringBuilder colorRequired = new StringBuilder(); boolean choice = true; boolean skipExpress = false; for (final String color : Constant.Color.MANA_COLORS) { + String shortColor = InputPayManaCostUtil.getShortColorString(color); if (manaCost.isNeeded(color)) { - cneeded.append(InputPayManaCostUtil.getShortColorString(color)); + cneeded.append(shortColor); + } + if (manaCost.isColor(shortColor)) { + colorRequired.append(shortColor); } } @@ -100,10 +105,37 @@ public class InputPayManaCostUtil { return manaCost; } - // TODO when implementing sunburst + // Store some information about color costs to help with any mana choices + String colorsNeeded = colorRequired.toString(); + if ("1".equals(colorsNeeded)) { // only colorless left + if (sa.getSourceCard().getSVar("ManaNeededToAvoidNegativeEffect") != "") { + colorsNeeded = ""; + String[] negEffects = sa.getSourceCard().getSVar("ManaNeededToAvoidNegativeEffect").split(","); + for (String negColor : negEffects) { + // convert long color strings to short color strings + if (negColor.length() > 1) { + negColor = InputPayManaCostUtil.getShortColorString(negColor); + } + if (!colorsNeeded.contains(negColor)) { + colorsNeeded = colorsNeeded.concat(negColor); + } + } + } + else { + colorsNeeded = "W"; + } + } + else { + // remove colorless from colors needed + colorsNeeded = colorsNeeded.replace("1", ""); + } + // If the card has sunburst or any other ability that tracks mana spent, // skip express Mana choice - // if (card.getTrackManaPaid()) skipExpress = true; + if (sa.getSourceCard().hasKeyword("Sunburst") && sa.isSpell()) { + colorsNeeded = "WUBRG"; + skipExpress = true; + } if (!skipExpress) { // express Mana Choice @@ -151,10 +183,16 @@ public class InputPayManaCostUtil { chosen = (AbilityMana) GuiUtils.getChoice("Choose mana ability", abilities.toArray()); } + // save off color needed for use by any mana and reflected mana + chosen.setExpressChoice(colorsNeeded); + AllZone.getGameAction().playSpellAbility(chosen); manaCost = AllZone.getHumanPlayer().getManaPool().subtractMana(sa, manaCost, chosen); + // reset choice to blank, make sure this done after subtractMana + chosen.setExpressChoice(""); + AllZone.getHumanPlayer().getZone(Zone.Battlefield).updateObservers(); // DO NOT REMOVE THIS, otherwise the cards don't always tap (copied) return manaCost;