[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.ChoiceImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.sets.Sets;
@ -119,7 +120,7 @@ class MindblazeEffect extends OneShotEffect<MindblazeEffect> {
cards.addAll(player.getLibrary().getCards(game));
playerControls.revealCards("Library", cards, game);
FilterCard filter = new FilterCard();
filter.getName().add(cardChoice.getChoice());
filter.add(new NamePredicate(cardChoice.getChoice()));
int count = Integer.parseInt(numberChoice.getChoice());
if (player.getLibrary().count(filter, game) == count) {
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.CardImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
@ -105,8 +107,7 @@ class CurseOfMisfortunesEffect extends OneShotEffect<CurseOfMisfortunesEffect> {
for (UUID attachmentId: targetPlayer.getAttachments()) {
Permanent attachment = game.getPermanent(attachmentId);
if (attachment != null && attachment.getSubtype().contains("Curse")) {
filter.getName().add(attachment.getName());
filter.setNotName(true);
filter.add(Predicates.not(new NamePredicate(attachment.getName())));
}
}

View file

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

View file

@ -44,6 +44,7 @@ import mage.target.common.TargetCardInLibrary;
import java.util.List;
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);
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);
TargetCardInLibrary target = new TargetCardInLibrary(count, count, filterCard);
target.setRequired(true);

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.common.search.SearchLibraryRevealPutInHandEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
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");
static {
filter.getName().add("Squadron Hawk");
filter.add(new NamePredicate("Squadron Hawk"));
}
public SquadronHawk(UUID ownerId) {

View file

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

View file

@ -45,6 +45,7 @@ import mage.target.common.TargetCardInLibrary;
import java.util.ArrayList;
import java.util.List;
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)) {
FilterCreatureCard filter = new FilterCreatureCard("creature card named" + creatureName);
filter.getName().add(creatureName);
filter.add(new NamePredicate(creatureName));
TargetCardInLibrary target = new TargetCardInLibrary(filter);
if (player.searchLibrary(target, game)) {

View file

@ -41,6 +41,7 @@ import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -91,8 +92,10 @@ class MitoticManipulationEffect extends OneShotEffect<MitoticManipulationEffect>
public boolean apply(Game game, Ability source) {
List<Permanent> permanents = game.getBattlefield().getActivePermanents(source.getControllerId(), game);
HashSet<String> permanentNames = new HashSet<String>();
FilterCard filter = new FilterCard("card to put onto the battlefield");
for (Permanent permanent : permanents) {
permanentNames.add(permanent.getName());
filter.add(new NamePredicate(permanent.getName()));
}
Player player = game.getPlayer(source.getControllerId());
@ -116,8 +119,6 @@ class MitoticManipulationEffect extends OneShotEffect<MitoticManipulationEffect>
player.lookAtCards("Mitotic Manipulation", cards, 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);
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.filter.Filter;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetCardInLibrary;
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");
static {
filterForest.getName().add("Forest");
filterForest.add(new NamePredicate("Forest"));
filterTreefolk.getSubtype().add("Treefolk");
filterTreefolk.setScopeSubtype(Filter.ComparisonScope.Any);
}

View file

@ -40,6 +40,7 @@ import mage.cards.CardImpl;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.filter.FilterCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
import mage.players.Player;
import mage.target.common.TargetCardInGraveyard;
@ -104,7 +105,7 @@ class SurgicalExtractionEffect extends OneShotEffect<SurgicalExtractionEffect> {
Player targetPlayer = game.getPlayer(card.getOwnerId());
if (targetPlayer != null) {
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);
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.cards.CardImpl;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.target.common.TargetControlledPermanent;
/**
@ -48,7 +49,7 @@ public class HandOfEmrakul extends CardImpl<HandOfEmrakul> {
private static final FilterControlledPermanent filter = new FilterControlledPermanent("Eldrazi Spawn");
static {
filter.getName().add("Eldrazi Spawn");
filter.add(new NamePredicate("Eldrazi Spawn"));
}
public HandOfEmrakul(UUID ownerId) {

View file

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

View file

@ -45,6 +45,7 @@ import mage.cards.Card;
import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
import mage.filter.common.FilterLandCard;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -132,7 +133,7 @@ class SameNameAsExiledCountValue implements DynamicValue {
Permanent permanent = game.getPermanent(sourceAbility.getSourceId());
if (permanent != null && permanent.getImprinted().size() > 0) {
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);
}
return value;

View file

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

View file

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

View file

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

View file

@ -33,6 +33,7 @@ import mage.Constants.Rarity;
import mage.abilities.effects.common.DestroyAllEffect;
import mage.cards.CardImpl;
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");
static {
filter.getName().add("Island");
filter.add(new NamePredicate("Island"));
}
public Boil(UUID ownerId) {

View file

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

View file

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

View file

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

View file

@ -51,6 +51,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import mage.filter.predicate.mageobject.NamePredicate;
/**
*
@ -134,7 +135,7 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
String command = action.getAction();
command = command.substring(command.indexOf("attack:") + 7);
FilterCreatureForCombat filter = new FilterCreatureForCombat();
filter.getName().add(command);
filter.add(new NamePredicate(command));
Permanent attacker = findPermanent(filter, playerId, game);
if (attacker != null && attacker.canAttack(game)) {
this.declareAttacker(attacker.getId(), opponentId, game);
@ -152,11 +153,11 @@ public class TestPlayer extends ComputerPlayer<TestPlayer> {
command = command.substring(command.indexOf("block:") + 6);
String[] groups = command.split(";");
FilterCreatureForCombat filterBlocker = new FilterCreatureForCombat();
filterBlocker.getName().add(groups[0]);
filterBlocker.add(new NamePredicate(groups[0]));
Permanent blocker = findPermanent(filterBlocker, playerId, game);
if (blocker != null) {
FilterAttackingCreature filterAttacker = new FilterAttackingCreature();
filterAttacker.getName().add(groups[1]);
filterAttacker.add(new NamePredicate(groups[1]));
Permanent attacker = findPermanent(filterAttacker, opponentId, game);
if (attacker != null) {
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.dynamicvalue.DynamicValue;
import mage.filter.common.FilterControlledPermanent;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.Game;
public class UrzaTerrainValue implements DynamicValue {
@ -15,19 +16,19 @@ public class UrzaTerrainValue implements DynamicValue {
@Override
public int calculate(Game game, Ability sourceAbility) {
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);
if (ppP.calculate(game, sourceAbility) < 1)
return 1;
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);
if (toP.calculate(game, sourceAbility) < 1)
return 1;
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);
if (miP.calculate(game, sourceAbility) < 1)
return 1;

View file

@ -28,20 +28,17 @@
package mage.abilities.effects.common.continious;
import mage.abilities.condition.common.ControlsPermanentCondition;
import mage.abilities.effects.WhileConditionContiniousEffect;
import mage.Constants.Duration;
import mage.Constants.Layer;
import mage.Constants.Outcome;
import mage.Constants.SubLayer;
import mage.abilities.Ability;
import mage.abilities.condition.common.ControlsPermanentCondition;
import mage.abilities.effects.WhileConditionContiniousEffect;
import mage.filter.FilterPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import java.util.ArrayList;
import java.util.List;
/**
*
* @author BetaSteward_at_googlemail.com
@ -50,13 +47,13 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContiniousEffe
private int power;
private int toughness;
private List<String> filterDescription;
private String filterDescription;
public BoostSourceWhileControlsEffect(FilterPermanent filter, int power, int toughness) {
super(Duration.WhileOnBattlefield, Layer.PTChangingEffects_7, SubLayer.ModifyPT_7c, new ControlsPermanentCondition(filter), Outcome.BoostCreature);
this.power = power;
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;
}
@ -64,8 +61,7 @@ public class BoostSourceWhileControlsEffect extends WhileConditionContiniousEffe
super(effect);
this.power = effect.power;
this.toughness = effect.toughness;
this.filterDescription = new ArrayList<String>();
this.filterDescription.addAll(effect.filterDescription);
this.filterDescription = effect.filterDescription;
}
@Override

View file

@ -28,18 +28,33 @@
package mage.filter;
import mage.game.Game;
import java.io.Serializable;
import mage.filter.predicate.Predicate;
import mage.game.Game;
/**
*
* @author BetaSteward_at_googlemail.com
* @author North
*/
public interface Filter<E> extends Serializable {
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 {
@ -47,9 +62,10 @@ public interface Filter<E> extends Serializable {
}
public boolean match(E o, Game game);
public void add(Predicate predicate);
public String getMessage();
public void setMessage(String message);
public void setNotFilter(boolean notFilter);
public Filter<E> copy();

View file

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

View file

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

View file

@ -28,7 +28,12 @@
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.abilities.Ability;
import mage.abilities.ActivatedAbility;
@ -52,6 +57,7 @@ import mage.counters.CounterType;
import mage.filter.Filter;
import mage.filter.Filter.ComparisonScope;
import mage.filter.common.*;
import mage.filter.predicate.mageobject.NamePredicate;
import mage.game.combat.Combat;
import mage.game.command.CommandObject;
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
for (Permanent legend: legendary) {
FilterLegendaryPermanent filterLegendName = new FilterLegendaryPermanent();
filterLegendName.getName().add(legend.getName());
filterLegendName.add(new NamePredicate(legend.getName()));
if (getBattlefield().contains(filterLegendName, legend.getControllerId(), this, 2)) {
for (Permanent dupLegend: getBattlefield().getActivePermanents(filterLegendName, legend.getControllerId(), this)) {
dupLegend.moveToZone(Zone.GRAVEYARD, null, this, false);

View file

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