diff --git a/Mage.Sets/src/mage/sets/conflux/HellsparkElemental.java b/Mage.Sets/src/mage/sets/conflux/HellsparkElemental.java index b4d33ca052..cb274cb430 100644 --- a/Mage.Sets/src/mage/sets/conflux/HellsparkElemental.java +++ b/Mage.Sets/src/mage/sets/conflux/HellsparkElemental.java @@ -63,7 +63,7 @@ public class HellsparkElemental extends CardImpl { // At the beginning of the end step, sacrifice Hellspark Elemental. this.addAbility(new OnEventTriggeredAbility(EventType.END_TURN_STEP_PRE, "beginning of the end step", true, new SacrificeSourceEffect())); - // Unearth {1}{R} ({1}{R}: Return this card from your graveyard to the battlefield. It gains haste. Exile it at the beginning of the next end step or if it would leave the battlefield. Unearth only as a sorcery.) + // Unearth {1}{R}: Return this card from your graveyard to the battlefield. It gains haste. Exile it at the beginning of the next end step or if it would leave the battlefield. Unearth only as a sorcery.) this.addAbility(new UnearthAbility(new ManaCostsImpl("{1}{R}"))); } diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UnearthTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UnearthTest.java new file mode 100644 index 0000000000..1d6911fd8e --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/abilities/keywords/UnearthTest.java @@ -0,0 +1,78 @@ +/* + * Copyright 2010 BetaSteward_at_googlemail.com. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without modification, are + * permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, this list of + * conditions and the following disclaimer. + * + * 2. Redistributions in binary form must reproduce the above copyright notice, this list + * of conditions and the following disclaimer in the documentation and/or other materials + * provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY BetaSteward_at_googlemail.com ``AS IS'' AND ANY EXPRESS OR IMPLIED + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND + * FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL BetaSteward_at_googlemail.com OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING + * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * The views and conclusions contained in the software and documentation are those of the + * authors and should not be interpreted as representing official policies, either expressed + * or implied, of BetaSteward_at_googlemail.com. + */ +package org.mage.test.cards.abilities.keywords; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * @author LevelX2 + */ + +public class UnearthTest extends CardTestPlayerBase { + + /** + * Hellspark Elemental (and probably other cards with the unearth ability) - If I unearth the elemental, + * attack, and then go to the end of my turn both the "sacrifice" and "exile" clauses will trigger and + * the game will ask me which one I want to put on the stack first. If I choose "sacrifice" first and + * "exile" second, all good, the exile part resolves first and the elemental is exiled, the sacrifice + * part does nothing afterwards. But if I choose "exile" first and "sacrifice" second then the elemental + * will be sacrificed and placed on my graveyard and after that the "exile" resolves but does nothing, as + * I'm guessing it can't "find" the elemental anymore and so it stays in my graveyard, despite the fact + * that because I use its unearth ability it should always be exiled once leaving the battlefield no matter what. + * The bug should be easy to reproduce if following the order I mention above (click the exile part, + * so the sacrifice goes on the top of the stack). + */ + @Test + public void testUnearthAttackExile() { + addCard(Zone.BATTLEFIELD, playerA, "Mountain", 2); + // 3/1 - Trample, haste + // At the beginning of the end step, sacrifice Hellspark Elemental. + // Unearth {1}{R} ({1}{R}: Return this card from your graveyard to the battlefield. + // It gains haste. Exile it at the beginning of the next end step or if it would + // leave the battlefield. Unearth only as a sorcery.) + addCard(Zone.GRAVEYARD, playerA, "Hellspark Elemental", 1); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Unearth"); + + attack(1, playerA, "Hellspark Elemental"); + + setStopAt(2, PhaseStep.UNTAP); + execute(); + + assertGraveyardCount(playerA, "Hellspark Elemental", 0); + assertLife(playerB, 17); + + assertPermanentCount(playerA, "Hellspark Elemental", 0); + assertExileCount("Hellspark Elemental", 1); + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/keyword/UnearthAbility.java b/Mage/src/mage/abilities/keyword/UnearthAbility.java index 19e9b4724b..c8411cfb87 100644 --- a/Mage/src/mage/abilities/keyword/UnearthAbility.java +++ b/Mage/src/mage/abilities/keyword/UnearthAbility.java @@ -45,6 +45,8 @@ import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.GameEvent.EventType; import mage.game.events.ZoneChangeEvent; +import mage.game.permanent.Permanent; +import mage.players.Player; /** * @@ -144,10 +146,11 @@ class UnearthLeavesBattlefieldEffect extends ReplacementEffectImpl { @Override public boolean applies(GameEvent event, Ability source, Game game) { - if (source.getSourceObjectIfItStillExists(game) != null) { + if (event.getTargetId().equals(source.getSourceId())) { ZoneChangeEvent zEvent = (ZoneChangeEvent)event; if (zEvent.getFromZone() == Zone.BATTLEFIELD && zEvent.getToZone() != Zone.EXILED) { - return true; + // started in graveyard goint to battlefield so current zone change counter has to be +1 + return source.getSourceObjectZoneChangeCounter() + 1 == game.getState().getZoneChangeCounter(source.getSourceId()); } } return false; @@ -155,7 +158,11 @@ class UnearthLeavesBattlefieldEffect extends ReplacementEffectImpl { @Override public boolean replaceEvent(GameEvent event, Ability source, Game game) { - new ExileSourceEffect().apply(game, source); + Permanent permanent = game.getPermanent(source.getSourceId()); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null && permanent != null) { + controller.moveCardToExileWithInfo(permanent, null, "", source.getSourceId(), game, Zone.BATTLEFIELD, true); + } return true; } }