From 6530b404c8b4ed6c225e7c6d8cc31665f5166fe4 Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 29 Jul 2017 20:13:48 +0200 Subject: [PATCH] * Some Aftermath fixes. --- .../test/cards/single/akh/DuskDawnTest.java | 5 +- .../abilities/keyword/AftermathAbility.java | 79 ++++++++++++++++++- 2 files changed, 81 insertions(+), 3 deletions(-) diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/akh/DuskDawnTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/akh/DuskDawnTest.java index 067f5c040d5..d988ff98559 100644 --- a/Mage.Tests/src/test/java/org/mage/test/cards/single/akh/DuskDawnTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/akh/DuskDawnTest.java @@ -46,6 +46,10 @@ public class DuskDawnTest extends CardTestPlayerBase { @Test public void testCastDawnFromGraveyard() { + // Dusk + // Destroy all creatures with power 3 or greater. + // Dawn + // Return all creature cards with power less than or equal to 2 from your graveyard to your hand. addCard(Zone.GRAVEYARD, playerA, "Dusk // Dawn"); addCard(Zone.BATTLEFIELD, playerA, "Plains", 5); addCard(Zone.GRAVEYARD, playerA, "Devoted Hero"); @@ -85,5 +89,4 @@ public class DuskDawnTest extends CardTestPlayerBase { assertGraveyardCount(playerA, "Devoted Hero", 1); } - } diff --git a/Mage/src/main/java/mage/abilities/keyword/AftermathAbility.java b/Mage/src/main/java/mage/abilities/keyword/AftermathAbility.java index 35b374f513c..cd246dd20a8 100644 --- a/Mage/src/main/java/mage/abilities/keyword/AftermathAbility.java +++ b/Mage/src/main/java/mage/abilities/keyword/AftermathAbility.java @@ -31,11 +31,14 @@ import java.util.UUID; import mage.abilities.Ability; import mage.abilities.common.SimpleStaticAbility; import mage.abilities.effects.*; -import mage.abilities.effects.common.ExileSpellEffect; import mage.cards.Card; +import mage.cards.SplitCardHalf; import mage.constants.*; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.events.ZoneChangeEvent; +import mage.game.stack.Spell; +import mage.players.Player; /** * Aftermath @@ -52,7 +55,7 @@ public class AftermathAbility extends SimpleStaticAbility { public AftermathAbility() { super(Zone.ALL, new AftermathCastFromGraveyard()); addEffect(new AftermathCantCastFromHand()); - addEffect(ExileSpellEffect.getInstance()); + addEffect(new AftermathExileAsResolvesFromGraveyard()); } public AftermathAbility(final AftermathAbility ability) { @@ -141,3 +144,75 @@ class AftermathCantCastFromHand extends ContinuousRuleModifyingEffectImpl { return false; } } + +class AftermathExileAsResolvesFromGraveyard extends ReplacementEffectImpl { + + AftermathExileAsResolvesFromGraveyard() { + super(Duration.WhileOnStack, Outcome.Detriment); + this.staticText = "Exile it afterwards."; + } + + AftermathExileAsResolvesFromGraveyard(AftermathExileAsResolvesFromGraveyard effect) { + super(effect); + } + + @Override + public boolean checksEventType(GameEvent event, Game game) { + return event.getType() == GameEvent.EventType.ZONE_CHANGE; + } + + @Override + public boolean applies(GameEvent evt, Ability source, Game game) { + ZoneChangeEvent event = (ZoneChangeEvent) evt; + if (event.getFromZone() == Zone.STACK && event.getToZone() != Zone.EXILED) { + // Moving something from stack to somewhere else + + // Get the source id, getting the whole split card's ID, because + // that's the card that is changing zones in the event, but + // source.getSourceId is only the split card half. + // If branch so that we also support putting Aftermath on + // non-split cards for... whatever reason, in case somebody + // wants to do that in the future. + UUID sourceId = source.getSourceId(); + Card sourceCard = game.getCard(source.getSourceId()); + if (sourceCard != null && sourceCard instanceof SplitCardHalf) { + sourceCard = ((SplitCardHalf) sourceCard).getParentCard(); + sourceId = sourceCard.getId(); + } + + if (event.getTargetId() == sourceId) { + // Moving this spell from stack to yard + Spell spell = game.getStack().getSpell(source.getSourceId()); + if (spell != null && spell.getFromZone() == Zone.GRAVEYARD) { + // And this spell was cast from the graveyard, so we need to exile it + return true; + } + } + } + return false; + } + + @Override + public boolean replaceEvent(GameEvent event, Ability source, Game game) { + UUID sourceId = source.getSourceId(); + Card sourceCard = game.getCard(source.getSourceId()); + if (sourceCard != null && sourceCard instanceof SplitCardHalf) { + sourceCard = ((SplitCardHalf) sourceCard).getParentCard(); + sourceId = sourceCard.getId(); + } + + if (sourceCard != null) { + Player player = game.getPlayer(sourceCard.getOwnerId()); + if (player != null) { + return player.moveCardToExileWithInfo(sourceCard, null, "", sourceId, game, ((ZoneChangeEvent) event).getFromZone(), true); + } + } + return false; + } + + @Override + public AftermathExileAsResolvesFromGraveyard copy() { + return new AftermathExileAsResolvesFromGraveyard(this); + } + +}