diff --git a/Mage.Sets/src/mage/sets/magic2012/AngelicDestiny.java b/Mage.Sets/src/mage/sets/magic2012/AngelicDestiny.java index f9604ea6f25..99a439abdc7 100644 --- a/Mage.Sets/src/mage/sets/magic2012/AngelicDestiny.java +++ b/Mage.Sets/src/mage/sets/magic2012/AngelicDestiny.java @@ -82,7 +82,7 @@ public class AngelicDestiny extends CardImpl { this.addAbility(ability); // When enchanted creature dies, return Angelic Destiny to its owner's hand. - this.addAbility(new DiesAttachedTriggeredAbility(new ReturnToHandSourceEffect(), "enchanted creature")); + this.addAbility(new DiesAttachedTriggeredAbility(new ReturnToHandSourceEffect(false, true), "enchanted creature")); } public AngelicDestiny(final AngelicDestiny card) { diff --git a/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/AngelicDestinyTest.java b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/AngelicDestinyTest.java new file mode 100644 index 00000000000..985b6bbf536 --- /dev/null +++ b/Mage.Tests/src/test/java/org/mage/test/cards/triggers/dies/AngelicDestinyTest.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.triggers.dies; + +import mage.constants.PhaseStep; +import mage.constants.Zone; +import org.junit.Test; +import org.mage.test.serverside.base.CardTestPlayerBase; + +/** + * + * + * @author LevelX2 + */ + +public class AngelicDestinyTest extends CardTestPlayerBase { + + /** + * I killed my opponent's Champion of the Parish, which was enchanted with Angelic Destiny. + * However the Angelic Destiny went to the graveyard instead of returning his hand. + * + */ + @Test + public void testDisabledEffectOnChangeZone() { + addCard(Zone.BATTLEFIELD, playerA, "Plains", 4); + // Enchantment - Aura {2}{W}{W} + // Enchant creature + // Enchanted creature gets +4/+4, has flying and first strike, and is an Angel in addition to its other types. + // When enchanted creature dies, return Angelic Destiny to its owner's hand. + addCard(Zone.HAND, playerA, "Angelic Destiny", 1); + // Champion of the Parish + // Whenever another Human enters the battlefield under your control, put a +1/+1 counter on Champion of the Parish. + addCard(Zone.BATTLEFIELD, playerA, "Champion of the Parish", 1); + + addCard(Zone.BATTLEFIELD, playerB, "Mountain", 1); + addCard(Zone.BATTLEFIELD, playerB, "Swamp", 1); + addCard(Zone.HAND, playerB, "Terminate", 1); + + castSpell(1, PhaseStep.PRECOMBAT_MAIN, playerA, "Angelic Destiny", "Champion of the Parish"); + castSpell(1, PhaseStep.POSTCOMBAT_MAIN, playerB, "Terminate", "Champion of the Parish"); + + setStopAt(1, PhaseStep.END_TURN); + execute(); + + assertGraveyardCount(playerA, "Champion of the Parish", 1); + assertGraveyardCount(playerB, "Terminate", 1); + + assertGraveyardCount(playerA, "Angelic Destiny", 0); + assertHandCount(playerA, "Angelic Destiny", 1); + + } + +} \ No newline at end of file diff --git a/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java b/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java index c48b9d33637..78fc74d57c1 100644 --- a/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java +++ b/Mage/src/mage/abilities/common/DiesAttachedTriggeredAbility.java @@ -6,7 +6,6 @@ import mage.abilities.effects.Effect; import mage.game.Game; import mage.game.events.GameEvent; import mage.game.events.ZoneChangeEvent; -import mage.game.permanent.Permanent; /** * "When enchanted/equipped creature dies" triggered ability diff --git a/Mage/src/mage/abilities/effects/common/ReturnToHandSourceEffect.java b/Mage/src/mage/abilities/effects/common/ReturnToHandSourceEffect.java index 4da3a673399..624fcf86de6 100644 --- a/Mage/src/mage/abilities/effects/common/ReturnToHandSourceEffect.java +++ b/Mage/src/mage/abilities/effects/common/ReturnToHandSourceEffect.java @@ -44,21 +44,33 @@ import mage.players.Player; */ public class ReturnToHandSourceEffect extends OneShotEffect { - boolean fromBattlefieldOnly = false; - + boolean fromBattlefieldOnly; + boolean returnFromNextZone ; + public ReturnToHandSourceEffect() { this(false); } - + public ReturnToHandSourceEffect(boolean fromBattlefieldOnly) { + this(fromBattlefieldOnly, false); + } + + /** + * + * @param fromBattlefieldOnly the object is only returned if it's on the battlefield as the effect resolves + * @param returnFromNextZone the object is only returned, if it has changed the zone one time after the source ability triggered or was activated (e.g. Angelic Destiny) + */ + public ReturnToHandSourceEffect(boolean fromBattlefieldOnly, boolean returnFromNextZone) { super(Outcome.ReturnToHand); this.fromBattlefieldOnly = fromBattlefieldOnly; + this.returnFromNextZone = returnFromNextZone; staticText = "return {this} to it's owner's hand"; } public ReturnToHandSourceEffect(final ReturnToHandSourceEffect effect) { super(effect); this.fromBattlefieldOnly = effect.fromBattlefieldOnly; + this.returnFromNextZone = effect.returnFromNextZone; } @Override @@ -70,7 +82,13 @@ public class ReturnToHandSourceEffect extends OneShotEffect { public boolean apply(Game game, Ability source) { Player controller = game.getPlayer(source.getControllerId()); if (controller != null) { - MageObject mageObject = source.getSourceObjectIfItStillExists(game); + MageObject mageObject; + if (returnFromNextZone && + game.getState().getZoneChangeCounter(source.getSourceId()) == source.getSourceObjectZoneChangeCounter() + 1) { + mageObject = game.getObject(source.getSourceId()); + } else { + mageObject = source.getSourceObjectIfItStillExists(game); + } if (mageObject != null) { switch (game.getState().getZone(mageObject.getId())) { case BATTLEFIELD: