refactor: additional improves for mana choice in some cards, related to Naked Singularity from 81039d6e72

This commit is contained in:
Oleg Agafonov 2023-09-23 06:39:01 +04:00
parent 81039d6e72
commit 0bf4b63bcf
14 changed files with 75 additions and 31 deletions

View file

@ -19,11 +19,7 @@ import mage.game.permanent.Permanent;
import mage.players.Player;
import mage.target.common.TargetLandPermanent;
import java.util.ArrayList;
import java.util.EnumSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
import java.util.*;
/**
* @author jeffwadsworth
@ -110,22 +106,32 @@ class BenthicExplorersManaEffect extends ManaEffect {
@Override
public Mana produceMana(Game game, Ability source) {
Mana mana = new Mana();
if (game == null) { return mana; }
Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), false);
if (choice.getChoices().isEmpty()) { return mana; }
if (game == null) {
return mana;
}
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return mana;
}
Choice choice = ManaType.getChoiceOfManaTypes(getManaTypes(game, source), false);
if (choice.getChoices().isEmpty()) {
return mana;
}
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (player == null
|| !player.choose(Outcome.Neutral, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}
if (choice.getChoice() == null) { return mana; }
if (choice.getChoice() == null) {
return mana;
}
switch (choice.getChoice()) {
case "Black":
@ -160,7 +166,9 @@ class BenthicExplorersManaEffect extends ManaEffect {
List<UUID> untapped = (List<UUID>) game.getState()
.getValue("UntapTargetCost" + source.getSourceId().toString());
Permanent land = game.getPermanentOrLKIBattlefield(untapped.get(0));
if (land == null) { return types; }
if (land == null) {
return types;
}
Abilities<ActivatedManaAbilityImpl> mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD);
for (ActivatedManaAbilityImpl ability : mana) {

View file

@ -192,7 +192,7 @@ class ChromeMoxManaEffect extends ManaEffect {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}

View file

@ -14,6 +14,7 @@ import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.ColoredManaSymbol;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.game.Game;
import mage.players.Player;
@ -148,7 +149,7 @@ class CorruptedGrafstoneManaEffect extends ManaEffect {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}

View file

@ -14,6 +14,7 @@ import mage.cards.CardSetInfo;
import mage.choices.Choice;
import mage.choices.ChoiceColor;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.counters.CounterType;
@ -140,9 +141,12 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
}
if (!choice.getChoices().isEmpty()) {
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return mana;
}
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else if (player == null || !player.choose(outcome, choice, game)) {
} else if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
if (choice.getChoice() != null) {

View file

@ -174,7 +174,7 @@ class KatildaDawnhartPrimeManaEffect extends ManaEffect {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
controller.choose(outcome, choice, game);
controller.choose(Outcome.PutManaInPool, choice, game);
}
if (choice.getChoice() == null) {
return new Mana();

View file

@ -11,6 +11,7 @@ import mage.cards.CardSetInfo;
import mage.choices.Choice;
import mage.constants.CardType;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.game.Game;
@ -72,12 +73,17 @@ class MeteorCraterEffect extends ManaEffect {
if (types.isEmpty()) {
return null;
}
Player player = game.getPlayer(source.getControllerId());
if (player == null) {
return null;
}
Choice choice = ManaType.getChoiceOfManaTypes(types, true);
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}

View file

@ -95,9 +95,16 @@ class RealityTwistEffect extends ReplacementEffectImpl {
String chosenColor;
if (choice.getChoices().size() == 1) {
chosenColor = choice.getChoices().iterator().next();
} else if (choice.getChoices().size() == 0) {
chosenColor = null;
} else {
controller.choose(Outcome.PutManaInPool, choice, game);
chosenColor = choice.getChoice();
// workaround to skip choose dialog in check playable state
if (game.inCheckPlayableState()) {
chosenColor = "Any";
} else {
controller.choose(Outcome.PutManaInPool, choice, game);
chosenColor = choice.getChoice();
}
}
if (chosenColor == null) {
return false;
@ -117,6 +124,9 @@ class RealityTwistEffect extends ReplacementEffectImpl {
case "Green":
mana.setToMana(Mana.GreenMana(amount));
break;
case "Any":
mana.setToMana(Mana.AnyMana(amount));
break;
}
return false;
}

View file

@ -226,14 +226,21 @@ class SasayasEssenceManaEffect extends ManaEffect {
for (int i = 0; i < count; i++) {
choice.clearChoice();
String chosenColor;
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
chosenColor = choice.getChoices().iterator().next();
} else {
if (!controller.choose(outcome, choice, game)) {
return newMana;
// workaround to skip choose dialog in check playable state
if (game.inCheckPlayableState()) {
chosenColor = "Any";
} else {
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
return newMana;
}
chosenColor = choice.getChoice();
}
}
switch (choice.getChoice()) {
switch (chosenColor) {
case "Black":
newMana.increaseBlack();
break;
@ -252,6 +259,9 @@ class SasayasEssenceManaEffect extends ManaEffect {
case "Colorless":
newMana.increaseColorless();
break;
case "Any":
newMana.increaseAny();
break;
}
}

View file

@ -15,6 +15,7 @@ import mage.cards.CardSetInfo;
import mage.choices.Choice;
import mage.constants.CardType;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.StaticFilters;
import mage.filter.common.FilterControlledLandPermanent;
@ -100,7 +101,7 @@ class SquanderedResourcesEffect extends ManaEffect {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!player.choose(outcome, choice, game)) {
if (!player.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}

View file

@ -219,7 +219,7 @@ class TazriStalwartSurvivorManaEffect extends ManaEffect {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
controller.choose(outcome, choice, game);
controller.choose(Outcome.PutManaInPool, choice, game);
}
if (choice.getChoice() == null) {
return new Mana();

View file

@ -8,6 +8,7 @@ import mage.abilities.effects.mana.ManaEffect;
import mage.cards.Card;
import mage.choices.Choice;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterCard;
@ -88,7 +89,7 @@ class AnyColorCardInYourGraveyardManaEffect extends ManaEffect {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (player == null || !player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}

View file

@ -6,6 +6,7 @@ import mage.abilities.Ability;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.mana.ManaEffect;
import mage.choices.Choice;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
@ -117,7 +118,7 @@ class AnyColorLandsProduceManaEffect extends ManaEffect {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (player == null || !player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}

View file

@ -7,6 +7,7 @@ import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.effects.mana.ManaEffect;
import mage.choices.Choice;
import mage.constants.ManaType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.filter.FilterPermanent;
@ -90,7 +91,7 @@ class AnyColorPermanentTypesManaEffect extends ManaEffect {
choice.setChoice(choice.getChoices().iterator().next());
} else {
Player player = game.getPlayer(source.getControllerId());
if (player == null || !player.choose(outcome, choice, game)) {
if (player == null || !player.choose(Outcome.PutManaInPool, choice, game)) {
return null;
}
}

View file

@ -10,6 +10,7 @@ import mage.choices.Choice;
import mage.choices.ChoiceImpl;
import mage.constants.ColoredManaSymbol;
import mage.constants.CommanderCardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.FilterMana;
import mage.game.Game;
@ -132,7 +133,7 @@ class CommanderIdentityManaEffect extends ManaEffect {
if (choice.getChoices().size() == 1) {
choice.setChoice(choice.getChoices().iterator().next());
} else {
if (!controller.choose(outcome, choice, game)) {
if (!controller.choose(Outcome.PutManaInPool, choice, game)) {
return mana;
}
}