reworked implementation of Ashling the Pilgrim and similar cards, added a test

This commit is contained in:
Evan Kranzler 2020-04-27 18:33:57 -04:00
parent ae20bb36a4
commit 4d1f37d0fe
5 changed files with 243 additions and 136 deletions

View file

@ -1,7 +1,5 @@
package mage.cards.a; package mage.cards.a;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
@ -11,16 +9,21 @@ import mage.abilities.effects.common.DamageEverythingEffect;
import mage.abilities.effects.common.counter.AddCountersSourceEffect; import mage.abilities.effects.common.counter.AddCountersSourceEffect;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.*; import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.SubType;
import mage.constants.SuperType;
import mage.counters.CounterType; import mage.counters.CounterType;
import mage.filter.common.FilterCreaturePermanent; import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent; import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.watchers.common.AbilityResolvedWatcher;
import java.util.UUID;
/** /**
* * @author TheElk801
* @author LevelX2
*/ */
public final class AshlingThePilgrim extends CardImpl { public final class AshlingThePilgrim extends CardImpl {
@ -34,12 +37,14 @@ public final class AshlingThePilgrim extends CardImpl {
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// {1}{R}: Put a +1/+1 counter on Ashling the Pilgrim. If this is the third time this ability has resolved this turn, remove all +1/+1 counters from Ashling the Pilgrim, and it deals that much damage to each creature and each player. // {1}{R}: Put a +1/+1 counter on Ashling the Pilgrim. If this is the third time this ability has resolved this turn, remove all +1/+1 counters from Ashling the Pilgrim, and it deals that much damage to each creature and each player.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new AddCountersSourceEffect(CounterType.P1P1.createInstance(), true), new ManaCostsImpl("{1}{R}")); Ability ability = new SimpleActivatedAbility(
new AddCountersSourceEffect(CounterType.P1P1.createInstance()), new ManaCostsImpl("{1}{R}")
);
ability.addEffect(new AshlingThePilgrimEffect()); ability.addEffect(new AshlingThePilgrimEffect());
this.addAbility(ability); this.addAbility(ability, new AbilityResolvedWatcher());
} }
public AshlingThePilgrim(final AshlingThePilgrim card) { private AshlingThePilgrim(final AshlingThePilgrim card) {
super(card); super(card);
} }
@ -51,18 +56,13 @@ public final class AshlingThePilgrim extends CardImpl {
class AshlingThePilgrimEffect extends OneShotEffect { class AshlingThePilgrimEffect extends OneShotEffect {
static class ActivationInfo { AshlingThePilgrimEffect() {
public int zoneChangeCounter;
public int turn;
public int activations;
}
public AshlingThePilgrimEffect() {
super(Outcome.Damage); super(Outcome.Damage);
this.staticText = "If this is the third time this ability has resolved this turn, remove all +1/+1 counters from {this}, and it deals that much damage to each creature and each player"; this.staticText = "If this is the third time this ability has resolved this turn, " +
"remove all +1/+1 counters from {this}, and it deals that much damage to each creature and each player";
} }
public AshlingThePilgrimEffect(final AshlingThePilgrimEffect effect) { private AshlingThePilgrimEffect(final AshlingThePilgrimEffect effect) {
super(effect); super(effect);
} }
@ -75,32 +75,18 @@ class AshlingThePilgrimEffect extends OneShotEffect {
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); Permanent sourcePermanent = game.getPermanent(source.getSourceId());
if (controller != null && sourcePermanent != null) { AbilityResolvedWatcher watcher = game.getState().getWatcher(AbilityResolvedWatcher.class);
ActivationInfo info; if (controller == null
Object object = game.getState().getValue(source.getSourceId() + "ActivationInfo"); || sourcePermanent == null
if (object instanceof ActivationInfo) { || watcher == null
info = (ActivationInfo) object; || !watcher.checkActivations(source, game)) {
if (info.turn != game.getTurnNum() || sourcePermanent.getZoneChangeCounter(game) != info.zoneChangeCounter) {
info.turn = game.getTurnNum();
info.zoneChangeCounter = sourcePermanent.getZoneChangeCounter(game);
info.activations = 0;
}
} else {
info = new ActivationInfo();
info.turn = game.getTurnNum();
info.zoneChangeCounter = sourcePermanent.getZoneChangeCounter(game);
game.getState().setValue(source.getSourceId() + "ActivationInfo", info);
}
info.activations++;
if (info.activations == 3) {
int damage = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
if (damage > 0) {
sourcePermanent.removeCounters(CounterType.P1P1.getName(), damage, game);
return new DamageEverythingEffect(damage, new FilterCreaturePermanent()).apply(game, source);
}
}
return true;
}
return false; return false;
} }
int counters = sourcePermanent.getCounters(game).getCount(CounterType.P1P1);
if (counters < 1) {
return false;
}
sourcePermanent.removeCounters(CounterType.P1P1.createInstance(counters), game);
return new DamageEverythingEffect(counters, StaticFilters.FILTER_PERMANENT_CREATURE).apply(game, source);
}
} }

View file

@ -1,7 +1,5 @@
package mage.cards.i; package mage.cards.i;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.abilities.Ability; import mage.abilities.Ability;
import mage.abilities.common.SimpleActivatedAbility; import mage.abilities.common.SimpleActivatedAbility;
@ -13,17 +11,18 @@ import mage.abilities.keyword.FirstStrikeAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.SubType;
import mage.filter.StaticFilters;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.watchers.common.AbilityResolvedWatcher;
import java.util.UUID;
/** /**
* * @author TheElk801
* @author LevelX2
*/ */
public final class InnerFlameIgniter extends CardImpl { public final class InnerFlameIgniter extends CardImpl {
@ -35,12 +34,14 @@ public final class InnerFlameIgniter extends CardImpl {
this.toughness = new MageInt(2); this.toughness = new MageInt(2);
// {2}{R}: Creatures you control get +1/+0 until end of turn. If this is the third time this ability has resolved this turn, creatures you control gain first strike until end of turn. // {2}{R}: Creatures you control get +1/+0 until end of turn. If this is the third time this ability has resolved this turn, creatures you control gain first strike until end of turn.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new BoostControlledEffect(1,0,Duration.EndOfTurn), new ManaCostsImpl("{2}{R}")); Ability ability = new SimpleActivatedAbility(
new BoostControlledEffect(1, 0, Duration.EndOfTurn), new ManaCostsImpl("{2}{R}")
);
ability.addEffect(new InnerFlameIgniterEffect()); ability.addEffect(new InnerFlameIgniterEffect());
this.addAbility(ability); this.addAbility(ability, new AbilityResolvedWatcher());
} }
public InnerFlameIgniter(final InnerFlameIgniter card) { private InnerFlameIgniter(final InnerFlameIgniter card) {
super(card); super(card);
} }
@ -52,18 +53,13 @@ public final class InnerFlameIgniter extends CardImpl {
class InnerFlameIgniterEffect extends OneShotEffect { class InnerFlameIgniterEffect extends OneShotEffect {
static class ActivationInfo { InnerFlameIgniterEffect() {
public int zoneChangeCounter; super(Outcome.AddAbility);
public int turn; this.staticText = "If this is the third time this ability has resolved this turn, " +
public int activations; "creatures you control gain first strike until end of turn";
} }
public InnerFlameIgniterEffect() { private InnerFlameIgniterEffect(final InnerFlameIgniterEffect effect) {
super(Outcome.Damage);
this.staticText = "If this is the third time this ability has resolved this turn, creatures you control gain first strike until end of turn";
}
public InnerFlameIgniterEffect(final InnerFlameIgniterEffect effect) {
super(effect); super(effect);
} }
@ -75,29 +71,16 @@ class InnerFlameIgniterEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); AbilityResolvedWatcher watcher = game.getState().getWatcher(AbilityResolvedWatcher.class);
if (controller != null && sourcePermanent != null) { if (controller == null
ActivationInfo info; || watcher == null
Object object = game.getState().getValue(source.getSourceId() + "ActivationInfo"); || !watcher.checkActivations(source, game)) {
if (object instanceof ActivationInfo) {
info = (ActivationInfo) object;
if (info.turn != game.getTurnNum() || sourcePermanent.getZoneChangeCounter(game) != info.zoneChangeCounter) {
info.turn = game.getTurnNum();
info.zoneChangeCounter = sourcePermanent.getZoneChangeCounter(game);
info.activations = 0;
}
} else {
info = new ActivationInfo();
info.turn = game.getTurnNum();
info.zoneChangeCounter = sourcePermanent.getZoneChangeCounter(game);
game.getState().setValue(source.getSourceId() + "ActivationInfo", info);
}
info.activations++;
if (info.activations == 3) {
game.addEffect(new GainAbilityControlledEffect(FirstStrikeAbility.getInstance(), Duration.EndOfTurn), source);
}
return true;
}
return false; return false;
} }
game.addEffect(new GainAbilityControlledEffect(
FirstStrikeAbility.getInstance(), Duration.EndOfTurn,
StaticFilters.FILTER_PERMANENT_CREATURE
), source);
return true;
}
} }

View file

@ -1,7 +1,5 @@
package mage.cards.s; package mage.cards.s;
import java.util.UUID;
import mage.MageInt; import mage.MageInt;
import mage.Mana; import mage.Mana;
import mage.abilities.Ability; import mage.abilities.Ability;
@ -13,18 +11,18 @@ import mage.abilities.keyword.TrampleAbility;
import mage.cards.CardImpl; import mage.cards.CardImpl;
import mage.cards.CardSetInfo; import mage.cards.CardSetInfo;
import mage.constants.CardType; import mage.constants.CardType;
import mage.constants.SubType;
import mage.constants.Duration; import mage.constants.Duration;
import mage.constants.Outcome; import mage.constants.Outcome;
import mage.constants.Zone; import mage.constants.SubType;
import mage.game.Game; import mage.game.Game;
import mage.game.permanent.Permanent;
import mage.players.Player; import mage.players.Player;
import mage.target.common.TargetCreaturePermanent; import mage.target.common.TargetCreaturePermanent;
import mage.watchers.common.AbilityResolvedWatcher;
import java.util.UUID;
/** /**
* * @author TheElk801
* @author LevelX2
*/ */
public final class SoulbrightFlamekin extends CardImpl { public final class SoulbrightFlamekin extends CardImpl {
@ -36,13 +34,15 @@ public final class SoulbrightFlamekin extends CardImpl {
this.toughness = new MageInt(1); this.toughness = new MageInt(1);
// {2}: Target creature gains trample until end of turn. If this is the third time this ability has resolved this turn, you may add {R}{R}{R}{R}{R}{R}{R}{R}. // {2}: Target creature gains trample until end of turn. If this is the third time this ability has resolved this turn, you may add {R}{R}{R}{R}{R}{R}{R}{R}.
Ability ability = new SimpleActivatedAbility(Zone.BATTLEFIELD, new GainAbilityTargetEffect(TrampleAbility.getInstance(), Duration.EndOfTurn), new ManaCostsImpl("{2}")); Ability ability = new SimpleActivatedAbility(new GainAbilityTargetEffect(
TrampleAbility.getInstance(), Duration.EndOfTurn
), new ManaCostsImpl("{2}"));
ability.addEffect(new SoulbrightFlamekinEffect()); ability.addEffect(new SoulbrightFlamekinEffect());
ability.addTarget(new TargetCreaturePermanent()); ability.addTarget(new TargetCreaturePermanent());
this.addAbility(ability); this.addAbility(ability, new AbilityResolvedWatcher());
} }
public SoulbrightFlamekin(final SoulbrightFlamekin card) { private SoulbrightFlamekin(final SoulbrightFlamekin card) {
super(card); super(card);
} }
@ -54,18 +54,13 @@ public final class SoulbrightFlamekin extends CardImpl {
class SoulbrightFlamekinEffect extends OneShotEffect { class SoulbrightFlamekinEffect extends OneShotEffect {
static class ActivationInfo { SoulbrightFlamekinEffect() {
public int zoneChangeCounter;
public int turn;
public int activations;
}
public SoulbrightFlamekinEffect() {
super(Outcome.Damage); super(Outcome.Damage);
this.staticText = "If this is the third time this ability has resolved this turn, you may add {R}{R}{R}{R}{R}{R}{R}{R}"; this.staticText = "If this is the third time this ability has resolved this turn, " +
"you may add {R}{R}{R}{R}{R}{R}{R}{R}";
} }
public SoulbrightFlamekinEffect(final SoulbrightFlamekinEffect effect) { private SoulbrightFlamekinEffect(final SoulbrightFlamekinEffect effect) {
super(effect); super(effect);
} }
@ -77,29 +72,14 @@ class SoulbrightFlamekinEffect extends OneShotEffect {
@Override @Override
public boolean apply(Game game, Ability source) { public boolean apply(Game game, Ability source) {
Player controller = game.getPlayer(source.getControllerId()); Player controller = game.getPlayer(source.getControllerId());
Permanent sourcePermanent = game.getPermanent(source.getSourceId()); AbilityResolvedWatcher watcher = game.getState().getWatcher(AbilityResolvedWatcher.class);
if (controller != null && sourcePermanent != null) { if (controller == null
ActivationInfo info; || watcher == null
Object object = game.getState().getValue(source.getSourceId() + "ActivationInfo"); || !watcher.checkActivations(source, game)
if (object instanceof ActivationInfo) { || !controller.chooseUse(Outcome.PutManaInPool, "Add {R}{R}{R}{R}{R}{R}{R}{R}}?", source, game)) {
info = (ActivationInfo) object;
if (info.turn != game.getTurnNum() || sourcePermanent.getZoneChangeCounter(game) != info.zoneChangeCounter) {
info.turn = game.getTurnNum();
info.zoneChangeCounter = sourcePermanent.getZoneChangeCounter(game);
info.activations = 0;
}
} else {
info = new ActivationInfo();
info.turn = game.getTurnNum();
info.zoneChangeCounter = sourcePermanent.getZoneChangeCounter(game);
game.getState().setValue(source.getSourceId() + "ActivationInfo", info);
}
info.activations++;
if (info.activations == 3) {
controller.getManaPool().addMana(Mana.RedMana(8), game, source);
}
return true;
}
return false; return false;
} }
controller.getManaPool().addMana(Mana.RedMana(8), game, source);
return true;
}
} }

View file

@ -0,0 +1,118 @@
package org.mage.test.cards.single.lrw;
import mage.constants.PhaseStep;
import mage.constants.Zone;
import mage.counters.CounterType;
import org.junit.Test;
import org.mage.test.serverside.base.CardTestPlayerBase;
/**
* @author TheElk801
*/
public class AshlingThePilgrimTest extends CardTestPlayerBase {
private static final String ashling = "Ashling the Pilgrim";
private static final String ashAbility = "{1}{R}: ";
private static final String cshift = "Cloudshift";
@Test
public void testAshling() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 6);
addCard(Zone.BATTLEFIELD, playerA, ashling);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, ashling, 0);
assertLife(playerA, 17);
}
@Test
public void testAshlingMultipleTurns() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 8);
addCard(Zone.BATTLEFIELD, playerA, ashling);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
setStopAt(2, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, ashling, 1);
assertCounterCount(ashling, CounterType.P1P1, 4);
assertLife(playerA, 20);
}
@Test
public void testAshlingMultipleTurns2() {
addCard(Zone.BATTLEFIELD, playerA, "Mountain", 14);
addCard(Zone.BATTLEFIELD, playerA, ashling);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(2, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
setStopAt(3, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, ashling, 0);
assertLife(playerA, 13);
}
@Test
public void testBlinkedAshling() {
addCard(Zone.BATTLEFIELD, playerA, "Plateau", 7);
addCard(Zone.BATTLEFIELD, playerA, ashling);
addCard(Zone.HAND, playerA, cshift);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, cshift, ashling);
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ashAbility);
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ashAbility);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, ashling, 1);
assertCounterCount(ashling, CounterType.P1P1, 2);
assertLife(playerA, 20);
}
@Test
public void testBlinkedAshling2() {
addCard(Zone.BATTLEFIELD, playerA, "Plateau", 9);
addCard(Zone.BATTLEFIELD, playerA, ashling);
addCard(Zone.HAND, playerA, cshift);
activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, ashAbility);
waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN);
castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, cshift, ashling);
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ashAbility);
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ashAbility);
waitStackResolved(1, PhaseStep.POSTCOMBAT_MAIN);
activateAbility(1, PhaseStep.POSTCOMBAT_MAIN, playerA, ashAbility);
setStopAt(1, PhaseStep.END_TURN);
execute();
assertAllCommandsUsed();
assertPermanentCount(playerA, ashling, 0);
assertLife(playerA, 17);
}
}

View file

@ -0,0 +1,40 @@
package mage.watchers.common;
import mage.MageObjectReference;
import mage.abilities.Ability;
import mage.constants.WatcherScope;
import mage.game.Game;
import mage.game.events.GameEvent;
import mage.watchers.Watcher;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
/**
* @author TheElk801
*/
public class AbilityResolvedWatcher extends Watcher {
private final Map<MageObjectReference, Map<UUID, Integer>> activationMap = new HashMap<>();
public AbilityResolvedWatcher() {
super(WatcherScope.GAME);
}
@Override
public void watch(GameEvent event, Game game) {
}
@Override
public void reset() {
super.reset();
activationMap.clear();
}
public boolean checkActivations(Ability source, Game game) {
return activationMap.computeIfAbsent(new MageObjectReference(
source.getSourceId(), source.getSourceObjectZoneChangeCounter(), game
), x -> new HashMap<>()).compute(source.getOriginalId(), (u, i) -> i == null ? 1 : i + 1).intValue() == 3;
}
}