[filters] replaced custom filters with predicates

This commit is contained in:
North 2012-07-22 17:35:39 +03:00
parent 0197c16cd7
commit 9cb5e61c34
2 changed files with 31 additions and 16 deletions

View file

@ -29,6 +29,7 @@
package mage.filter.common;
import mage.abilities.keyword.DefenderAbility;
import mage.filter.predicate.Predicate;
import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.AbilityPredicate;
import mage.filter.predicate.permanent.AttackingPredicate;
@ -40,6 +41,7 @@ import mage.game.permanent.Permanent;
/**
*
* @author BetaSteward_at_googlemail.com
* @author North
*/
public class FilterCreatureForAttack extends FilterCreaturePermanent {
@ -53,22 +55,28 @@ public class FilterCreatureForAttack extends FilterCreaturePermanent {
this.add(Predicates.not(new BlockingPredicate()));
this.add(Predicates.not(new TappedPredicate()));
this.add(Predicates.not(new AbilityPredicate(DefenderAbility.class)));
this.add(new CanTapPredicate());
}
public FilterCreatureForAttack(final FilterCreatureForAttack filter) {
super(filter);
}
@Override
public boolean match(Permanent permanent, Game game) {
if (!super.match(permanent, game))
return notFilter;
return permanent.canTap();
}
@Override
public FilterCreatureForAttack copy() {
return new FilterCreatureForAttack(this);
}
}
class CanTapPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return input.canTap();
}
@Override
public String toString() {
return "CanTap";
}
}

View file

@ -38,6 +38,7 @@ import mage.game.permanent.Permanent;
/**
*
* @author BetaSteward_at_googlemail.com
* @author North
*/
public class FilterCreatureForCombat extends FilterCreaturePermanent {
@ -50,20 +51,13 @@ public class FilterCreatureForCombat extends FilterCreaturePermanent {
this.add(Predicates.not(new AttackingPredicate()));
this.add(Predicates.not(new TappedPredicate()));
this.add(new PhasedInPredicate());
this.add(new CanBlockPredicate());
}
public FilterCreatureForCombat(final FilterCreatureForCombat filter) {
super(filter);
}
@Override
public boolean match(Permanent permanent, Game game) {
if (!super.match(permanent, game))
return notFilter;
return permanent.getMaxBlocks() == 0 || permanent.getBlocking() < permanent.getMaxBlocks();
}
@Override
public FilterCreatureForCombat copy() {
return new FilterCreatureForCombat(this);
@ -82,3 +76,16 @@ class PhasedInPredicate implements Predicate<Permanent> {
return "PhasedIn";
}
}
class CanBlockPredicate implements Predicate<Permanent> {
@Override
public boolean apply(Permanent input, Game game) {
return input.getMaxBlocks() == 0 || input.getBlocking() < input.getMaxBlocks();
}
@Override
public String toString() {
return "CanBlock";
}
}