- little refactor of Hero of Bretagard condition

This commit is contained in:
jeffwadsworth 2021-02-01 17:40:33 -06:00
parent 98f1ed0a4c
commit 03979f77bb
2 changed files with 193 additions and 195 deletions

View file

@ -5,6 +5,7 @@ import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl; import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.SimpleStaticAbility; import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.condition.common.SourceHasAnyCountersCondition;
import mage.abilities.condition.common.SourceMatchesFilterCondition; import mage.abilities.condition.common.SourceMatchesFilterCondition;
import mage.abilities.decorator.ConditionalContinuousEffect; import mage.abilities.decorator.ConditionalContinuousEffect;
import mage.abilities.effects.Effect; import mage.abilities.effects.Effect;
@ -27,8 +28,6 @@ import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game; import mage.game.Game;
import mage.game.events.GameEvent; import mage.game.events.GameEvent;
import mage.game.events.ZoneChangeEvent; import mage.game.events.ZoneChangeEvent;
import mage.game.permanent.Permanent;
import mage.filter.predicate.Predicate;
/** /**
* @author jeffwadsworth * @author jeffwadsworth
@ -39,8 +38,8 @@ public final class HeroOfBretagard extends CardImpl {
private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent(); private static final FilterCreaturePermanent filter2 = new FilterCreaturePermanent();
static { static {
filter.add(test1.instance); filter.add(new SourceHasAnyCountersCondition(5));
filter2.add(test2.instance); filter2.add(new SourceHasAnyCountersCondition(10));
} }
public HeroOfBretagard(UUID ownerId, CardSetInfo setInfo) { public HeroOfBretagard(UUID ownerId, CardSetInfo setInfo) {
@ -165,31 +164,3 @@ class HeroOfBretagardEffect extends OneShotEffect {
return new AddCountersSourceEffect(CounterType.P1P1.createInstance((Integer) this.getValue("number"))).apply(game, source); return new AddCountersSourceEffect(CounterType.P1P1.createInstance((Integer) this.getValue("number"))).apply(game, source);
} }
} }
enum test1 implements Predicate<Permanent> {
instance;
@Override
public boolean apply(Permanent input, Game game) {
return input.getCounters(game).values().stream().anyMatch(counter -> counter.getCount() > 4);
}
@Override
public String toString() {
return "any counter";
}
}
enum test2 implements Predicate<Permanent> {
instance;
@Override
public boolean apply(Permanent input, Game game) {
return input.getCounters(game).values().stream().anyMatch(counter -> counter.getCount() > 9);
}
@Override
public String toString() {
return "any counter";
}
}

View file

@ -0,0 +1,27 @@
package mage.abilities.condition.common;
import mage.filter.predicate.Predicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
// @author jeffwadsworth
public class SourceHasAnyCountersCondition implements Predicate<Permanent> {
final int count;
public SourceHasAnyCountersCondition(int count) {
this.count = count;
}
@Override
public boolean apply(Permanent input, Game game) {
return input.getCounters(game).values().stream().anyMatch(counter -> counter.getCount() >= count);
}
@Override
public String toString() {
return "any counter";
}
}