Implemented Pattern Matcher

This commit is contained in:
Evan Kranzler 2019-06-29 11:14:12 -04:00
parent e2030aead9
commit 08028265d5
2 changed files with 92 additions and 0 deletions

View file

@ -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<NamePredicate> 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);
}
}

View file

@ -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));