From 66716a43143e7b5ae3bfb05edf476341657cbde3 Mon Sep 17 00:00:00 2001 From: xenohedron Date: Thu, 21 Dec 2023 22:07:16 -0500 Subject: [PATCH] cleanup usage of SubType from string --- .../src/mage/cards/f/ForTheAncestors.java | 18 +++++++++++------- .../mage/cards/l/LeoriSparktouchedHunter.java | 2 +- .../src/mage/cards/l/LongListOfTheEnts.java | 4 ++-- Mage/src/main/java/mage/constants/SubType.java | 3 +++ 4 files changed, 17 insertions(+), 10 deletions(-) diff --git a/Mage.Sets/src/mage/cards/f/ForTheAncestors.java b/Mage.Sets/src/mage/cards/f/ForTheAncestors.java index 81991a1f993..216afdc577b 100644 --- a/Mage.Sets/src/mage/cards/f/ForTheAncestors.java +++ b/Mage.Sets/src/mage/cards/f/ForTheAncestors.java @@ -4,16 +4,14 @@ import mage.abilities.Ability; import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.effects.OneShotEffect; import mage.abilities.keyword.FlashbackAbility; -import mage.cards.CardImpl; -import mage.cards.CardSetInfo; -import mage.cards.Cards; -import mage.cards.CardsImpl; +import mage.cards.*; import mage.choices.ChoiceCreatureType; import mage.constants.CardType; import mage.constants.Outcome; import mage.constants.SubType; import mage.constants.Zone; import mage.filter.FilterCard; +import mage.filter.predicate.Predicate; import mage.game.Game; import mage.players.Player; import mage.target.TargetCard; @@ -72,9 +70,15 @@ class ForTheAncestorsEffect extends OneShotEffect { } ChoiceCreatureType choice = new ChoiceCreatureType(); player.choose(outcome, choice, game); - SubType subType = SubType.fromString(choice.getChoice()); - FilterCard filter = new FilterCard(subType + " cards"); - filter.add(subType.getPredicate()); + SubType subType = SubType.byDescription(choice.getChoice()); + FilterCard filter; + if (subType != null) { + filter = new FilterCard(choice.getChoice() + " cards"); + filter.add(subType.getPredicate()); + } else { + filter = new FilterCard(); + filter.add((Predicate) (input, game1) -> false); + } Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6)); TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, filter); player.choose(outcome, cards, target, source, game); diff --git a/Mage.Sets/src/mage/cards/l/LeoriSparktouchedHunter.java b/Mage.Sets/src/mage/cards/l/LeoriSparktouchedHunter.java index 29c355cb436..7306983c901 100644 --- a/Mage.Sets/src/mage/cards/l/LeoriSparktouchedHunter.java +++ b/Mage.Sets/src/mage/cards/l/LeoriSparktouchedHunter.java @@ -90,7 +90,7 @@ class LeoriSparktouchedHunterEffect extends OneShotEffect { return false; } - SubType subType = SubType.fromString(choice.getChoice()); + SubType subType = SubType.byDescription(choice.getChoice()); if (subType == null) { return false; } diff --git a/Mage.Sets/src/mage/cards/l/LongListOfTheEnts.java b/Mage.Sets/src/mage/cards/l/LongListOfTheEnts.java index 8845ce7d58d..4e7d1676241 100644 --- a/Mage.Sets/src/mage/cards/l/LongListOfTheEnts.java +++ b/Mage.Sets/src/mage/cards/l/LongListOfTheEnts.java @@ -103,7 +103,7 @@ class LongListOfTheEntsEffect extends OneShotEffect { if (player == null) { return false; } - Set chosenTypes = this + Set chosenTypes = LongListOfTheEntsEffect .getSubTypes(game, source) .stream() .map(SubType::toString) @@ -111,7 +111,7 @@ class LongListOfTheEntsEffect extends OneShotEffect { ChoiceCreatureType choice = new ChoiceCreatureType(source.getSourceObject(game)); choice.getChoices().removeIf(chosenTypes::contains); player.choose(Outcome.BoostCreature, choice, game); - SubType subType = SubType.fromString(choice.getChoice()); + SubType subType = SubType.byDescription(choice.getChoice()); if (subType == null) { return false; } diff --git a/Mage/src/main/java/mage/constants/SubType.java b/Mage/src/main/java/mage/constants/SubType.java index 42deb20bca8..3c6be66baef 100644 --- a/Mage/src/main/java/mage/constants/SubType.java +++ b/Mage/src/main/java/mage/constants/SubType.java @@ -600,6 +600,9 @@ public enum SubType { return customSet; } + /** + * Use in test framework only, use SubType.byDescription instead for card logic + */ public static SubType fromString(String value) { for (SubType st : SubType.values()) { if (st.toString().equals(value)) {