From 61b5f8555e9923e8b6530a3bb5366dabf52fff5e Mon Sep 17 00:00:00 2001 From: North Date: Sun, 22 Jul 2012 13:19:08 +0300 Subject: [PATCH] [filters] added BlockedPredicate --- .../src/mage/sets/riseoftheeldrazi/Smite.java | 8 +++- .../permanent/BlockedPredicate.java} | 38 ++++++------------- 2 files changed, 17 insertions(+), 29 deletions(-) rename Mage/src/mage/filter/{common/FilterBlockedCreature.java => predicate/permanent/BlockedPredicate.java} (72%) diff --git a/Mage.Sets/src/mage/sets/riseoftheeldrazi/Smite.java b/Mage.Sets/src/mage/sets/riseoftheeldrazi/Smite.java index 980687a5efa..2e1c0861161 100644 --- a/Mage.Sets/src/mage/sets/riseoftheeldrazi/Smite.java +++ b/Mage.Sets/src/mage/sets/riseoftheeldrazi/Smite.java @@ -32,8 +32,8 @@ import mage.Constants.CardType; import mage.Constants.Rarity; import mage.abilities.effects.common.DestroyTargetEffect; import mage.cards.CardImpl; -import mage.filter.common.FilterBlockedCreature; import mage.filter.common.FilterCreaturePermanent; +import mage.filter.predicate.permanent.BlockedPredicate; import mage.target.common.TargetCreaturePermanent; /** @@ -42,7 +42,11 @@ import mage.target.common.TargetCreaturePermanent; */ public class Smite extends CardImpl { - private static final FilterCreaturePermanent filter = new FilterBlockedCreature(); + private static final FilterCreaturePermanent filter = new FilterCreaturePermanent("blocked creature"); + + static { + filter.add(new BlockedPredicate()); + } public Smite(UUID ownerId) { super(ownerId, 43, "Smite", Rarity.COMMON, new CardType[]{CardType.INSTANT}, "{W}"); diff --git a/Mage/src/mage/filter/common/FilterBlockedCreature.java b/Mage/src/mage/filter/predicate/permanent/BlockedPredicate.java similarity index 72% rename from Mage/src/mage/filter/common/FilterBlockedCreature.java rename to Mage/src/mage/filter/predicate/permanent/BlockedPredicate.java index eb89dcbcbd5..ff7a711322b 100644 --- a/Mage/src/mage/filter/common/FilterBlockedCreature.java +++ b/Mage/src/mage/filter/predicate/permanent/BlockedPredicate.java @@ -25,8 +25,9 @@ * authors and should not be interpreted as representing official policies, either expressed * or implied, of BetaSteward_at_googlemail.com. */ -package mage.filter.common; +package mage.filter.predicate.permanent; +import mage.filter.predicate.Predicate; import mage.game.Game; import mage.game.combat.CombatGroup; import mage.game.permanent.Permanent; @@ -35,37 +36,20 @@ import mage.game.permanent.Permanent; * * @author North */ -public class FilterBlockedCreature extends FilterCreaturePermanent { - - public FilterBlockedCreature() { - this("blocked creature"); - } - - public FilterBlockedCreature(String name) { - super(name); - } - - public FilterBlockedCreature(final FilterBlockedCreature filter) { - super(filter); - } +public class BlockedPredicate implements Predicate { @Override - public FilterBlockedCreature copy() { - return new FilterBlockedCreature(this); - } - - @Override - public boolean match(Permanent permanent, Game game) { - if (!super.match(permanent, game)) { - return notFilter; - } - + public boolean apply(Permanent input, Game game) { for (CombatGroup combatGroup : game.getCombat().getGroups()) { - if (!combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(permanent.getId())) { - return !notFilter; + if (!combatGroup.getBlockers().isEmpty() && combatGroup.getAttackers().contains(input.getId())) { + return true; } } + return false; + } - return notFilter; + @Override + public String toString() { + return "Blocked"; } }