From 3beb5568c4a195b7357a2013e5716c53ef4555ab Mon Sep 17 00:00:00 2001 From: LevelX2 Date: Sat, 31 Oct 2015 00:55:12 +0100 Subject: [PATCH] * Karn Liberated - Fixed that commanders were not returned to command zone after game reset. --- .../mage/sets/newphyrexia/KarnLiberated.java | 30 ++++++++++++------- .../commander/duel/CastBRGCommanderTest.java | 27 +++++++++++++++++ .../common/ExileFromZoneTargetEffect.java | 13 +++----- Mage/src/mage/game/GameImpl.java | 3 +- 4 files changed, 53 insertions(+), 20 deletions(-) diff --git a/Mage.Sets/src/mage/sets/newphyrexia/KarnLiberated.java b/Mage.Sets/src/mage/sets/newphyrexia/KarnLiberated.java index e51d4c7d16e..468537a4201 100644 --- a/Mage.Sets/src/mage/sets/newphyrexia/KarnLiberated.java +++ b/Mage.Sets/src/mage/sets/newphyrexia/KarnLiberated.java @@ -139,12 +139,17 @@ class KarnLiberatedEffect extends OneShotEffect { if (card.getOwnerId().equals(player.getId()) && !card.isCopy() // no copies && !player.getSideboard().contains(card.getId()) && !cards.contains(card)) { // not the exiled cards - player.getLibrary().putOnTop(card, game); + if (card.getId().equals(player.getCommanderId())) { + card.moveToZone(Zone.COMMAND, null, game, true); + } else { + player.getLibrary().putOnTop(card, game); + } } } player.init(game); } for (Card card : cards) { + game.getState().setZone(card.getId(), Zone.EXILED); if (CardUtil.isPermanentCard(card) && !card.getSubtype().contains("Aura")) { game.getExile().add(exileId, sourceObject.getIdName(), card); } @@ -209,16 +214,21 @@ class KarnLiberatedDelayedEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - ExileZone exile = game.getExile().getExileZone(exileId); - if (exile != null) { - Cards cards = new CardsImpl(); // needed because putOntoTheBattlefield removes from exile - cards.addAll(exile); - for (Card card : cards.getCards(game)) { - card.putOntoBattlefield(game, Zone.EXILED, source.getSourceId(), source.getControllerId()); - Permanent permanent = game.getPermanent(card.getId()); - ((PermanentImpl) permanent).removeSummoningSickness(); + Player controller = game.getPlayer(source.getControllerId()); + if (controller != null) { + ExileZone exile = game.getExile().getExileZone(exileId); + if (exile != null) { + // Creatures put onto the battlefield due to Karn's ability will have been under their controller's control continuously + // since the beginning of the first turn. They can attack and their activated abilities with {T} in the cost can be activated. + Cards cards = new CardsImpl(); // needed because putOntoTheBattlefield removes from exile + cards.addAll(exile); + controller.moveCards(cards, Zone.BATTLEFIELD, source, game); + for (Card card : cards.getCards(game)) { + Permanent permanent = game.getPermanent(card.getId()); + ((PermanentImpl) permanent).removeSummoningSickness(); + } + return true; } - return true; } return false; } diff --git a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java index b7732e593b4..12dc632f2f3 100644 --- a/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java +++ b/Mage.Tests/src/test/java/org/mage/test/commander/duel/CastBRGCommanderTest.java @@ -69,4 +69,31 @@ public class CastBRGCommanderTest extends CardTestCommanderDuelBase { } + /** + * Activating Karn Liberated 's ultimate in an edh game (human OR ai) causes + * all the command zones to lose their generals upon the new game restart + */ + @Test + public void castCommanderAfterKarnUltimate() { + // +4: Target player exiles a card from his or her hand. + // -3: Exile target permanent. + // -14: Restart the game, leaving in exile all non-Aura permanent cards exiled with Karn Liberated. Then put those cards onto the battlefield under your control. + addCard(Zone.BATTLEFIELD, playerA, "Karn Liberated", 1); + addCard(Zone.HAND, playerA, "Silvercoat Lion", 2); + + activateAbility(1, PhaseStep.PRECOMBAT_MAIN, playerA, "+4: Target player", playerA); + addTarget(playerA, "Silvercoat Lion"); + activateAbility(3, PhaseStep.PRECOMBAT_MAIN, playerA, "+4: Target player", playerA); + addTarget(playerA, "Silvercoat Lion"); + activateAbility(5, PhaseStep.PRECOMBAT_MAIN, playerA, "-14: Restart"); + + setStopAt(5, PhaseStep.BEGIN_COMBAT); + execute(); + + assertGraveyardCount(playerA, "Karn Liberated", 0); + assertPermanentCount(playerA, "Silvercoat Lion", 2); + assertCommandZoneCount(playerA, "Prossh, Skyraider of Kher", 1); + assertCommandZoneCount(playerB, "Ob Nixilis of the Black Oath", 1); + + } } diff --git a/Mage/src/mage/abilities/effects/common/ExileFromZoneTargetEffect.java b/Mage/src/mage/abilities/effects/common/ExileFromZoneTargetEffect.java index 654c49ea41e..97ecc487a04 100644 --- a/Mage/src/mage/abilities/effects/common/ExileFromZoneTargetEffect.java +++ b/Mage/src/mage/abilities/effects/common/ExileFromZoneTargetEffect.java @@ -30,7 +30,7 @@ package mage.abilities.effects.common; import java.util.UUID; import mage.abilities.Ability; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; +import mage.cards.CardsImpl; import mage.constants.Outcome; import mage.constants.Zone; import mage.filter.FilterCard; @@ -91,16 +91,11 @@ public class ExileFromZoneTargetEffect extends OneShotEffect { default: } if (target != null && target.canChoose(source.getSourceId(), player.getId(), game)) { - if (target.choose(Outcome.Exile, player.getId(), source.getSourceId(), game)) { - for (UUID cardId : target.getTargets()) { - Card card = game.getCard(cardId); - if (card != null) { - card.moveToExile(exileId, exileName, source.getSourceId(), game); - } - } - return true; + if (target.chooseTarget(Outcome.Exile, player.getId(), source, game)) { + player.moveCardsToExile(new CardsImpl(target.getTargets()).getCards(game), source, game, true, exileId, exileName); } } + return true; } return false; } diff --git a/Mage/src/mage/game/GameImpl.java b/Mage/src/mage/game/GameImpl.java index ba89c05297f..6edfd87c44b 100644 --- a/Mage/src/mage/game/GameImpl.java +++ b/Mage/src/mage/game/GameImpl.java @@ -671,7 +671,8 @@ public abstract class GameImpl implements Game, Serializable { } @Override - public void removeBookmark(int bookmark) { + public void removeBookmark(int bookmark + ) { if (!simulation) { if (bookmark != 0) { while (savedStates.size() > bookmark) {