refactor: ChoiceImpl constructor must specify whether required

changed a few others to required where clearly applicable
This commit is contained in:
xenohedron 2024-06-29 22:57:47 -04:00
parent bdeb4ed7ae
commit 9863e23435
27 changed files with 32 additions and 38 deletions

View file

@ -440,7 +440,7 @@ public final class SystemUtil {
choices.put(ability.getId().toString(), object.getName() + ": " + ability.toString());
});
// TODO: set priority for us?
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl(false);
choice.setMessage("Choose playable ability to activate by opponent " + opponent.getName());
choice.setKeyChoices(choices);
if (feedbackPlayer.choose(Outcome.Detriment, choice, game) && choice.getChoiceKey() != null) {

View file

@ -114,7 +114,7 @@ class ChooseHumanMerfolkOrGoblinEffect extends OneShotEffect {
return false;
}
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl(true);
Set<String> choices = new LinkedHashSet<>();
choices.add("Human");
choices.add("Merfolk");

View file

@ -77,7 +77,7 @@ class BloodOathEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (player != null && opponent != null && sourceObject != null) {
Choice choiceImpl = new ChoiceImpl();
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
CardType type = null;

View file

@ -1,4 +1,3 @@
package mage.cards.b;
import java.util.HashSet;
@ -24,7 +23,6 @@ import mage.constants.*;
import mage.filter.StaticFilters;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetControlledCreaturePermanent;
/**
*
@ -72,7 +70,7 @@ class ButcherOfTheHordeEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source);
if (sourceObject != null && controller != null) {
Choice abilityChoice = new ChoiceImpl();
Choice abilityChoice = new ChoiceImpl(true);
abilityChoice.setMessage("Choose an ability to add");
Set<String> abilities = new HashSet<>();

View file

@ -97,7 +97,7 @@ class ElementalResonanceEffect extends OneShotEffect {
String manaToAdd = "";
if (manaOptions.size() > 1) {
// TODO: Make the choices look nicer, right now the brace notation is hard to visually parse, especially with Reaper King
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl(false);
choice.setMessage("Choose a mana combination");
choice.getChoices().addAll(manaOptions);
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {

View file

@ -80,7 +80,7 @@ class FertileImaginationEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
Player opponent = game.getPlayer(source.getFirstTarget());
if (player != null && opponent != null && sourceObject != null) {
Choice choiceImpl = new ChoiceImpl();
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
CardType type = null;

View file

@ -92,7 +92,7 @@ class GoblinClearCutterManaEffect extends ManaEffect {
}
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Choice manaChoice = new ChoiceImpl();
Choice manaChoice = new ChoiceImpl(false);
Set<String> choices = new LinkedHashSet<>();
choices.add("Red");
choices.add("Green");

View file

@ -80,7 +80,7 @@ class GolemArtisanEffect extends OneShotEffect {
Permanent permanent = game.getPermanent(getTargetPointer().getFirst(game, source));
Player playerControls = game.getPlayer(source.getControllerId());
if (permanent != null && playerControls != null) {
Choice abilityChoice = new ChoiceImpl();
Choice abilityChoice = new ChoiceImpl(true);
abilityChoice.setMessage("Choose an ability to add");
Set<String> abilities = new HashSet<>();

View file

@ -147,7 +147,7 @@ class GrandWarlordRadhaEffect extends OneShotEffect {
}
}
if (attackingCreatures > 0) {
Choice manaChoice = new ChoiceImpl();
Choice manaChoice = new ChoiceImpl(false);
Set<String> choices = new LinkedHashSet<>();
choices.add("Red");
choices.add("Green");

View file

@ -84,7 +84,7 @@ class GremlinMineEffect extends OneShotEffect {
if (player != null && permanent != null) {
int existingCount = permanent.getCounters(game).getCount(CounterType.CHARGE);
if (existingCount > 0) {
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl(false);
choice.setMessage("Select number of charge counters to remove:");
for (Integer i = 0; i <= existingCount; i++) {
choice.getChoices().add(i.toString());

View file

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

View file

@ -78,8 +78,8 @@ class LavabrinkFloodgatesEffect extends OneShotEffect {
if (player == null || permanent == null) {
return false;
}
Choice choice = new ChoiceImpl();
choice.setChoices(new HashSet(Arrays.asList(
Choice choice = new ChoiceImpl(false);
choice.setChoices(new HashSet<>(Arrays.asList(
"Add a doom counter",
"Remove a doom counter",
"Do nothing"

View file

@ -102,11 +102,11 @@ class LeechBonderEffect extends OneShotEffect {
}
Set<String> possibleChoices = new LinkedHashSet<>(fromPermanent.getCounters(game).keySet());
if (possibleChoices.size() == 0) {
if (possibleChoices.isEmpty()) {
return false;
}
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl(false);
choice.setChoices(possibleChoices);
if (controller.choose(outcome, choice, game)) {
String chosen = choice.getChoice();

View file

@ -70,7 +70,7 @@ class MindblazeEffect extends OneShotEffect {
if (player == null || playerControls == null || sourceObject == null) {
return false;
}
Choice numberChoice = new ChoiceImpl();
Choice numberChoice = new ChoiceImpl(false);
numberChoice.setMessage("Choose a number greater than 0");
Set<String> numbers = new HashSet<>();
for (int i = 1; i <= 4; i++) {

View file

@ -103,7 +103,7 @@ class NestingGroundsEffect extends OneShotEffect {
return true;
}
Choice choice = new ChoiceImpl();
Choice choice = new ChoiceImpl(false);
Set<String> possibleChoices = new LinkedHashSet<>(fromPermanent.getCounters(game).keySet());
choice.setChoices(possibleChoices);
choice.setMessage("Choose a counter");

View file

@ -93,7 +93,7 @@ class OrcishLumberjackManaEffect extends ManaEffect {
}
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
Choice manaChoice = new ChoiceImpl();
Choice manaChoice = new ChoiceImpl(false);
Set<String> choices = new LinkedHashSet<>();
choices.add("Red");
choices.add("Green");

View file

@ -85,7 +85,7 @@ class SarkhanUnbrokenAbility1 extends OneShotEffect {
game.fireUpdatePlayersEvent();
Choice manaChoice = new ChoiceImpl();
Choice manaChoice = new ChoiceImpl(false);
Set<String> choices = new LinkedHashSet<>();
choices.add("White");
choices.add("Blue");

View file

@ -76,7 +76,7 @@ class ShapeshifterEffect extends OneShotEffect {
mageObject = game.getPermanent(source.getSourceId());
}
if (controller != null) {
Choice numberChoice = new ChoiceImpl();
Choice numberChoice = new ChoiceImpl(false);
numberChoice.setMessage("Choose a number beween 0 and 7");
Set<String> numbers = new HashSet<>();
for (int i = 0; i <= 7; i++) {

View file

@ -114,7 +114,7 @@ class SnowfallManaEffect extends ManaEffect {
}
if (land.isSnow(game)) {
Choice choiceImpl = new ChoiceImpl();
Choice choiceImpl = new ChoiceImpl(false);
choiceImpl.setMessage("Add additional blue mana? This mana can only be spent to pay cumulative upkeep costs.");
choiceImpl.setChoices(choice);

View file

@ -80,7 +80,7 @@ class TazriStalwartSurvivorManaAbility extends ActivatedManaAbilityImpl {
&& permanent
.getAbilities(game)
.stream()
.filter(ability -> ability.isActivatedAbility())
.filter(Ability::isActivatedAbility)
.map(Ability::getOriginalId)
.anyMatch(abilityId -> !source.getOriginalId().equals(abilityId));
}
@ -190,7 +190,7 @@ class TazriStalwartSurvivorManaEffect extends ManaEffect {
if (controller == null || permanent == null) {
return new Mana();
}
Choice choice = new ChoiceImpl().setManaColorChoice(true);
Choice choice = new ChoiceImpl(false).setManaColorChoice(true);
choice.setMessage("Pick a mana color");
ObjectColor color = permanent.getColor(game);
if (color.isWhite()) {

View file

@ -486,7 +486,7 @@ class UrzaAcademyHeadmasterManaEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
if (player != null) {
int x = game.getBattlefield().count(new FilterControlledCreaturePermanent(), source.getControllerId(), source, game);
Choice manaChoice = new ChoiceImpl();
Choice manaChoice = new ChoiceImpl(false);
Set<String> choices = new LinkedHashSet<>();
choices.add("White");
choices.add("Blue");

View file

@ -88,7 +88,7 @@ class VeteranWarleaderEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
MageObject sourceObject = game.getObject(source);
if (sourceObject != null && controller != null) {
Choice abilityChoice = new ChoiceImpl();
Choice abilityChoice = new ChoiceImpl(true);
abilityChoice.setMessage("Choose an ability to add");
Set<String> abilities = new HashSet<>();

View file

@ -81,7 +81,7 @@ class VigeanIntuitionEffect extends OneShotEffect {
return false;
}
Choice choiceImpl = new ChoiceImpl();
Choice choiceImpl = new ChoiceImpl(true);
choiceImpl.setChoices(choice);
if (player.choose(Outcome.Neutral, choiceImpl, game)) {
String chosenType = choiceImpl.getChoice();
@ -126,4 +126,4 @@ class VigeanIntuitionEffect extends OneShotEffect {
}
return false;
}
}
}

View file

@ -76,8 +76,8 @@ class WalkingSpongeEffect extends OneShotEffect {
Player controller = game.getPlayer(source.getControllerId());
Permanent permanent = game.getPermanent(source.getSourceId());
if (controller != null && permanent != null) {
ChoiceImpl chooseAbility = new ChoiceImpl();
chooseAbility.setMessage("Choose an ability to remove (default is flying)");
ChoiceImpl chooseAbility = new ChoiceImpl(true);
chooseAbility.setMessage("Choose an ability to remove");
Set<String> choice = new LinkedHashSet<>();
choice.add("Flying");
choice.add("First strike");

View file

@ -64,7 +64,7 @@ class WorldQuellerEffect extends OneShotEffect {
choice.add(CardType.KINDRED.toString());
}
public WorldQuellerEffect() {
WorldQuellerEffect() {
super(Outcome.Benefit);
staticText = "you may choose a card type. If you do, each player sacrifices a permanent of that type";
}
@ -84,7 +84,7 @@ class WorldQuellerEffect extends OneShotEffect {
Player player = game.getPlayer(source.getControllerId());
Permanent sourceCreature = game.getPermanent(source.getSourceId());
if (player != null && sourceCreature != null) {
Choice choiceImpl = new ChoiceImpl();
Choice choiceImpl = new ChoiceImpl(false);
choiceImpl.setChoices(choice);
if (!player.choose(Outcome.Neutral, choiceImpl, game)) {
return false;

View file

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

View file

@ -36,10 +36,6 @@ public class ChoiceImpl implements Choice {
protected boolean manaColorChoice = false; // set true to allow automatic choosing with Outcome.PutManaInPool
public ChoiceImpl() {
this(false);
}
public ChoiceImpl(boolean required) {
this(required, ChoiceHintType.TEXT);
}