Skip to content

Commit

Permalink
Small rework for autochoosing color of mana to add (#11495)
Browse files Browse the repository at this point in the history
fix #11494
  • Loading branch information
xenohedron authored Dec 1, 2023
1 parent b4a58a3 commit 35f4a89
Show file tree
Hide file tree
Showing 8 changed files with 24 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import mage.cards.repository.CardInfo;
import mage.cards.repository.CardRepository;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.FilterCard;
Expand Down Expand Up @@ -1956,7 +1955,7 @@ public boolean choose(Outcome outcome, Choice choice, Game game) {
}

// 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")) {
choice.setChoice("White");
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
import mage.cards.*;
import mage.cards.decks.Deck;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.choices.ChoiceImpl;
import mage.constants.*;
import mage.filter.StaticFilters;
Expand Down Expand Up @@ -583,7 +582,7 @@ public boolean choose(Outcome outcome, Choice choice, Game game) {
}

// 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
// See: https://github.com/magefree/mage/issues/9070
boolean caresAboutManaColor = false;
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/k/KatildaDawnhartPrime.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Mana produceMana(Game game, Ability source) {
if (controller == null || permanent == null) {
return new Mana();
}
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl().setManaColorChoice(true);
choice.setMessage("Pick a mana color");
ObjectColor color = permanent.getColor(game);
if (color.isWhite()) {
Expand Down
2 changes: 1 addition & 1 deletion Mage.Sets/src/mage/cards/t/TazriStalwartSurvivor.java
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ public Mana produceMana(Game game, Ability source) {
if (controller == null || permanent == null) {
return new Mana();
}
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl().setManaColorChoice(true);
choice.setMessage("Pick a mana color");
ObjectColor color = permanent.getColor(game);
if (color.isWhite()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public Mana produceMana(Game game, Ability source) {
}
Player controller = game.getPlayer(source.getControllerId());
if (controller != null) {
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl().setManaColorChoice(true);
choice.setMessage("Pick a mana color");
for (UUID commanderId : game.getCommandersIds(controller, CommanderCardType.COMMANDER_OR_OATHBREAKER, false)) {
Card commander = game.getCard(commanderId);
Expand Down
4 changes: 4 additions & 0 deletions Mage/src/main/java/mage/choices/Choice.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ public interface Choice extends Serializable, Copyable<Choice> {

ChoiceHintType getHintType();

boolean isManaColorChoice();

Choice setManaColorChoice(boolean manaColorChoice);

// string choice
void setChoices(Set<String> choices);

Expand Down
1 change: 1 addition & 0 deletions Mage/src/main/java/mage/choices/ChoiceColor.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public ChoiceColor(boolean required, String chooseMessage, String chooseSubMessa

this.setMessage(chooseMessage);
this.setSubMessage(chooseSubMessage);
this.manaColorChoice = true;
}

protected ChoiceColor(final ChoiceColor choice) {
Expand Down
14 changes: 14 additions & 0 deletions Mage/src/main/java/mage/choices/ChoiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ public class ChoiceImpl implements Choice {
protected String specialText = "";
protected String specialHint = "";

protected boolean manaColorChoice = false; // set true to allow automatic choosing with Outcome.PutManaInPool

public ChoiceImpl() {
this(false);
}
Expand Down Expand Up @@ -65,6 +67,7 @@ protected ChoiceImpl(final ChoiceImpl choice) {
this.specialCanBeEmpty = choice.specialCanBeEmpty;
this.specialText = choice.specialText;
this.specialHint = choice.specialHint;
this.manaColorChoice = choice.manaColorChoice;
}

@Override
Expand Down Expand Up @@ -328,6 +331,17 @@ public ChoiceHintType getHintType() {
return this.hintType;
}

@Override
public boolean isManaColorChoice() {
return manaColorChoice;
}

@Override
public ChoiceImpl setManaColorChoice(boolean manaColorChoice) {
this.manaColorChoice = manaColorChoice;
return this;
}

private void protectFromEmptyChoices() {
// 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
Expand Down

0 comments on commit 35f4a89

Please sign in to comment.