refactor: new predicate for mana value equal to counters on source

This commit is contained in:
xenohedron 2025-05-31 16:01:36 -04:00
parent 00084bfd7d
commit fc1d5ce4cf
9 changed files with 128 additions and 290 deletions

View file

@ -23,7 +23,11 @@ public class DestroyAllEffect extends OneShotEffect {
super(Outcome.DestroyPermanent);
this.filter = filter;
this.noRegen = noRegen;
this.staticText = "destroy all " + filter.getMessage() + (noRegen ? ". They can't be regenerated" : "");
String filterMessage = filter.getMessage();
if (!filterMessage.startsWith("each") && !filterMessage.startsWith("all")) {
filterMessage = "all " + filterMessage;
}
this.staticText = "destroy " + filterMessage + (noRegen ? ". They can't be regenerated" : "");
}
protected DestroyAllEffect(final DestroyAllEffect effect) {

View file

@ -0,0 +1,36 @@
package mage.filter.predicate.mageobject;
import mage.MageObject;
import mage.counters.CounterType;
import mage.filter.predicate.ObjectSourcePlayer;
import mage.filter.predicate.ObjectSourcePlayerPredicate;
import mage.game.Game;
import java.util.Optional;
/**
* @author xenohedron
*/
public class ManaValueEqualToCountersSourceCountPredicate implements ObjectSourcePlayerPredicate<MageObject> {
private final CounterType counterType;
public ManaValueEqualToCountersSourceCountPredicate(CounterType counterType) {
this.counterType = counterType;
}
@Override
public boolean apply(ObjectSourcePlayer<MageObject> input, Game game) {
return Optional
.ofNullable(input.getSource().getSourcePermanentOrLKI(game))
.map(permanent -> permanent.getCounters(game))
.map(counters -> counters.getCount(counterType))
.orElse(-1) // always false
.equals(input.getObject().getManaValue());
}
@Override
public String toString() {
return "mana value equal to the number of " + counterType.getName() + " counters on {this}";
}
}