cleanup usage of SubType from string

This commit is contained in:
xenohedron 2023-12-21 22:07:16 -05:00
parent 4f2f566b32
commit 66716a4314
4 changed files with 17 additions and 10 deletions

View file

@ -4,16 +4,14 @@ import mage.abilities.Ability;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect; import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlashbackAbility; import mage.abilities.keyword.FlashbackAbility;
import mage.cards.CardImpl; import mage.cards.*;
import mage.cards.CardSetInfo;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.choices.ChoiceCreatureType; import mage.choices.ChoiceCreatureType;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.SubType; import mage.constants.SubType;
import mage.constants.Zone; import mage.constants.Zone;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.Predicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.TargetCard; import mage.target.TargetCard;
@ -72,9 +70,15 @@ class ForTheAncestorsEffect extends OneShotEffect {
} }
ChoiceCreatureType choice = new ChoiceCreatureType(); ChoiceCreatureType choice = new ChoiceCreatureType();
player.choose(outcome, choice, game); player.choose(outcome, choice, game);
SubType subType = SubType.fromString(choice.getChoice()); SubType subType = SubType.byDescription(choice.getChoice());
FilterCard filter = new FilterCard(subType + " cards"); FilterCard filter;
if (subType != null) {
filter = new FilterCard(choice.getChoice() + " cards");
filter.add(subType.getPredicate()); filter.add(subType.getPredicate());
} else {
filter = new FilterCard();
filter.add((Predicate<Card>) (input, game1) -> false);
}
Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6)); Cards cards = new CardsImpl(player.getLibrary().getTopCards(game, 6));
TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, filter); TargetCard target = new TargetCardInHand(0, Integer.MAX_VALUE, filter);
player.choose(outcome, cards, target, source, game); player.choose(outcome, cards, target, source, game);

View file

@ -90,7 +90,7 @@ class LeoriSparktouchedHunterEffect extends OneShotEffect {
return false; return false;
} }
SubType subType = SubType.fromString(choice.getChoice()); SubType subType = SubType.byDescription(choice.getChoice());
if (subType == null) { if (subType == null) {
return false; return false;
} }

View file

@ -103,7 +103,7 @@ class LongListOfTheEntsEffect extends OneShotEffect {
if (player == null) { if (player == null) {
return false; return false;
} }
Set<String> chosenTypes = this Set<String> chosenTypes = LongListOfTheEntsEffect
.getSubTypes(game, source) .getSubTypes(game, source)
.stream() .stream()
.map(SubType::toString) .map(SubType::toString)
@ -111,7 +111,7 @@ class LongListOfTheEntsEffect extends OneShotEffect {
ChoiceCreatureType choice = new ChoiceCreatureType(source.getSourceObject(game)); ChoiceCreatureType choice = new ChoiceCreatureType(source.getSourceObject(game));
choice.getChoices().removeIf(chosenTypes::contains); choice.getChoices().removeIf(chosenTypes::contains);
player.choose(Outcome.BoostCreature, choice, game); player.choose(Outcome.BoostCreature, choice, game);
SubType subType = SubType.fromString(choice.getChoice()); SubType subType = SubType.byDescription(choice.getChoice());
if (subType == null) { if (subType == null) {
return false; return false;
} }

View file

@ -600,6 +600,9 @@ public enum SubType {
return customSet; return customSet;
} }
/**
* Use in test framework only, use SubType.byDescription instead for card logic
*/
public static SubType fromString(String value) { public static SubType fromString(String value) {
for (SubType st : SubType.values()) { for (SubType st : SubType.values()) {
if (st.toString().equals(value)) { if (st.toString().equals(value)) {