move CounterPredicate to be within CounterType class

This commit is contained in:
Evan Kranzler 2020-09-12 20:48:13 -04:00
parent b5370ecf32
commit 8876d39491
109 changed files with 162 additions and 277 deletions

View file

@ -10,7 +10,6 @@ import mage.abilities.effects.Effect;
import mage.constants.TargetController;
import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.CounterPredicate;
/**
*
@ -22,7 +21,7 @@ public class BountyAbility extends DiesCreatureTriggeredAbility {
static {
bountyCounterFilter.add(TargetController.OPPONENT.getControllerPredicate());
bountyCounterFilter.add(new CounterPredicate(CounterType.BOUNTY));
bountyCounterFilter.add(CounterType.BOUNTY.getPredicate());
}
public BountyAbility(Effect effect) {

View file

@ -1,6 +1,9 @@
package mage.counters;
import mage.abilities.keyword.*;
import mage.cards.Card;
import mage.filter.predicate.Predicate;
import mage.game.Game;
/**
* Enum for counters, names and instances.
@ -160,10 +163,35 @@ public enum CounterType {
WIND("wind"),
WISH("wish");
private static class CounterPredicate implements Predicate<Card> {
private final CounterType counter;
private CounterPredicate(CounterType counter) {
this.counter = counter;
}
@Override
public boolean apply(Card input, Game game) {
if (counter == null) {
return !input.getCounters(game).keySet().isEmpty();
} else {
return input.getCounters(game).containsKey(counter);
}
}
@Override
public String toString() {
return "CounterType(" + counter.getName() + ')';
}
}
private final String name;
private final CounterPredicate predicate;
CounterType(String name) {
this.name = name;
this.predicate = new CounterPredicate(this);
}
/**
@ -249,4 +277,8 @@ public enum CounterType {
}
return null;
}
public CounterPredicate getPredicate() {
return predicate;
}
}

View file

@ -1,37 +0,0 @@
package mage.filter.predicate.permanent;
import mage.cards.Card;
import mage.counters.CounterType;
import mage.filter.predicate.Predicate;
import mage.game.Game;
/**
*
* @author jeffwadsworth
*/
public class CounterPredicate implements Predicate<Card> {
private final CounterType counter;
/**
*
* @param counter if null any counter selects the permanent
*/
public CounterPredicate(CounterType counter) {
this.counter = counter;
}
@Override
public boolean apply(Card input, Game game) {
if (counter == null) {
return !input.getCounters(game).keySet().isEmpty();
} else {
return input.getCounters(game).containsKey(counter);
}
}
@Override
public String toString() {
return "CounterType(" + counter.getName() + ')';
}
}