From 0bf4b63bcf948eb7aa558954c88f79694312dfb9 Mon Sep 17 00:00:00 2001 From: Oleg Agafonov Date: Sat, 23 Sep 2023 06:39:01 +0400 Subject: [PATCH] refactor: additional improves for mana choice in some cards, related to Naked Singularity from 81039d6e72930a1f6e498e386d86136dd57fceac --- .../src/mage/cards/b/BenthicExplorers.java | 34 ++++++++++++------- Mage.Sets/src/mage/cards/c/ChromeMox.java | 2 +- .../src/mage/cards/c/CorruptedGrafstone.java | 3 +- .../src/mage/cards/i/IncubationDruid.java | 6 +++- .../mage/cards/k/KatildaDawnhartPrime.java | 2 +- Mage.Sets/src/mage/cards/m/MeteorCrater.java | 10 ++++-- Mage.Sets/src/mage/cards/r/RealityTwist.java | 14 ++++++-- .../mage/cards/s/SasayaOrochiAscendant.java | 18 +++++++--- .../src/mage/cards/s/SquanderedResources.java | 3 +- .../mage/cards/t/TazriStalwartSurvivor.java | 2 +- ...nyColorCardInYourGraveyardManaAbility.java | 3 +- .../mana/AnyColorLandsProduceManaAbility.java | 3 +- .../AnyColorPermanentTypesManaAbility.java | 3 +- .../CommanderColorIdentityManaAbility.java | 3 +- 14 files changed, 75 insertions(+), 31 deletions(-) diff --git a/Mage.Sets/src/mage/cards/b/BenthicExplorers.java b/Mage.Sets/src/mage/cards/b/BenthicExplorers.java index 98333b18c7d..b4998813171 100644 --- a/Mage.Sets/src/mage/cards/b/BenthicExplorers.java +++ b/Mage.Sets/src/mage/cards/b/BenthicExplorers.java @@ -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 untapped = (List) 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 mana = land.getAbilities().getActivatedManaAbilities(Zone.BATTLEFIELD); for (ActivatedManaAbilityImpl ability : mana) { diff --git a/Mage.Sets/src/mage/cards/c/ChromeMox.java b/Mage.Sets/src/mage/cards/c/ChromeMox.java index 6d524368a9b..55fba9d82ca 100644 --- a/Mage.Sets/src/mage/cards/c/ChromeMox.java +++ b/Mage.Sets/src/mage/cards/c/ChromeMox.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java b/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java index 251ced30140..4155be08527 100644 --- a/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java +++ b/Mage.Sets/src/mage/cards/c/CorruptedGrafstone.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/i/IncubationDruid.java b/Mage.Sets/src/mage/cards/i/IncubationDruid.java index 0bc69a192da..a6206e59dcf 100644 --- a/Mage.Sets/src/mage/cards/i/IncubationDruid.java +++ b/Mage.Sets/src/mage/cards/i/IncubationDruid.java @@ -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) { diff --git a/Mage.Sets/src/mage/cards/k/KatildaDawnhartPrime.java b/Mage.Sets/src/mage/cards/k/KatildaDawnhartPrime.java index cf59dd20386..8e551fd7e7c 100644 --- a/Mage.Sets/src/mage/cards/k/KatildaDawnhartPrime.java +++ b/Mage.Sets/src/mage/cards/k/KatildaDawnhartPrime.java @@ -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(); diff --git a/Mage.Sets/src/mage/cards/m/MeteorCrater.java b/Mage.Sets/src/mage/cards/m/MeteorCrater.java index d1857ec141a..976830e7ba2 100644 --- a/Mage.Sets/src/mage/cards/m/MeteorCrater.java +++ b/Mage.Sets/src/mage/cards/m/MeteorCrater.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/r/RealityTwist.java b/Mage.Sets/src/mage/cards/r/RealityTwist.java index 669cfb695e6..52fc3ab1f80 100644 --- a/Mage.Sets/src/mage/cards/r/RealityTwist.java +++ b/Mage.Sets/src/mage/cards/r/RealityTwist.java @@ -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; } diff --git a/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java b/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java index f394966abe3..37c5ed94f69 100644 --- a/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java +++ b/Mage.Sets/src/mage/cards/s/SasayaOrochiAscendant.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/s/SquanderedResources.java b/Mage.Sets/src/mage/cards/s/SquanderedResources.java index b05dac40125..6b943c3f885 100644 --- a/Mage.Sets/src/mage/cards/s/SquanderedResources.java +++ b/Mage.Sets/src/mage/cards/s/SquanderedResources.java @@ -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; } } diff --git a/Mage.Sets/src/mage/cards/t/TazriStalwartSurvivor.java b/Mage.Sets/src/mage/cards/t/TazriStalwartSurvivor.java index ef780670d2a..d8d609690c6 100644 --- a/Mage.Sets/src/mage/cards/t/TazriStalwartSurvivor.java +++ b/Mage.Sets/src/mage/cards/t/TazriStalwartSurvivor.java @@ -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(); diff --git a/Mage/src/main/java/mage/abilities/mana/AnyColorCardInYourGraveyardManaAbility.java b/Mage/src/main/java/mage/abilities/mana/AnyColorCardInYourGraveyardManaAbility.java index 85801b0b3dd..19dab086f6a 100644 --- a/Mage/src/main/java/mage/abilities/mana/AnyColorCardInYourGraveyardManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/AnyColorCardInYourGraveyardManaAbility.java @@ -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; } } diff --git a/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java b/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java index 92f572f0975..9c3b8f26943 100644 --- a/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/AnyColorLandsProduceManaAbility.java @@ -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; } } diff --git a/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java b/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java index 0d9b0cebaeb..f6cd43bbfcc 100644 --- a/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/AnyColorPermanentTypesManaAbility.java @@ -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; } } diff --git a/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java b/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java index d6489776937..57d5aa40784 100644 --- a/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java +++ b/Mage/src/main/java/mage/abilities/mana/CommanderColorIdentityManaAbility.java @@ -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; } }