From df0d6511013083341563c495999ccc7c35fe76be Mon Sep 17 00:00:00 2001 From: Bug Hunter Date: Sat, 20 Feb 2021 04:22:02 +0000 Subject: [PATCH] ExpressPay different ComboMana if possible --- .../main/java/forge/ai/ComputerUtilMana.java | 22 +++++++++++++------ .../src/main/java/forge/card/ColorSet.java | 1 - .../game/ability/effects/ManaEffect.java | 10 +++++---- .../java/forge/match/input/InputPayMana.java | 5 +++-- 4 files changed, 24 insertions(+), 14 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java index e5bbf11bae9..8be6891d926 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilMana.java @@ -1241,7 +1241,7 @@ public class ComputerUtilMana { choice = abMana.getExpressChoice(); abMana.clearExpressChoice(); byte colorMask = ManaAtom.fromName(choice); - if (manaAb.canProduce(choice) && testCost.isAnyPartPayableWith(colorMask, ai.getManaPool())) { + if (manaAb.canProduce(choice) && satisfiesColorChoice(abMana, choiceString, choice) && testCost.isAnyPartPayableWith(colorMask, ai.getManaPool())) { choiceString.append(choice); payMultipleMana(testCost, choice, ai); continue; @@ -1251,7 +1251,7 @@ public class ComputerUtilMana { if (!testCost.isPaid()) { // Loop over combo colors for (String color : comboColors) { - if (testCost.isAnyPartPayableWith(ManaAtom.fromName(color), ai.getManaPool())) { + if (satisfiesColorChoice(abMana, choiceString, choice) && testCost.isAnyPartPayableWith(ManaAtom.fromName(color), ai.getManaPool())) { payMultipleMana(testCost, color, ai); if (nMana != 1) { choiceString.append(" "); @@ -1266,14 +1266,18 @@ public class ComputerUtilMana { } } // check if combo mana can produce most common color in hand - String commonColor = ComputerUtilCard.getMostProminentColor(ai.getCardsIn( - ZoneType.Hand)); - if (!commonColor.isEmpty() && abMana.getComboColors().contains(MagicColor.toShortString(commonColor))) { + String commonColor = ComputerUtilCard.getMostProminentColor(ai.getCardsIn(ZoneType.Hand)); + if (!commonColor.isEmpty() && satisfiesColorChoice(abMana, choiceString, MagicColor.toShortString(commonColor)) && abMana.getComboColors().contains(MagicColor.toShortString(commonColor))) { choice = MagicColor.toShortString(commonColor); } else { - // default to first color - choice = comboColors[0]; + // default to first available color + for (String c : comboColors) { + if (satisfiesColorChoice(abMana, choiceString, c)) { + choice = c; + break; + } + } } if (nMana != 1) { choiceString.append(" "); @@ -1288,6 +1292,10 @@ public class ComputerUtilMana { abMana.setExpressChoice(choiceString.toString()); } + private static boolean satisfiesColorChoice(AbilityManaPart abMana, StringBuilder choices, String choice) { + return !abMana.getOrigProduced().contains("Different") || !choices.toString().contains(choice); + } + /** *

* payMultipleMana. diff --git a/forge-core/src/main/java/forge/card/ColorSet.java b/forge-core/src/main/java/forge/card/ColorSet.java index 0384ff5a481..8065f0a4e48 100644 --- a/forge-core/src/main/java/forge/card/ColorSet.java +++ b/forge-core/src/main/java/forge/card/ColorSet.java @@ -41,7 +41,6 @@ public final class ColorSet implements Comparable, Iterable, Ser private static final long serialVersionUID = 794691267379929080L; private final byte myColor; - public byte getMyColor() { return myColor; } private final float orderWeight; private static final ColorSet[] cache = new ColorSet[32]; diff --git a/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java b/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java index 74f6a3bdc3a..24f4d5e94be 100644 --- a/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java +++ b/forge-game/src/main/java/forge/game/ability/effects/ManaEffect.java @@ -72,14 +72,16 @@ public class ManaEffect extends SpellAbilityEffect { choice = colorsProduced[differentChoice ? nMana : 0]; } else { byte chosenColor = p.getController().chooseColor(Localizer.getInstance().getMessage("lblSelectManaProduce"), sa, - differentChoice ? fullOptions : colorOptions); + differentChoice && (colorsNeeded == null || colorsNeeded.length <= nMana) ? fullOptions : colorOptions); if (chosenColor == 0) throw new RuntimeException("ManaEffect::resolve() /*combo mana*/ - " + p + " color mana choice is empty for " + card.getName()); - - fullOptions = ColorSet.fromMask(fullOptions.getMyColor() - chosenColor); + + if (differentChoice) { + fullOptions = ColorSet.fromMask(fullOptions.getColor() - chosenColor); + } choice = MagicColor.toShortString(chosenColor); } - + if (nMana > 0) { choiceString.append(" "); } diff --git a/forge-gui/src/main/java/forge/match/input/InputPayMana.java b/forge-gui/src/main/java/forge/match/input/InputPayMana.java index 964f89f34f3..ae52ec69690 100644 --- a/forge-gui/src/main/java/forge/match/input/InputPayMana.java +++ b/forge-gui/src/main/java/forge/match/input/InputPayMana.java @@ -330,8 +330,9 @@ public abstract class InputPayMana extends InputSyncronizedBase { @Override public void run() { if (HumanPlay.playSpellAbility(getController(), chosen.getActivatingPlayer(), chosen)) { - player.getManaPool().payManaFromAbility(saPaidFor, InputPayMana.this.manaCost, chosen); - + if (chosen.getManaPart().meetsManaRestrictions(saPaidFor)) { + player.getManaPool().payManaFromAbility(saPaidFor, InputPayMana.this.manaCost, chosen); + } onManaAbilityPaid(); onStateChanged(); }