- 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.
This commit is contained in:
Alex Vasile 2022-05-27 17:16:43 -06:00
parent 7566115121
commit 7643ff5597
3 changed files with 38 additions and 25 deletions

View file

@ -91,31 +91,38 @@ public class Mana implements Comparable<Mana>, Serializable, Copyable<Mana> {
this.flag = mana.flag; this.flag = mana.flag;
} }
public Mana(final ColoredManaSymbol color) {
this(color, 1);
}
/** /**
* Creates {@link Mana} object from {@link ColoredManaSymbol}. Created * Creates {@link Mana} object from {@link ColoredManaSymbol}. Created
* {@link Mana} will have a single mana of the passed in * {@link Mana} will have a single mana of the passed in
* {@link ColoredManaSymbol} color. * {@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(); this();
Objects.requireNonNull(color, "The passed in ColoredManaSymbol can not be null"); Objects.requireNonNull(color, "The passed in ColoredManaSymbol can not be null");
switch (color) { switch (color) {
case W: case W:
white = CardUtil.overflowInc(white, 1); white = CardUtil.overflowInc(white, amount);
break; break;
case U: case U:
blue = CardUtil.overflowInc(blue, 1); blue = CardUtil.overflowInc(blue, amount);
break; break;
case B: case B:
black = CardUtil.overflowInc(black, 1); black = CardUtil.overflowInc(black, amount);
break; break;
case R: case R:
red = CardUtil.overflowInc(red, 1); red = CardUtil.overflowInc(red, amount);
break; break;
case G: case G:
green = CardUtil.overflowInc(green, 1); green = CardUtil.overflowInc(green, amount);
break; break;
default: default:
throw new IllegalArgumentException("Unknown mana color: " + color); throw new IllegalArgumentException("Unknown mana color: " + color);

View file

@ -113,24 +113,30 @@ public class AddManaInAnyCombinationEffect extends ManaEffect {
@Override @Override
public Mana produceMana(Game game, Ability source) { public Mana produceMana(Game game, Ability source) {
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
if (player != null) { if (player == null) {
int size = manaSymbols.size(); return null;
Mana mana = new Mana();
List<String> manaStrings = new ArrayList<>(size);
for (ColoredManaSymbol coloredManaSymbol : manaSymbols) {
manaStrings.add(coloredManaSymbol.toString());
}
List<Integer> 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;
} }
return null;
// Calculate which mana colors are available as options
int size = manaSymbols.size();
Mana mana = new Mana();
List<String> 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<Integer> 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 @Override

View file

@ -158,7 +158,7 @@ public class DynamicManaEffect extends ManaEffect {
manaStrings.add("B"); manaStrings.add("B");
manaStrings.add("R"); manaStrings.add("R");
manaStrings.add("G"); manaStrings.add("G");
List<Integer> choices = controller.getMultiAmount(this.outcome, manaStrings, 0, count, MultiAmountType.MANA, game); List<Integer> 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)); computedMana.add(new Mana(choices.get(0), choices.get(1), choices.get(2), choices.get(3), choices.get(4), 0, 0, 0));
} }
} }