[filters] Replaced Another condition with Predicate

This commit is contained in:
North 2012-07-15 17:18:33 +03:00
parent d66c172952
commit 021e2b59df
22 changed files with 100 additions and 49 deletions

View file

@ -37,6 +37,7 @@ import mage.abilities.effects.common.SacrificeEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import java.util.UUID;
@ -49,7 +50,7 @@ public class DemonicTaskmaster extends CardImpl<DemonicTaskmaster> {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("a creature other than Demonic Taskmaster");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public DemonicTaskmaster(UUID ownerId) {

View file

@ -37,6 +37,7 @@ import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.UndyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.common.TargetControlledPermanent;
import java.util.UUID;
@ -46,10 +47,10 @@ import java.util.UUID;
*/
public class DemonlordOfAshmouth extends CardImpl<DemonlordOfAshmouth> {
private static FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(" another creature");
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent(" another creature");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public DemonlordOfAshmouth(UUID ownerId) {

View file

@ -39,6 +39,7 @@ import mage.abilities.effects.OneShotEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -79,10 +80,10 @@ public class Fettergeist extends CardImpl<Fettergeist> {
class FettergeistUnlessPaysEffect extends OneShotEffect<FettergeistUnlessPaysEffect> {
private static FilterCreaturePermanent filter = new FilterCreaturePermanent();
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public FettergeistUnlessPaysEffect() {

View file

@ -36,6 +36,7 @@ import mage.abilities.effects.common.GainLifeEffect;
import mage.abilities.keyword.FlyingAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import java.util.UUID;
@ -46,10 +47,10 @@ import java.util.UUID;
*/
public class GoldnightRedeemer extends CardImpl<GoldnightRedeemer> {
private static FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("other creature you control");
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("other creature you control");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public GoldnightRedeemer(UUID ownerId) {

View file

@ -36,6 +36,7 @@ import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.effects.common.ReturnToHandTargetEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.common.TargetControlledCreaturePermanent;
@ -77,7 +78,7 @@ class HavengulSkaabAbility extends TriggeredAbilityImpl<HavengulSkaabAbility> {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another creature you control");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public HavengulSkaabAbility() {

View file

@ -40,6 +40,7 @@ import mage.abilities.effects.RestrictionEffect;
import mage.abilities.keyword.ShroudAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -68,7 +69,7 @@ public class HisokasGuard extends CardImpl<HisokasGuard> {
// {1}{U}, {T}: Target creature you control other than Hisoka's Guard has shroud for as long as Hisoka's Guard remains tapped. (It can't be the target of spells or abilities.)
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
filter.setAnother(true);
filter.add(new AnotherPredicate());
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new HisokasGuardGainAbilityTargetEffect(), new ManaCostsImpl("{1}{U}"));
ability.addCost(new TapSourceCost());
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true, true);

View file

@ -48,6 +48,7 @@ import mage.abilities.keyword.IndestructibleAbility;
import mage.cards.CardImpl;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.watchers.common.CastFromHandWatcher;
/**
@ -57,7 +58,7 @@ public class MyojinOfCleansingFire extends CardImpl<MyojinOfCleansingFire> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("other creatures");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public MyojinOfCleansingFire(UUID ownerId) {

View file

@ -27,6 +27,7 @@
*/
package mage.sets.innistrad;
import java.util.UUID;
import mage.Constants;
import mage.Constants.CardType;
import mage.Constants.Rarity;
@ -34,14 +35,13 @@ import mage.MageInt;
import mage.abilities.Ability;
import mage.abilities.common.EntersBattlefieldTriggeredAbility;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.target.Target;
import mage.target.TargetPermanent;
import java.util.UUID;
import mage.abilities.effects.common.ExileTargetForSourceEffect;
import mage.abilities.effects.common.ReturnFromExileForSourceEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.Target;
import mage.target.TargetPermanent;
/**
* @author nantuko
@ -50,7 +50,7 @@ public class FiendHunter extends CardImpl<FiendHunter> {
private static final FilterCreaturePermanent filter = new FilterCreaturePermanent();
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public FiendHunter(UUID ownerId) {

View file

@ -45,6 +45,7 @@ import mage.cards.CardImpl;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.target.common.TargetControlledCreaturePermanent;
@ -59,7 +60,7 @@ public class GrimgrinCorpseBorn extends CardImpl<GrimgrinCorpseBorn> {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("another creature");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public GrimgrinCorpseBorn(UUID ownerId) {

View file

@ -45,6 +45,7 @@ import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl;
import mage.counters.CounterType;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
@ -58,7 +59,7 @@ public class MikaeusTheLunarch extends CardImpl<MikaeusTheLunarch> {
private static final FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent();
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public MikaeusTheLunarch(UUID ownerId) {

View file

@ -45,6 +45,7 @@ import mage.cards.CardImpl;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.common.TargetCreaturePermanent;
/**
@ -57,7 +58,7 @@ public class OliviaVoldaren extends CardImpl<OliviaVoldaren> {
private static final FilterCreaturePermanent vampireFilter = new FilterCreaturePermanent("Vampire");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
vampireFilter.add(new SubtypePredicate("Vampire"));
}

View file

@ -41,6 +41,7 @@ import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.mageobject.SubtypePredicate;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.common.TargetControlledCreaturePermanent;
import java.util.UUID;
@ -56,7 +57,7 @@ public class MadAuntie extends CardImpl<MadAuntie> {
static {
filter1.add(new SubtypePredicate("Goblin"));
filter1.setAnother(true);
filter1.add(new AnotherPredicate());
filter2.add(new SubtypePredicate("Goblin"));
}

View file

@ -42,6 +42,7 @@ import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl;
import mage.filter.common.FilterControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player;
@ -107,7 +108,7 @@ class XathridDemonEffect extends OneShotEffect<XathridDemonEffect> {
}
FilterControlledCreaturePermanent filter = new FilterControlledCreaturePermanent("creature other than " + sourcePermanent.getName());
filter.setAnother(true);
filter.add(new AnotherPredicate());
Target target = new TargetControlledCreaturePermanent(1, 1, filter, true, true);
if (target.canChoose(source.getSourceId(), player.getId(), game)) {

View file

@ -41,6 +41,7 @@ import mage.abilities.keyword.FlyingAbility;
import mage.abilities.keyword.IndestructibleAbility;
import mage.cards.CardImpl;
import mage.filter.FilterPermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.Target;
import mage.target.TargetPermanent;
@ -58,7 +59,7 @@ public class AegisAngel extends CardImpl<AegisAngel> {
this.toughness = new MageInt(5);
this.addAbility(FlyingAbility.getInstance());
FilterPermanent filter = new FilterPermanent("another target permanent");
filter.setAnother(true);
filter.add(new AnotherPredicate());
Ability ability = new EntersBattlefieldTriggeredAbility(new GainAbilityTargetEffect(IndestructibleAbility.getInstance(), Constants.Duration.WhileOnBattlefield), false);
Target target = new TargetPermanent(filter);
target.setRequired(true);

View file

@ -40,6 +40,7 @@ import mage.abilities.effects.ContinuousEffectImpl;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetCreaturePermanent;
@ -52,7 +53,7 @@ public class Cryptoplasm extends CardImpl<Cryptoplasm> {
final static FilterCreaturePermanent filter = new FilterCreaturePermanent();
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public Cryptoplasm(UUID ownerId) {

View file

@ -43,6 +43,7 @@ import mage.game.events.GameEvent;
import mage.game.permanent.token.Token;
import java.util.UUID;
import mage.filter.predicate.permanent.AnotherPredicate;
/**
*
@ -92,7 +93,7 @@ class ThopterAssemblyTriggeredAbility extends TriggeredAbilityImpl<ThopterAssemb
if (event.getType() == GameEvent.EventType.UPKEEP_STEP_PRE && event.getPlayerId().equals(this.controllerId)) {
FilterPermanent filter = new FilterPermanent();
filter.add(new SubtypePredicate("Thopter"));
filter.setAnother(true);
filter.add(new AnotherPredicate());
if (!game.getBattlefield().contains(filter, controllerId, 1, game)) {
return true;
}

View file

@ -39,6 +39,7 @@ import mage.abilities.effects.common.ExileTargetForSourceEffect;
import mage.abilities.effects.common.ReturnFromExileForSourceEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterNonlandPermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.Target;
import mage.target.TargetPermanent;
@ -48,10 +49,10 @@ import mage.target.TargetPermanent;
*/
public class OblivionRing extends CardImpl<OblivionRing> {
private static FilterNonlandPermanent anotherNonlandPermanent = new FilterNonlandPermanent("another nonland permanent");
private static final FilterNonlandPermanent anotherNonlandPermanent = new FilterNonlandPermanent("another nonland permanent");
static {
anotherNonlandPermanent.setAnother(true);
anotherNonlandPermanent.add(new AnotherPredicate());
}
public OblivionRing(UUID ownerId) {

View file

@ -42,6 +42,7 @@ import mage.abilities.effects.common.MayTapOrUntapTargetEffect;
import mage.abilities.effects.common.UntapSourceEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.common.TargetCreaturePermanent;
/**
@ -50,11 +51,10 @@ import mage.target.common.TargetCreaturePermanent;
*/
public class TideforceElemental extends CardImpl<TideforceElemental> {
// private final static String text = "You may tap or untap another target creature";
private final static FilterCreaturePermanent filter = new FilterCreaturePermanent("another creature");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public TideforceElemental(UUID ownerId) {

View file

@ -39,6 +39,7 @@ import mage.abilities.effects.common.ExileTargetForSourceEffect;
import mage.abilities.effects.common.ReturnFromExileForSourceEffect;
import mage.cards.CardImpl;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.target.Target;
import mage.target.TargetPermanent;
@ -53,7 +54,7 @@ public class JourneyToNowhere extends CardImpl<JourneyToNowhere> {
this.expansionSetCode = "ZEN";
this.color.setWhite(true);
FilterCreaturePermanent filter = new FilterCreaturePermanent();
filter.setAnother(true);
filter.add(new AnotherPredicate());
Ability ability1 = new EntersBattlefieldTriggeredAbility(new ExileTargetForSourceEffect("Journey to Nowhere exile"), false);
Target target = new TargetPermanent(filter);
target.setRequired(true);

View file

@ -48,7 +48,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
protected boolean notController;
protected TargetController controller = TargetController.ANY;
protected TargetController owner = TargetController.ANY;
protected boolean another;
public FilterPermanent() {
super("permanent");
@ -60,7 +59,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
this.notController = filter.notController;
this.controller = filter.controller;
this.owner = filter.owner;
this.another = filter.another;
this.extraPredicates = new ArrayList<ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>>>(extraPredicates);
}
@ -117,13 +115,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
}
}
if (another) {
// filter out itself
if (permanent.getId().equals(sourceId)) {
return notFilter;
}
}
return Predicates.and(extraPredicates).apply(new ObjectSourcePlayer(permanent, sourceId, playerId), game);
}
@ -147,14 +138,6 @@ public class FilterPermanent extends FilterObject<Permanent> {
this.owner = owner;
}
public boolean isAnother() {
return another;
}
public void setAnother(boolean another) {
this.another = another;
}
public boolean matchController(UUID testControllerId) {
if (controllerId.size() > 0 && controllerId.contains(testControllerId) == notController)
return false;

View file

@ -0,0 +1,50 @@
/*
* Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are
* permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this list of
* conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright notice, this list
* of conditions and the following disclaimer in the documentation and/or other materials
* provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
* ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* The views and conclusions contained in the software and documentation are those of the
* authors and should not be interpreted as representing official policies, either expressed
* or implied, of BetaSteward_at_googlemail.com.
*/
package mage.filter.predicate.permanent;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
/**
*
* @author North
*/
public class AnotherPredicate implements ObjectSourcePlayerPredicate<ObjectSourcePlayer<Permanent>> {
@Override
public boolean apply(ObjectSourcePlayer<Permanent> input, Game game) {
return !input.getObject().getId().equals(input.getSourceId());
}
@Override
public String toString() {
return "Another";
}
}

View file

@ -34,6 +34,7 @@ import mage.abilities.keyword.SoulbondAbility;
import mage.cards.Cards;
import mage.cards.CardsImpl;
import mage.filter.common.FilterNotPairedControlledCreaturePermanent;
import mage.filter.predicate.permanent.AnotherPredicate;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent;
@ -49,10 +50,10 @@ import mage.watchers.WatcherImpl;
*/
public class SoulbondWatcher extends WatcherImpl<SoulbondWatcher> {
private static FilterNotPairedControlledCreaturePermanent filter = new FilterNotPairedControlledCreaturePermanent("another not paired creature you control");
private static final FilterNotPairedControlledCreaturePermanent filter = new FilterNotPairedControlledCreaturePermanent("another not paired creature you control");
static {
filter.setAnother(true);
filter.add(new AnotherPredicate());
}
public SoulbondWatcher() {