diff --git a/Mage.Sets/src/mage/cards/p/PatternMatcher.java b/Mage.Sets/src/mage/cards/p/PatternMatcher.java new file mode 100644 index 0000000000..b22972117c --- /dev/null +++ b/Mage.Sets/src/mage/cards/p/PatternMatcher.java @@ -0,0 +1,91 @@ +package mage.cards.p; + +import mage.MageInt; +import mage.abilities.Ability; +import mage.abilities.common.EntersBattlefieldTriggeredAbility; +import mage.abilities.effects.OneShotEffect; +import mage.abilities.effects.common.search.SearchLibraryPutInHandEffect; +import mage.cards.CardImpl; +import mage.cards.CardSetInfo; +import mage.constants.CardType; +import mage.constants.Outcome; +import mage.constants.SubType; +import mage.filter.FilterCard; +import mage.filter.StaticFilters; +import mage.filter.common.FilterCreatureCard; +import mage.filter.predicate.Predicates; +import mage.filter.predicate.mageobject.NamePredicate; +import mage.game.Game; +import mage.game.permanent.Permanent; +import mage.players.Player; +import mage.target.common.TargetCardInLibrary; + +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +/** + * @author TheElk801 + */ +public final class PatternMatcher extends CardImpl { + + public PatternMatcher(UUID ownerId, CardSetInfo setInfo) { + super(ownerId, setInfo, new CardType[]{CardType.ARTIFACT, CardType.CREATURE}, "{4}"); + + this.subtype.add(SubType.GOLEM); + this.power = new MageInt(3); + this.toughness = new MageInt(3); + + // When Pattern Matcher enters the battlefield, you may search your library for a creature card with the same name as another creature you control, reveal it, put it into your hand, then shuffle your library. + this.addAbility(new EntersBattlefieldTriggeredAbility(new RegularExpression(), true)); + } + + private PatternMatcher(final PatternMatcher card) { + super(card); + } + + @Override + public PatternMatcher copy() { + return new PatternMatcher(this); + } +} + +class RegularExpression extends OneShotEffect { + + RegularExpression() { + super(Outcome.Benefit); + staticText = "search your library for a creature card with the same name as another creature you control, " + + "reveal it, put it into your hand, then shuffle your library."; + } + + private RegularExpression(final RegularExpression effect) { + super(effect); + } + + @Override + public RegularExpression copy() { + return new RegularExpression(this); + } + + @Override + public boolean apply(Game game, Ability source) { + Player player = game.getPlayer(source.getControllerId()); + if (player == null) { + return false; + } + List predicates = new ArrayList(); + game.getBattlefield() + .getAllActivePermanents( + StaticFilters.FILTER_CONTROLLED_ANOTHER_CREATURE, source.getControllerId(), game + ).stream() + .map(Permanent::getName) + .filter(s -> !"".equals(s)) + .forEach(s -> predicates.add(new NamePredicate(s))); + FilterCard filter + = new FilterCreatureCard("a creature card with the same name as another creature you control"); + filter.add(Predicates.or(predicates)); + return new SearchLibraryPutInHandEffect( + new TargetCardInLibrary(filter), true, true + ).apply(game, source); + } +} diff --git a/Mage.Sets/src/mage/sets/CoreSet2020.java b/Mage.Sets/src/mage/sets/CoreSet2020.java index 6d1a215e67..8d86a2563b 100644 --- a/Mage.Sets/src/mage/sets/CoreSet2020.java +++ b/Mage.Sets/src/mage/sets/CoreSet2020.java @@ -237,6 +237,7 @@ public final class CoreSet2020 extends ExpansionSet { cards.add(new SetCardInfo("Overgrowth Elemental", 187, Rarity.UNCOMMON, mage.cards.o.OvergrowthElemental.class)); cards.add(new SetCardInfo("Pacifism", 32, Rarity.COMMON, mage.cards.p.Pacifism.class)); cards.add(new SetCardInfo("Pack Mastiff", 152, Rarity.COMMON, mage.cards.p.PackMastiff.class)); + cards.add(new SetCardInfo("Pattern Matcher", 234, Rarity.UNCOMMON, mage.cards.p.PatternMatcher.class)); cards.add(new SetCardInfo("Plains", 261, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Plains", 262, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS)); cards.add(new SetCardInfo("Plains", 263, Rarity.LAND, mage.cards.basiclands.Plains.class, NON_FULL_USE_VARIOUS));