diff --git a/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java b/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java index 2f3a3b78d9..20384365cf 100644 --- a/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java +++ b/Mage.Sets/src/mage/cards/j/JelevaNephaliasScourge.java @@ -15,6 +15,7 @@ import mage.constants.*; import mage.filter.StaticFilters; import mage.game.Game; import mage.game.events.GameEvent; +import mage.game.permanent.Permanent; import mage.game.stack.Spell; import mage.game.stack.StackObject; import mage.players.Player; @@ -81,18 +82,18 @@ class JelevaNephaliasScourgeEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); - MageObject sourceObject = source.getSourceObject(game); + Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId()); JelevaNephaliasWatcher watcher = game.getState().getWatcher(JelevaNephaliasWatcher.class); if (controller != null - && sourceObject != null + && permanent != null && watcher != null) { - int xValue = watcher.getManaSpentToCastLastTime(sourceObject.getId(), sourceObject.getZoneChangeCounter(game) - 1); + int xValue = watcher.getManaSpentToCastLastTime(permanent.getId(), permanent.getZoneChangeCounter(game) - 1); if (xValue > 0) { for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) { Player player = game.getPlayer(playerId); if (player != null) { player.moveCardsToExile(player.getLibrary().getTopCards(game, xValue), - source, game, true, CardUtil.getCardExileZoneId(game, source), sourceObject.getIdName()); + source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName()); } } } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/single/c13/JelevaNephaliasScourgeTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/single/c13/JelevaNephaliasScourgeTest.java new file mode 100644 index 0000000000..7ed4b0f020 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/single/c13/JelevaNephaliasScourgeTest.java @@ -0,0 +1,48 @@ +package org.mage.test.cards.single.c13; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * {@link mage.cards.j.JelevaNephaliasScourge Jeleva, Nephalia's Scourge} + * {1}{U}{B}{R} + * Flying + * When Jeleva, Nephalia’s Scourge enters the battlefield, each player exiles the top X cards of their library, + * where X is the amount of mana spent to cast Jeleva. + * Whenever Jeleva attacks, you may cast an instant or sorcery spell from among cards exiled with Jeleva without paying its mana cost. + */ +public class JelevaNephaliasScourgeTest extends CardTestPlayerBase { + private static final String jeleva = "Jeleva, Nephalia's Scourge"; + + /** + * Reported bug: https://github.com/magefree/mage/issues/3476 + * When casting Jeleva, Nephalia's Scourge, + * if Jeleva is no longer on the battlefield when her ETB trigger resolves, + * she won't exile any cards. + */ + @Test + public void etbWorksIfShesRemoved() { + addCard(Zone.HAND, playerA, jeleva); + addCard(Zone.BATTLEFIELD, playerA, "Island"); + addCard(Zone.BATTLEFIELD, playerA, "Swamp"); + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + + // Destroy target Creature + String murder = "Murder"; + addCard(Zone.HAND, playerB, murder); + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 3); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, jeleva); + waitStackResolved(1, PhaseStep.PRECOMBAT_MAIN, 1); + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerB, murder, jeleva); + + setStopAt(1, PhaseStep.PRECOMBAT_MAIN); + execute(); + + assertGraveyardCount(playerA, jeleva, 1); + assertExileCount(playerA, 4); + assertExileCount(playerB, 4); + } +}