From 7643ff5597f80eeaa4e12718fd2cdc4d86aaf142 Mon Sep 17 00:00:00 2001 From: Alex Vasile <48962821+Alex-Vasile@users.noreply.github.com> Date: Fri, 27 May 2022 17:16:43 -0600 Subject: [PATCH] - Fixed AddManaInAnyCombinationEffect and DynamicManaEffect to not let you click Choose until you've selected the correct amount. - Added an extra constructor to Mana using ColoredManaSymbols and a count so that a for loop isn't needed in AddManaInAnyCombinationEffect. --- Mage/src/main/java/mage/Mana.java | 21 ++++++---- .../mana/AddManaInAnyCombinationEffect.java | 40 +++++++++++-------- .../effects/mana/DynamicManaEffect.java | 2 +- 3 files changed, 38 insertions(+), 25 deletions(-) diff --git a/Mage/src/main/java/mage/Mana.java b/Mage/src/main/java/mage/Mana.java index 61ac0987b9..03d80ef053 100644 --- a/Mage/src/main/java/mage/Mana.java +++ b/Mage/src/main/java/mage/Mana.java @@ -91,31 +91,38 @@ public class Mana implements Comparable, Serializable, Copyable { this.flag = mana.flag; } + + public Mana(final ColoredManaSymbol color) { + this(color, 1); + } + /** * Creates {@link Mana} object from {@link ColoredManaSymbol}. Created * {@link Mana} will have a single mana of the passed in * {@link ColoredManaSymbol} color. * - * @param color The color to create the {@link Mana} object with. + * @param color the color to create the {@link Mana} object with. + * @param amount the number of mana to add of the given color */ - public Mana(final ColoredManaSymbol color) { + + public Mana(final ColoredManaSymbol color, int amount) { this(); Objects.requireNonNull(color, "The passed in ColoredManaSymbol can not be null"); switch (color) { case W: - white = CardUtil.overflowInc(white, 1); + white = CardUtil.overflowInc(white, amount); break; case U: - blue = CardUtil.overflowInc(blue, 1); + blue = CardUtil.overflowInc(blue, amount); break; case B: - black = CardUtil.overflowInc(black, 1); + black = CardUtil.overflowInc(black, amount); break; case R: - red = CardUtil.overflowInc(red, 1); + red = CardUtil.overflowInc(red, amount); break; case G: - green = CardUtil.overflowInc(green, 1); + green = CardUtil.overflowInc(green, amount); break; default: throw new IllegalArgumentException("Unknown mana color: " + color); diff --git a/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java index 532502bfb2..afb895ef7c 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/AddManaInAnyCombinationEffect.java @@ -113,24 +113,30 @@ public class AddManaInAnyCombinationEffect extends ManaEffect { @Override public Mana produceMana(Game game, Ability source) { Player player = game.getPlayer(source.getControllerId()); - if (player != null) { - int size = manaSymbols.size(); - Mana mana = new Mana(); - List manaStrings = new ArrayList<>(size); - for (ColoredManaSymbol coloredManaSymbol : manaSymbols) { - manaStrings.add(coloredManaSymbol.toString()); - } - List manaList = player.getMultiAmount(this.outcome, manaStrings, 0, amount.calculate(game, source, this), MultiAmountType.MANA, game); - for (int i = 0; i < size; i++) { - ColoredManaSymbol coloredManaSymbol = manaSymbols.get(i); - int amount = manaList.get(i); - for (int j = 0; j < amount; j++) { - mana.add(new Mana(coloredManaSymbol)); - } - } - return mana; + if (player == null) { + return null; } - return null; + + // Calculate which mana colors are available as options + int size = manaSymbols.size(); + Mana mana = new Mana(); + List manaStrings = new ArrayList<>(size); + for (ColoredManaSymbol coloredManaSymbol : manaSymbols) { + manaStrings.add(coloredManaSymbol.toString()); + } + + // Ask player for color distribution + int manaAmount = amount.calculate(game, source, this); + List manaList = player.getMultiAmount(this.outcome, manaStrings, manaAmount, manaAmount, MultiAmountType.MANA, game); + + // Covert choices to mana + for (int i = 0; i < size; i++) { + ColoredManaSymbol coloredManaSymbol = manaSymbols.get(i); + int amount = manaList.get(i); + + mana.add(new Mana(coloredManaSymbol, amount)); + } + return mana; } @Override diff --git a/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java b/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java index d14c147c51..0a3c173be6 100644 --- a/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java +++ b/Mage/src/main/java/mage/abilities/effects/mana/DynamicManaEffect.java @@ -158,7 +158,7 @@ public class DynamicManaEffect extends ManaEffect { manaStrings.add("B"); manaStrings.add("R"); manaStrings.add("G"); - List choices = controller.getMultiAmount(this.outcome, manaStrings, 0, count, MultiAmountType.MANA, game); + List choices = controller.getMultiAmount(this.outcome, manaStrings, count, count, MultiAmountType.MANA, game); computedMana.add(new Mana(choices.get(0), choices.get(1), choices.get(2), choices.get(3), choices.get(4), 0, 0, 0)); } }