new RemoveAllCountersAllEffect

This commit is contained in:
xenohedron 2024-06-02 03:18:38 -04:00
parent 21f1aa559b
commit 3497facd6b
4 changed files with 59 additions and 139 deletions

View file

@ -1,11 +1,9 @@
package mage.cards.a;
import mage.abilities.Ability;
import mage.abilities.TriggeredAbilityImpl;
import mage.abilities.common.DealsDamageToYouAllTriggeredAbility;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleStaticAbility;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.RemoveAllCountersAllEffect;
import mage.abilities.effects.common.continuous.BecomesSubtypeAllEffect;
import mage.abilities.effects.common.continuous.GainAbilityAllEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
@ -14,11 +12,8 @@ import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.*;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.game.permanent.Permanent;
import mage.target.targetpointer.FixedTarget;
import java.util.Arrays;
import java.util.UUID;
@ -41,7 +36,8 @@ public final class Aurification extends CardImpl {
super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{2}{W}{W}");
// Whenever a creature deals damage to you, put a gold counter on it.
this.addAbility(new AddGoldCountersAbility());
this.addAbility(new DealsDamageToYouAllTriggeredAbility(StaticFilters.FILTER_PERMANENT_CREATURE,
new AddCountersTargetEffect(CounterType.GOLD.createInstance()).setText("put a gold counter on it")));
// Each creature with a gold counter on it is a Wall in addition to its other creature types and has defender.
BecomesSubtypeAllEffect becomesSubtypeAllEffect = new BecomesSubtypeAllEffect(Duration.WhileOnBattlefield, Arrays.asList(SubType.WALL), filter, false);
@ -51,7 +47,8 @@ public final class Aurification extends CardImpl {
this.addAbility(new SimpleStaticAbility(Zone.BATTLEFIELD, new GainAbilityAllEffect(DefenderAbility.getInstance(), Duration.WhileOnBattlefield, filter, rule)));
// When Aurification leaves the battlefield, remove all gold counters from all creatures.
this.addAbility(new LeavesBattlefieldTriggeredAbility(new RemoveAllGoldCountersEffect(), false));
this.addAbility(new LeavesBattlefieldTriggeredAbility(new RemoveAllCountersAllEffect(
CounterType.GOLD, StaticFilters.FILTER_PERMANENT_CREATURES), false));
}
private Aurification(final Aurification card) {
@ -62,71 +59,4 @@ public final class Aurification extends CardImpl {
public Aurification copy() {
return new Aurification(this);
}
public static class AddGoldCountersAbility extends TriggeredAbilityImpl {
public AddGoldCountersAbility() {
super(Zone.BATTLEFIELD, new AddCountersTargetEffect(CounterType.GOLD.createInstance()));
}
private AddGoldCountersAbility(final AddGoldCountersAbility ability) {
super(ability);
}
@Override
public AddGoldCountersAbility copy() {
return new AddGoldCountersAbility(this);
}
@Override
public boolean checkEventType(GameEvent event, Game game) {
return event.getType() == GameEvent.EventType.DAMAGED_PLAYER;
}
@Override
public boolean checkTrigger(GameEvent event, Game game) {
if (event.getPlayerId().equals(this.getControllerId())) {
Permanent permanent = game.getPermanent(event.getSourceId());
if (permanent != null && permanent.isCreature(game)) {
for (Effect effect : this.getEffects()) {
effect.setTargetPointer(new FixedTarget(event.getSourceId(), game));
}
return true;
}
}
return false;
}
@Override
public String getRule() {
return "Whenever a creature deals damage to you, put a gold counter on it.";
}
}
public static class RemoveAllGoldCountersEffect extends OneShotEffect {
public RemoveAllGoldCountersEffect() {
super(Outcome.Neutral);
this.staticText = "remove all gold counters from all creatures";
}
private RemoveAllGoldCountersEffect(final RemoveAllGoldCountersEffect effect) {
super(effect);
}
@Override
public RemoveAllGoldCountersEffect copy() {
return new RemoveAllGoldCountersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game)) {
if (permanent != null) {
permanent.removeAllCounters(CounterType.GOLD.getName(), source, game);
}
}
return true;
}
}
}
}

View file

@ -7,19 +7,17 @@ import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
import mage.abilities.common.SimpleActivatedAbility;
import mage.abilities.costs.common.TapSourceCost;
import mage.abilities.costs.mana.ManaCostsImpl;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.DestroyTargetEffect;
import mage.abilities.effects.common.RemoveAllCountersAllEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.filter.common.FilterLandPermanent;
import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.target.common.TargetLandPermanent;
import java.util.UUID;
@ -52,7 +50,8 @@ public final class MineLayer extends CardImpl {
this.addAbility(new BecomesTappedTriggeredAbility(new DestroyTargetEffect().setText("destroy it"), false, filter, true));
// When Mine Layer leaves the battlefield, remove all mine counters from all lands.
this.addAbility(new LeavesBattlefieldTriggeredAbility(new RemoveAllMineCountersEffect(), false));
this.addAbility(new LeavesBattlefieldTriggeredAbility(new RemoveAllCountersAllEffect(
CounterType.MINE, StaticFilters.FILTER_LANDS), false));
}
private MineLayer(final MineLayer card) {
@ -64,30 +63,3 @@ public final class MineLayer extends CardImpl {
return new MineLayer(this);
}
}
class RemoveAllMineCountersEffect extends OneShotEffect {
RemoveAllMineCountersEffect() {
super(Outcome.Neutral);
this.staticText = "remove all mine counters from all lands";
}
private RemoveAllMineCountersEffect(final RemoveAllMineCountersEffect effect) {
super(effect);
}
@Override
public RemoveAllMineCountersEffect copy() {
return new RemoveAllMineCountersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(CardType.LAND, game)) {
if (permanent != null) {
permanent.removeAllCounters(CounterType.MINE.getName(), source, game);
}
}
return true;
}
}

View file

@ -6,16 +6,16 @@ import mage.abilities.common.BeginningOfUpkeepTriggeredAbility;
import mage.abilities.common.LeavesBattlefieldTriggeredAbility;
import mage.abilities.dynamicvalue.DynamicValue;
import mage.abilities.effects.Effect;
import mage.abilities.effects.OneShotEffect;
import mage.abilities.effects.common.CreateTokenEffect;
import mage.abilities.effects.common.RemoveAllCountersAllEffect;
import mage.abilities.effects.common.counter.AddCountersTargetEffect;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.TargetController;
import mage.constants.Zone;
import mage.counters.CounterType;
import mage.filter.StaticFilters;
import mage.filter.common.FilterCreaturePermanent;
import mage.filter.predicate.permanent.TokenPredicate;
import mage.game.Game;
@ -51,7 +51,8 @@ public final class Sporogenesis extends CardImpl {
this.addAbility(new SporogenesisTriggeredAbility());
// When Sporogenesis leaves the battlefield, remove all fungus counters from all creatures.
this.addAbility(new LeavesBattlefieldTriggeredAbility(new SporogenesisRemoveCountersEffect(), false));
this.addAbility(new LeavesBattlefieldTriggeredAbility(new RemoveAllCountersAllEffect(
CounterType.FUNGUS, StaticFilters.FILTER_PERMANENT_CREATURES), false));
}
private Sporogenesis(final Sporogenesis card) {
@ -66,7 +67,7 @@ public final class Sporogenesis extends CardImpl {
class SporogenesisTriggeredAbility extends TriggeredAbilityImpl {
public SporogenesisTriggeredAbility() {
SporogenesisTriggeredAbility() {
super(Zone.BATTLEFIELD, new CreateTokenEffect(new SaprolingToken(), new SporogenesisCount()), false);
}
@ -132,28 +133,3 @@ class SporogenesisCount implements DynamicValue {
return "fungus counter on that creature";
}
}
class SporogenesisRemoveCountersEffect extends OneShotEffect {
SporogenesisRemoveCountersEffect() {
super(Outcome.Neutral);
staticText = "remove all fungus counters from all creatures";
}
private SporogenesisRemoveCountersEffect(final SporogenesisRemoveCountersEffect effect) {
super(effect);
}
@Override
public SporogenesisRemoveCountersEffect copy() {
return new SporogenesisRemoveCountersEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
for (Permanent permanent : game.getBattlefield().getAllActivePermanents(CardType.CREATURE, game)) {
permanent.removeAllCounters(CounterType.FUNGUS.getName(), source, game);
}
return true;
}
}

View file

@ -0,0 +1,42 @@
package mage.abilities.effects.common;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.constants.Outcome;
import mage.counters.CounterType;
import mage.filter.FilterPermanent;
import mage.game.Game;
/**
* @author xenohedron
*/
public class RemoveAllCountersAllEffect extends OneShotEffect {
private final CounterType counterType;
private final FilterPermanent filter;
public RemoveAllCountersAllEffect(CounterType counterType, FilterPermanent filter) {
super(Outcome.Neutral);
this.counterType = counterType;
this.filter = filter;
staticText = "remove all " + counterType.getName() + " counters from all " + filter.getMessage();
}
protected RemoveAllCountersAllEffect(final RemoveAllCountersAllEffect effect) {
super(effect);
this.counterType = effect.counterType;
this.filter = effect.filter;
}
@Override
public RemoveAllCountersAllEffect copy() {
return new RemoveAllCountersAllEffect(this);
}
@Override
public boolean apply(Game game, Ability source) {
game.getBattlefield().getActivePermanents(filter, source.getControllerId(), source, game)
.forEach(p -> p.removeAllCounters(counterType.getName(), source, game));
return true;
}
}