[filters] replaced Name condition with Predicate

This commit is contained in:
North 2012-07-10 22:37:53 +03:00
parent 3d1f23e03b
commit 98feeb9968
28 changed files with 120 additions and 83 deletions

View file

@ -42,6 +42,7 @@ import mage.cards.CardsImpl;
import mage.choices.Choice; import mage.choices.Choice;
import mage.choices.ChoiceImpl; import mage.choices.ChoiceImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.sets.Sets; import mage.sets.Sets;
@ -119,7 +120,7 @@ class MindblazeEffect extends OneShotEffect<MindblazeEffect> {
cards.addAll(player.getLibrary().getCards(game)); cards.addAll(player.getLibrary().getCards(game));
playerControls.revealCards("Library", cards, game); playerControls.revealCards("Library", cards, game);
FilterCard filter = new FilterCard(); FilterCard filter = new FilterCard();
filter.getName().add(cardChoice.getChoice()); filter.add(new NamePredicate(cardChoice.getChoice()));
int count = Integer.parseInt(numberChoice.getChoice()); int count = Integer.parseInt(numberChoice.getChoice());
if (player.getLibrary().count(filter, game) == count) { if (player.getLibrary().count(filter, game) == count) {
player.damage(8, source.getSourceId(), game.copy(), false, true); player.damage(8, source.getSourceId(), game.copy(), false, true);

View file

@ -39,6 +39,8 @@ import mage.abilities.keyword.EnchantAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -105,8 +107,7 @@ class CurseOfMisfortunesEffect extends OneShotEffect<CurseOfMisfortunesEffect> {
for (UUID attachmentId: targetPlayer.getAttachments()) { for (UUID attachmentId: targetPlayer.getAttachments()) {
Permanent attachment = game.getPermanent(attachmentId); Permanent attachment = game.getPermanent(attachmentId);
if (attachment != null && attachment.getSubtype().contains("Curse")) { if (attachment != null && attachment.getSubtype().contains("Curse")) {
filter.getName().add(attachment.getName()); filter.add(Predicates.not(new NamePredicate(attachment.getName())));
filter.setNotName(true);
} }
} }

View file

@ -39,6 +39,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlashbackAbility; import mage.abilities.keyword.FlashbackAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
@ -93,7 +94,7 @@ class SeverTheBloodlineEffect extends OneShotEffect<SeverTheBloodlineEffect> {
Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source)); Permanent targetPermanent = game.getPermanent(targetPointer.getFirst(game, source));
if (targetPermanent != null) { if (targetPermanent != null) {
FilterCreaturePermanent filter = new FilterCreaturePermanent(); FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.getName().add(targetPermanent.getName()); filter.add(new NamePredicate(targetPermanent.getName()));
List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getId(), game); List<Permanent> permanents = game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source.getId(), game);
for (Permanent permanent : permanents) { for (Permanent permanent : permanents) {
permanent.moveToExile(null, "", source.getId(), game); permanent.moveToExile(null, "", source.getId(), game);

View file

@ -44,6 +44,7 @@ import mage.target.common.TargetCardInLibrary;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.filter.predicate.mageobject.NamePredicate;
/** /**
* *
@ -92,7 +93,7 @@ class HauntingEchoesEffect extends OneShotEffect<HauntingEchoesEffect> {
card.moveToExile(null, "", source.getId(), game); card.moveToExile(null, "", source.getId(), game);
FilterCard filterCard = new FilterCard("cards named " + card.getName()); FilterCard filterCard = new FilterCard("cards named " + card.getName());
filterCard.getName().add(card.getName()); filterCard.add(new NamePredicate(card.getName()));
int count = targetPlayer.getLibrary().count(filterCard, game); int count = targetPlayer.getLibrary().count(filterCard, game);
TargetCardInLibrary target = new TargetCardInLibrary(count, count, filterCard); TargetCardInLibrary target = new TargetCardInLibrary(count, count, filterCard);
target.setRequired(true); target.setRequired(true);

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.common.search.SearchLibraryRevealPutInHandEffect;
import mage.abilities.keyword.FlyingAbility; import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
/** /**
@ -48,7 +49,7 @@ public class SquadronHawk extends CardImpl<SquadronHawk> {
private static final FilterCard filter = new FilterCard("cards named Squadron Hawk"); private static final FilterCard filter = new FilterCard("cards named Squadron Hawk");
static { static {
filter.getName().add("Squadron Hawk"); filter.add(new NamePredicate("Squadron Hawk"));
} }
public SquadronHawk(UUID ownerId) { public SquadronHawk(UUID ownerId) {

View file

@ -42,6 +42,7 @@ import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -115,7 +116,7 @@ class ArachnusSpinnerEffect extends OneShotEffect<ArachnusSpinnerEffect> {
} }
FilterCard filter = new FilterCard("card named Arachnus Web"); FilterCard filter = new FilterCard("card named Arachnus Web");
filter.getName().add("Arachnus Web"); filter.add(new NamePredicate("Arachnus Web"));
Card card = null; Card card = null;
Zone zone = null; Zone zone = null;

View file

@ -45,6 +45,7 @@ import mage.target.common.TargetCardInLibrary;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.UUID; import java.util.UUID;
import mage.filter.predicate.mageobject.NamePredicate;
/** /**
* *
@ -105,7 +106,7 @@ class DoublingChantEffect extends OneShotEffect<DoublingChantEffect> {
if (player.chooseUse(Outcome.PutCreatureInPlay, sb.toString(), game)) { if (player.chooseUse(Outcome.PutCreatureInPlay, sb.toString(), game)) {
FilterCreatureCard filter = new FilterCreatureCard("creature card named" + creatureName); FilterCreatureCard filter = new FilterCreatureCard("creature card named" + creatureName);
filter.getName().add(creatureName); filter.add(new NamePredicate(creatureName));
TargetCardInLibrary target = new TargetCardInLibrary(filter); TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (player.searchLibrary(target, game)) { if (player.searchLibrary(target, game)) {

View file

@ -41,6 +41,7 @@ import mage.cards.CardImpl;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -91,8 +92,10 @@ class MitoticManipulationEffect extends OneShotEffect<MitoticManipulationEffect>
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game); List<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game);
HashSet<String> permanentNames = new HashSet<String>(); HashSet<String> permanentNames = new HashSet<String>();
FilterCard filter = new FilterCard("card to put onto the battlefield");
for (Permanent permanent : permanents) { for (Permanent permanent : permanents) {
permanentNames.add(permanent.getName()); permanentNames.add(permanent.getName());
filter.add(new NamePredicate(permanent.getName()));
} }
Player player = game.getPlayer(source.getControllerId()); Player player = game.getPlayer(source.getControllerId());
@ -116,8 +119,6 @@ class MitoticManipulationEffect extends OneShotEffect<MitoticManipulationEffect>
player.lookAtCards("Mitotic Manipulation", cards, game); player.lookAtCards("Mitotic Manipulation", cards, game);
if (!cardsFound.isEmpty() && player.chooseUse(Outcome.PutCardInPlay, "Do you wish to put a card on the battlefield?", game)) { if (!cardsFound.isEmpty() && player.chooseUse(Outcome.PutCardInPlay, "Do you wish to put a card on the battlefield?", game)) {
FilterCard filter = new FilterCard("card to put onto the battlefield");
filter.getName().add(permanentNames);
TargetCard target = new TargetCard(Zone.PICK, filter); TargetCard target = new TargetCard(Zone.PICK, filter);
if (player.choose(Outcome.PutCardInPlay, cardsFound, target, game)) { if (player.choose(Outcome.PutCardInPlay, cardsFound, target, game)) {

View file

@ -41,6 +41,7 @@ import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.Filter; import mage.filter.Filter;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetCardInYourGraveyard; import mage.target.common.TargetCardInYourGraveyard;
@ -54,7 +55,7 @@ public class EverbarkShaman extends CardImpl<EverbarkShaman> {
private final static FilterCard filterTreefolk = new FilterCard("Treefolk from your graveyard"); private final static FilterCard filterTreefolk = new FilterCard("Treefolk from your graveyard");
static { static {
filterForest.getName().add("Forest"); filterForest.add(new NamePredicate("Forest"));
filterTreefolk.getSubtype().add("Treefolk"); filterTreefolk.getSubtype().add("Treefolk");
filterTreefolk.setScopeSubtype(Filter.ComparisonScope.Any); filterTreefolk.setScopeSubtype(Filter.ComparisonScope.Any);
} }

View file

@ -40,6 +40,7 @@ import mage.cards.CardImpl;
import mage.cards.Cards; import mage.cards.Cards;
import mage.cards.CardsImpl; import mage.cards.CardsImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInGraveyard; import mage.target.common.TargetCardInGraveyard;
@ -104,7 +105,7 @@ class SurgicalExtractionEffect extends OneShotEffect<SurgicalExtractionEffect> {
Player targetPlayer = game.getPlayer(card.getOwnerId()); Player targetPlayer = game.getPlayer(card.getOwnerId());
if (targetPlayer != null) { if (targetPlayer != null) {
FilterCard filter = new FilterCard("card named " + card.getName()); FilterCard filter = new FilterCard("card named " + card.getName());
filter.getName().add(card.getName()); filter.add(new NamePredicate(card.getName()));
Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY); Cards cardsInLibrary = new CardsImpl(Zone.LIBRARY);
cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game)); cardsInLibrary.addAll(targetPlayer.getLibrary().getCards(game));

View file

@ -36,6 +36,7 @@ import mage.abilities.costs.common.SacrificeTargetCost;
import mage.abilities.keyword.AnnihilatorAbility; import mage.abilities.keyword.AnnihilatorAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetControlledPermanent; import mage.target.common.TargetControlledPermanent;
/** /**
@ -48,7 +49,7 @@ public class HandOfEmrakul extends CardImpl<HandOfEmrakul> {
private static final FilterControlledPermanent filter = new FilterControlledPermanent("Eldrazi Spawn"); private static final FilterControlledPermanent filter = new FilterControlledPermanent("Eldrazi Spawn");
static { static {
filter.getName().add("Eldrazi Spawn"); filter.add(new NamePredicate("Eldrazi Spawn"));
} }
public HandOfEmrakul(UUID ownerId) { public HandOfEmrakul(UUID ownerId) {

View file

@ -36,13 +36,15 @@ import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.mana.ManaCostsImpl; import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.common.RegenerateTargetEffect;
import mage.abilities.effects.common.continious.BoostControlledEffect; import mage.abilities.effects.common.continious.BoostControlledEffect;
import mage.abilities.effects.common.continious.GainAbilityControlledEffect; import mage.abilities.effects.common.continious.GainAbilityControlledEffect;
import mage.abilities.effects.common.RegenerateTargetEffect;
import mage.abilities.keyword.TrampleAbility; import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledCreaturePermanent;
/** /**
@ -59,8 +61,7 @@ public class EzuriRenegadeLeader extends CardImpl<EzuriRenegadeLeader> {
elfFilter.setMessage("Elf creatures"); elfFilter.setMessage("Elf creatures");
notEzuri.getSubtype().add("Elf"); notEzuri.getSubtype().add("Elf");
notEzuri.getName().add("Ezuri, Renegade Leader"); notEzuri.add(Predicates.not(new NamePredicate("Ezuri, Renegade Leader")));
notEzuri.setNotName(true);
} }
public EzuriRenegadeLeader(UUID ownerId) { public EzuriRenegadeLeader(UUID ownerId) {

View file

@ -45,6 +45,7 @@ import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandCard; import mage.filter.common.FilterLandCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -132,7 +133,7 @@ class SameNameAsExiledCountValue implements DynamicValue {
Permanent permanent = game.getPermanent(sourceAbility.getSourceId()); Permanent permanent = game.getPermanent(sourceAbility.getSourceId());
if (permanent != null && permanent.getImprinted().size() > 0) { if (permanent != null && permanent.getImprinted().size() > 0) {
FilterPermanent filterPermanent = new FilterPermanent(); FilterPermanent filterPermanent = new FilterPermanent();
filterPermanent.getName().add(game.getCard(permanent.getImprinted().get(0)).getName()); filterPermanent.add(new NamePredicate(game.getCard(permanent.getImprinted().get(0)).getName()));
value = game.getBattlefield().countAll(filterPermanent, game); value = game.getBattlefield().countAll(filterPermanent, game);
} }
return value; return value;

View file

@ -42,6 +42,7 @@ import mage.abilities.effects.common.search.SearchLibraryPutInPlayEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import mage.target.common.TargetControlledCreaturePermanent; import mage.target.common.TargetControlledCreaturePermanent;
@ -63,10 +64,8 @@ public class AngelsHerald extends CardImpl<AngelsHerald> {
filterWhite.setUseColor(true); filterWhite.setUseColor(true);
filterBlue.getColor().setBlue(true); filterBlue.getColor().setBlue(true);
filterBlue.setUseColor(true); filterBlue.setUseColor(true);
}
static { filter.add(new NamePredicate("Empyrial Archangel"));
filter.getName().add("Empyrial Archangel");
} }
public AngelsHerald(UUID ownerId) { public AngelsHerald(UUID ownerId) {

View file

@ -39,6 +39,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
@ -113,8 +114,8 @@ class ClarionUltimatumEffect extends OneShotEffect<ClarionUltimatumEffect> {
sb.append("Search for ").append(cardName).append(" in your library?"); sb.append("Search for ").append(cardName).append(" in your library?");
if (player.chooseUse(Outcome.PutCardInPlay, sb.toString(), game)) { if (player.chooseUse(Outcome.PutCardInPlay, sb.toString(), game)) {
FilterCard filter = new FilterCard("card named" + cardName); FilterCard filter = new FilterCard("card named " + cardName);
filter.getName().add(cardName); filter.add(new NamePredicate(cardName));
TargetCardInLibrary target = new TargetCardInLibrary(filter); TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (player.searchLibrary(target, game)) { if (player.searchLibrary(target, game)) {

View file

@ -28,6 +28,7 @@
package mage.sets.shardsofalara; package mage.sets.shardsofalara;
import java.util.UUID;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.Constants.Outcome; import mage.Constants.Outcome;
import mage.Constants.Rarity; import mage.Constants.Rarity;
@ -39,11 +40,10 @@ import mage.abilities.keyword.FirstStrikeAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterLandPermanent; import mage.filter.common.FilterLandPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
import java.util.UUID;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -80,7 +80,7 @@ class KnightOfTheWhiteOrchidAbility extends ZoneChangeTriggeredAbility<KnightOfT
private static final FilterLandPermanent filter2 = new FilterLandPermanent(); private static final FilterLandPermanent filter2 = new FilterLandPermanent();
static { static {
filter1.getName().add("Plains"); filter1.add(new NamePredicate("Plains"));
} }
public KnightOfTheWhiteOrchidAbility() { public KnightOfTheWhiteOrchidAbility() {

View file

@ -33,6 +33,7 @@ import mage.Constants.Rarity;
import mage.abilities.effects.common.DestroyAllEffect; import mage.abilities.effects.common.DestroyAllEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
/** /**
* *
@ -43,7 +44,7 @@ public class Boil extends CardImpl<Boil> {
private final static FilterPermanent filter = new FilterPermanent("islands"); private final static FilterPermanent filter = new FilterPermanent("islands");
static { static {
filter.getName().add("Island"); filter.add(new NamePredicate("Island"));
} }
public Boil(UUID ownerId) { public Boil(UUID ownerId) {

View file

@ -42,6 +42,7 @@ import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.ContinuousEffectImpl; import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
@ -54,7 +55,7 @@ public class RelentlessRats extends CardImpl<RelentlessRats> {
private final static FilterCreaturePermanent filter = new FilterCreaturePermanent(); private final static FilterCreaturePermanent filter = new FilterCreaturePermanent();
static { static {
filter.getName().add("Relentless Rats"); filter.add(new NamePredicate("Relentless Rats"));
} }
public RelentlessRats(UUID ownerId) { public RelentlessRats(UUID ownerId) {

View file

@ -50,6 +50,7 @@ import mage.abilities.keyword.TrampleAbility;
import mage.cards.Card; import mage.cards.Card;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
@ -155,7 +156,7 @@ class GigantiformEffect extends OneShotEffect<GigantiformEffect> {
private static final FilterCard filter = new FilterCard("card named Gigantiform"); private static final FilterCard filter = new FilterCard("card named Gigantiform");
static { static {
filter.getName().add("Gigantiform"); filter.add(new NamePredicate("Gigantiform"));
} }
public GigantiformEffect() { public GigantiformEffect() {

View file

@ -41,6 +41,7 @@ import mage.cards.CardImpl;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.filter.FilterCard; import mage.filter.FilterCard;
import mage.filter.common.FilterControlledCreaturePermanent; import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCardInLibrary; import mage.target.common.TargetCardInLibrary;
@ -51,14 +52,12 @@ import mage.target.common.TargetCardInLibrary;
*/ */
public class NissaRevane extends CardImpl<NissaRevane> { public class NissaRevane extends CardImpl<NissaRevane> {
private static final FilterCard nissasChosenFilter = new FilterCard(); private static final FilterCard nissasChosenFilter = new FilterCard("card named Nissa's Chosen");
private static final FilterCard elfFilter = new FilterCard(); private static final FilterCard elfFilter = new FilterCard("Elf creature cards");
static { static {
nissasChosenFilter.getName().add("Nissa's Chosen"); nissasChosenFilter.add(new NamePredicate("Nissa's Chosen"));
nissasChosenFilter.setMessage("card named Nissa's Chosen");
elfFilter.getSubtype().add("Elf"); elfFilter.getSubtype().add("Elf");
elfFilter.setMessage("Elf creature cards");
} }
public NissaRevane(UUID ownerId) { public NissaRevane(UUID ownerId) {

View file

@ -51,6 +51,7 @@ import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.UUID; import java.util.UUID;
import mage.filter.predicate.mageobject.NamePredicate;
/** /**
* *
@ -134,7 +135,7 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
String command = action.getAction(); String command = action.getAction();
command = command.substring(command.indexOf("attack:") + 7); command = command.substring(command.indexOf("attack:") + 7);
FilterCreatureForCombat filter = new FilterCreatureForCombat(); FilterCreatureForCombat filter = new FilterCreatureForCombat();
filter.getName().add(command); filter.add(new NamePredicate(command));
Permanent attacker = findPermanent(filter, playerId, game); Permanent attacker = findPermanent(filter, playerId, game);
if (attacker != null && attacker.canAttack(game)) { if (attacker != null && attacker.canAttack(game)) {
this.declareAttacker(attacker.getId(), opponentId, game); this.declareAttacker(attacker.getId(), opponentId, game);
@ -152,11 +153,11 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
command = command.substring(command.indexOf("block:") + 6); command = command.substring(command.indexOf("block:") + 6);
String[] groups = command.split(";"); String[] groups = command.split(";");
FilterCreatureForCombat filterBlocker = new FilterCreatureForCombat(); FilterCreatureForCombat filterBlocker = new FilterCreatureForCombat();
filterBlocker.getName().add(groups[0]); filterBlocker.add(new NamePredicate(groups[0]));
Permanent blocker = findPermanent(filterBlocker, playerId, game); Permanent blocker = findPermanent(filterBlocker, playerId, game);
if (blocker != null) { if (blocker != null) {
FilterAttackingCreature filterAttacker = new FilterAttackingCreature(); FilterAttackingCreature filterAttacker = new FilterAttackingCreature();
filterAttacker.getName().add(groups[1]); filterAttacker.add(new NamePredicate(groups[1]));
Permanent attacker = findPermanent(filterAttacker, opponentId, game); Permanent attacker = findPermanent(filterAttacker, opponentId, game);
if (attacker != null) { if (attacker != null) {
this.declareBlocker(blocker.getId(), attacker.getId(), game); this.declareBlocker(blocker.getId(), attacker.getId(), game);

View file

@ -3,6 +3,7 @@ package mage.abilities.dynamicvalue.common;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.dynamicvalue.DynamicValue; import mage.abilities.dynamicvalue.DynamicValue;
import mage.filter.common.FilterControlledPermanent; import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game; import mage.game.Game;
public class UrzaTerrainValue implements DynamicValue { public class UrzaTerrainValue implements DynamicValue {
@ -15,19 +16,19 @@ public class UrzaTerrainValue implements DynamicValue {
@Override @Override
public int calculate(Game game, Ability sourceAbility) { public int calculate(Game game, Ability sourceAbility) {
FilterControlledPermanent pp = new FilterControlledPermanent("Urza's Power Plant"); FilterControlledPermanent pp = new FilterControlledPermanent("Urza's Power Plant");
pp.getName().add("Urza's Power Plant"); pp.add(new NamePredicate("Urza's Power Plant"));
PermanentsOnBattlefieldCount ppP = new PermanentsOnBattlefieldCount(pp); PermanentsOnBattlefieldCount ppP = new PermanentsOnBattlefieldCount(pp);
if (ppP.calculate(game, sourceAbility) < 1) if (ppP.calculate(game, sourceAbility) < 1)
return 1; return 1;
FilterControlledPermanent to = new FilterControlledPermanent("Urza's Tower"); FilterControlledPermanent to = new FilterControlledPermanent("Urza's Tower");
to.getName().add("Urza's Tower"); to.add(new NamePredicate("Urza's Tower"));
PermanentsOnBattlefieldCount toP = new PermanentsOnBattlefieldCount(to); PermanentsOnBattlefieldCount toP = new PermanentsOnBattlefieldCount(to);
if (toP.calculate(game, sourceAbility) < 1) if (toP.calculate(game, sourceAbility) < 1)
return 1; return 1;
FilterControlledPermanent mi = new FilterControlledPermanent("Urza's Mine"); FilterControlledPermanent mi = new FilterControlledPermanent("Urza's Mine");
mi.getName().add("Urza's Mine"); mi.add(new NamePredicate("Urza's Mine"));
PermanentsOnBattlefieldCount miP = new PermanentsOnBattlefieldCount(mi); PermanentsOnBattlefieldCount miP = new PermanentsOnBattlefieldCount(mi);
if (miP.calculate(game, sourceAbility) < 1) if (miP.calculate(game, sourceAbility) < 1)
return 1; return 1;

View file

@ -28,20 +28,17 @@
package mage.abilities.effects.common.continious; package mage.abilities.effects.common.continious;
import mage.abilities.condition.common.ControlsPermanentCondition;
import mage.abilities.effects.WhileConditionContiniousEffect;
import mage.Constants.Duration; import mage.Constants.Duration;
import mage.Constants.Layer; import mage.Constants.Layer;
import mage.Constants.Outcome; import mage.Constants.Outcome;
import mage.Constants.SubLayer; import mage.Constants.SubLayer;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.condition.common.ControlsPermanentCondition;
import mage.abilities.effects.WhileConditionContiniousEffect;
import mage.filter.FilterPermanent; import mage.filter.FilterPermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import java.util.ArrayList;
import java.util.List;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -50,13 +47,13 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContiniousEffe
private int power; private int power;
private int toughness; private int toughness;
private List<String> filterDescription; private String filterDescription;
public BoostSourceWhileControlsEffect(FilterPermanent filter, int power, int toughness) { public BoostSourceWhileControlsEffect(FilterPermanent filter, int power, int toughness) {
super(Duration.WhileOnBattlefield, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, new ControlsPermanentCondition(filter), Outcome.BoostCreature); super(Duration.WhileOnBattlefield, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, new ControlsPermanentCondition(filter), Outcome.BoostCreature);
this.power = power; this.power = power;
this.toughness = toughness; this.toughness = toughness;
this.filterDescription = filter.getName(); this.filterDescription = filter.getMessage();
staticText = "{this} gets " + String.format("%1$+d/%2$+d", power, toughness) + " as long as you control a " + filterDescription; staticText = "{this} gets " + String.format("%1$+d/%2$+d", power, toughness) + " as long as you control a " + filterDescription;
} }
@ -64,8 +61,7 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContiniousEffe
super(effect); super(effect);
this.power = effect.power; this.power = effect.power;
this.toughness = effect.toughness; this.toughness = effect.toughness;
this.filterDescription = new ArrayList<String>(); this.filterDescription = effect.filterDescription;
this.filterDescription.addAll(effect.filterDescription);
} }
@Override @Override

View file

@ -28,18 +28,33 @@
package mage.filter; package mage.filter;
import mage.game.Game;
import java.io.Serializable; import java.io.Serializable;
import mage.filter.predicate.Predicate;
import mage.game.Game;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* @author North
*/ */
public interface Filter<E> extends Serializable { public interface Filter<E> extends Serializable {
public enum ComparisonType { public enum ComparisonType {
GreaterThan, Equal, LessThan
GreaterThan(">"),
Equal("=="),
LessThan("<");
private String text;
ComparisonType(String text) {
this.text = text;
}
@Override
public String toString() {
return text;
}
} }
public enum ComparisonScope { public enum ComparisonScope {
@ -47,9 +62,10 @@ public interface Filter<E> extends Serializable {
} }
public boolean match(E o, Game game); public boolean match(E o, Game game);
public void add(Predicate predicate);
public String getMessage(); public String getMessage();
public void setMessage(String message); public void setMessage(String message);
public void setNotFilter(boolean notFilter);
public Filter<E> copy(); public Filter<E> copy();

View file

@ -28,18 +28,23 @@
package mage.filter; package mage.filter;
import java.util.LinkedList;
import java.util.List;
import mage.Constants.CardType; import mage.Constants.CardType;
import mage.ObjectColor; import mage.filter.predicate.Predicate;
import mage.game.Game;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* @author North
*/ */
public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filter<E> { public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filter<E> {
protected static ListComparer<CardType> compCardType = new ListComparer<CardType>(); protected static ListComparer<CardType> compCardType = new ListComparer<CardType>();
protected static ListComparer<String> compString = new ListComparer<String>(); protected static ListComparer<String> compString = new ListComparer<String>();
protected List<Predicate> predicates = new LinkedList<Predicate>();
protected String message; protected String message;
protected boolean notFilter = false; protected boolean notFilter = false;
@ -53,6 +58,7 @@ public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filte
public FilterImpl(FilterImpl filter) { public FilterImpl(FilterImpl filter) {
this.message = filter.message; this.message = filter.message;
this.notFilter = filter.notFilter; this.notFilter = filter.notFilter;
this.predicates = new LinkedList<Predicate>(filter.predicates);
} }
protected boolean compareInts(int int1, int int2, ComparisonType type) { protected boolean compareInts(int int1, int int2, ComparisonType type) {
@ -73,11 +79,19 @@ public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filte
return true; return true;
} }
protected boolean compareColors(ObjectColor color1, ObjectColor color2, ComparisonScope scope) { @Override
if (scope == ComparisonScope.All) public boolean match(E e, Game game) {
return color2.equals(color1); for (int i = 0; i < predicates.size(); i++) {
else if (!predicates.get(i).apply(e, game)) {
return color2.contains(color1); return false;
}
}
return true;
}
@Override
public final void add(Predicate predicate) {
predicates.add(predicate);
} }
@Override @Override
@ -90,7 +104,6 @@ public abstract class FilterImpl<E, T extends FilterImpl<E, T>> implements Filte
this.message = message; this.message = message;
} }
@Override
public void setNotFilter(boolean notFilter) { public void setNotFilter(boolean notFilter) {
this.notFilter = notFilter; this.notFilter = notFilter;
} }

View file

@ -43,6 +43,7 @@ import java.util.List;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
* @author North
*/ */
public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> extends FilterImpl<E, T> implements Filter<E> { public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> extends FilterImpl<E, T> implements Filter<E> {
protected Abilities<Ability> abilities; protected Abilities<Ability> abilities;
@ -57,8 +58,6 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
protected ObjectColor color; protected ObjectColor color;
protected ComparisonScope scopeColor = ComparisonScope.Any; protected ComparisonScope scopeColor = ComparisonScope.Any;
protected boolean notColor; protected boolean notColor;
protected List<String> name = new ArrayList<String>();
protected boolean notName;
protected List<String> subtype = new ArrayList<String>(); protected List<String> subtype = new ArrayList<String>();
protected ComparisonScope scopeSubtype = ComparisonScope.All; protected ComparisonScope scopeSubtype = ComparisonScope.All;
protected boolean notSubtype; protected boolean notSubtype;
@ -102,8 +101,6 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
this.color = filter.color.copy(); this.color = filter.color.copy();
this.scopeColor = filter.scopeColor; this.scopeColor = filter.scopeColor;
this.notColor = filter.notColor; this.notColor = filter.notColor;
this.name.addAll(filter.name);
this.notName = filter.notName;
this.subtype.addAll(filter.subtype); this.subtype.addAll(filter.subtype);
this.scopeSubtype = filter.scopeSubtype; this.scopeSubtype = filter.scopeSubtype;
this.notSubtype = filter.notSubtype; this.notSubtype = filter.notSubtype;
@ -121,9 +118,7 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
@Override @Override
public boolean match(E object, Game game) { public boolean match(E object, Game game) {
if (!super.match(object, game)) {
if (name.size() > 0) {
if (name.contains(object.getName()) == notName)
return notFilter; return notFilter;
} }
@ -242,14 +237,6 @@ public class FilterObject<E extends MageObject, T extends FilterObject<E, T>> ex
this.notColor = notColor; this.notColor = notColor;
} }
public List<String> getName() {
return this.name;
}
public void setNotName(boolean notName) {
this.notName = notName;
}
public List<String> getSubtype() { public List<String> getSubtype() {
return this.subtype; return this.subtype;
} }

View file

@ -28,7 +28,12 @@
package mage.game; package mage.game;
import mage.Constants.*; import mage.Constants.CardType;
import mage.Constants.MultiplayerAttackOption;
import mage.Constants.Outcome;
import mage.Constants.PhaseStep;
import mage.Constants.RangeOfInfluence;
import mage.Constants.Zone;
import mage.MageObject; import mage.MageObject;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.ActivatedAbility; import mage.abilities.ActivatedAbility;
@ -52,6 +57,7 @@ import mage.counters.CounterType;
import mage.filter.Filter; import mage.filter.Filter;
import mage.filter.Filter.ComparisonScope; import mage.filter.Filter.ComparisonScope;
import mage.filter.common.*; import mage.filter.common.*;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.combat.Combat; import mage.game.combat.Combat;
import mage.game.command.CommandObject; import mage.game.command.CommandObject;
import mage.game.command.Emblem; import mage.game.command.Emblem;
@ -1045,7 +1051,7 @@ public abstract class GameImpl<T extends GameImpl<T>> implements Game, Serializa
if (legendary.size() > 1) { //don't bother checking if less than 2 legends in play if (legendary.size() > 1) { //don't bother checking if less than 2 legends in play
for (Permanent legend: legendary) { for (Permanent legend: legendary) {
FilterLegendaryPermanent filterLegendName = new FilterLegendaryPermanent(); FilterLegendaryPermanent filterLegendName = new FilterLegendaryPermanent();
filterLegendName.getName().add(legend.getName()); filterLegendName.add(new NamePredicate(legend.getName()));
if (getBattlefield().contains(filterLegendName, legend.getControllerId(), this, 2)) { if (getBattlefield().contains(filterLegendName, legend.getControllerId(), this, 2)) {
for (Permanent dupLegend: getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) { for (Permanent dupLegend: getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
dupLegend.moveToZone(Zone.GRAVEYARD, null, this, false); dupLegend.moveToZone(Zone.GRAVEYARD, null, this, false);

View file

@ -28,6 +28,9 @@
package mage.target.common; package mage.target.common;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
/** /**
* *
* @author BetaSteward_at_googlemail.com * @author BetaSteward_at_googlemail.com
@ -35,12 +38,11 @@ package mage.target.common;
public class TargetNonBasicLandPermanent extends TargetLandPermanent<TargetNonBasicLandPermanent> { public class TargetNonBasicLandPermanent extends TargetLandPermanent<TargetNonBasicLandPermanent> {
public TargetNonBasicLandPermanent() { public TargetNonBasicLandPermanent() {
filter.setNotName(true); filter.add(Predicates.not(new NamePredicate("Island")));
filter.getName().add("Island"); filter.add(Predicates.not(new NamePredicate("Forest")));
filter.getName().add("Forest"); filter.add(Predicates.not(new NamePredicate("Mountain")));
filter.getName().add("Mountain"); filter.add(Predicates.not(new NamePredicate("Swamp")));
filter.getName().add("Swamp"); filter.add(Predicates.not(new NamePredicate("Plains")));
filter.getName().add("Plains");
this.targetName = "nonbasic land"; this.targetName = "nonbasic land";
} }