Small rework for autochoosing color of mana to add (#11495)

fix #11494
This commit is contained in:
xenohedron 2023-12-01 00:49:42 -05:00 committed by GitHub
parent b4a58a339d
commit 35f4a898f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 24 additions and 7 deletions

View file

@ -24,7 +24,6 @@ import mage.cards.repository.CardCriteria;
import mage.cards.repository.CardInfo; import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository; import mage.cards.repository.CardRepository;
import mage.choices.Choice; import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.*; import mage.constants.*;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.filter.FilterCard; import mage.filter.FilterCard;
@ -1956,7 +1955,7 @@ public class ComputerPlayer extends PlayerImpl implements Player {
} }
// choose the correct color to pay a spell // choose the correct color to pay a spell
if (outcome == Outcome.PutManaInPool && choice instanceof ChoiceColor && currentUnpaidMana != null) { if (outcome == Outcome.PutManaInPool && choice.isManaColorChoice() && currentUnpaidMana != null) {
if (currentUnpaidMana.containsColor(ColoredManaSymbol.W) && choice.getChoices().contains("White")) { if (currentUnpaidMana.containsColor(ColoredManaSymbol.W) && choice.getChoices().contains("White")) {
choice.setChoice("White"); choice.setChoice("White");
return true; return true;

View file

@ -16,7 +16,6 @@ import mage.abilities.mana.ManaAbility;
import mage.cards.*; import mage.cards.*;
import mage.cards.decks.Deck; import mage.cards.decks.Deck;
import mage.choices.Choice; import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.choices.ChoiceImpl; import mage.choices.ChoiceImpl;
import mage.constants.*; import mage.constants.*;
import mage.filter.StaticFilters; import mage.filter.StaticFilters;
@ -583,7 +582,7 @@ public class HumanPlayer extends PlayerImpl {
} }
// Try to autopay for mana // Try to autopay for mana
if (Outcome.PutManaInPool == outcome && choice instanceof ChoiceColor && currentlyUnpaidMana != null) { if (Outcome.PutManaInPool == outcome && choice.isManaColorChoice() && currentlyUnpaidMana != null) {
// Check check if the spell being paid for cares about the color of mana being paid // Check check if the spell being paid for cares about the color of mana being paid
// See: https://github.com/magefree/mage/issues/9070 // See: https://github.com/magefree/mage/issues/9070
boolean caresAboutManaColor = false; boolean caresAboutManaColor = false;

View file

@ -150,7 +150,7 @@ class KatildaDawnhartPrimeManaEffect extends ManaEffect {
if (controller == null || permanent == null) { if (controller == null || permanent == null) {
return new Mana(); return new Mana();
} }
Choice choice = new ChoiceImpl(); Choice choice = new ChoiceImpl().setManaColorChoice(true);
choice.setMessage("Pick a mana color"); choice.setMessage("Pick a mana color");
ObjectColor color = permanent.getColor(game); ObjectColor color = permanent.getColor(game);
if (color.isWhite()) { if (color.isWhite()) {

View file

@ -195,7 +195,7 @@ class TazriStalwartSurvivorManaEffect extends ManaEffect {
if (controller == null || permanent == null) { if (controller == null || permanent == null) {
return new Mana(); return new Mana();
} }
Choice choice = new ChoiceImpl(); Choice choice = new ChoiceImpl().setManaColorChoice(true);
choice.setMessage("Pick a mana color"); choice.setMessage("Pick a mana color");
ObjectColor color = permanent.getColor(game); ObjectColor color = permanent.getColor(game);
if (color.isWhite()) { if (color.isWhite()) {

View file

@ -106,7 +106,7 @@ class CommanderIdentityManaEffect extends ManaEffect {
} }
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
if (controller != null) { if (controller != null) {
Choice choice = new ChoiceImpl(); Choice choice = new ChoiceImpl().setManaColorChoice(true);
choice.setMessage("Pick a mana color"); choice.setMessage("Pick a mana color");
for (UUID commanderId : game.getCommandersIds(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)) { for (UUID commanderId : game.getCommandersIds(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)) {
Card commander = game.getCard(commanderId); Card commander = game.getCard(commanderId);

View file

@ -41,6 +41,10 @@ public interface Choice extends Serializable, Copyable<Choice> {
ChoiceHintType getHintType(); ChoiceHintType getHintType();
boolean isManaColorChoice();
Choice setManaColorChoice(boolean manaColorChoice);
// string choice // string choice
void setChoices(Set<String> choices); void setChoices(Set<String> choices);

View file

@ -47,6 +47,7 @@ public class ChoiceColor extends ChoiceImpl {
this.setMessage(chooseMessage); this.setMessage(chooseMessage);
this.setSubMessage(chooseSubMessage); this.setSubMessage(chooseSubMessage);
this.manaColorChoice = true;
} }
protected ChoiceColor(final ChoiceColor choice) { protected ChoiceColor(final ChoiceColor choice) {

View file

@ -34,6 +34,8 @@ public class ChoiceImpl implements Choice {
protected String specialText = ""; protected String specialText = "";
protected String specialHint = ""; protected String specialHint = "";
protected boolean manaColorChoice = false; // set true to allow automatic choosing with Outcome.PutManaInPool
public ChoiceImpl() { public ChoiceImpl() {
this(false); this(false);
} }
@ -65,6 +67,7 @@ public class ChoiceImpl implements Choice {
this.specialCanBeEmpty = choice.specialCanBeEmpty; this.specialCanBeEmpty = choice.specialCanBeEmpty;
this.specialText = choice.specialText; this.specialText = choice.specialText;
this.specialHint = choice.specialHint; this.specialHint = choice.specialHint;
this.manaColorChoice = choice.manaColorChoice;
} }
@Override @Override
@ -328,6 +331,17 @@ public class ChoiceImpl implements Choice {
return this.hintType; return this.hintType;
} }
@Override
public boolean isManaColorChoice() {
return manaColorChoice;
}
@Override
public ChoiceImpl setManaColorChoice(boolean manaColorChoice) {
this.manaColorChoice = manaColorChoice;
return this;
}
private void protectFromEmptyChoices() { private void protectFromEmptyChoices() {
// if there are no choices then required must be disabled to allow user to close a dialog // if there are no choices then required must be disabled to allow user to close a dialog
// example: database error on too low memory, see Brain Pry and 500 Mb server // example: database error on too low memory, see Brain Pry and 500 Mb server