From e52e7f23e9483fa525bb1b45379755c9f0e86ee2 Mon Sep 17 00:00:00 2001 From: Evan Kranzler Date: Sun, 27 Aug 2017 14:09:03 -0400 Subject: [PATCH] Fixed bug #3491 --- .../src/mage/cards/d/DetentionSphere.java | 35 ++++++++++--------- 1 file changed, 18 insertions(+), 17 deletions(-) diff --git a/Mage.Sets/src/mage/cards/d/DetentionSphere.java b/Mage.Sets/src/mage/cards/d/DetentionSphere.java index aabef80c95..835f494d8c 100644 --- a/Mage.Sets/src/mage/cards/d/DetentionSphere.java +++ b/Mage.Sets/src/mage/cards/d/DetentionSphere.java @@ -33,7 +33,7 @@ import mage.abilities.Ability; import mage.abilities.common.EntersBattlefieldTriggeredAbility; import mage.abilities.common.LeavesBattlefieldTriggeredAbility; import mage.abilities.effects.OneShotEffect; -import mage.cards.Card; +import mage.abilities.effects.common.ReturnFromExileForSourceEffect; import mage.cards.CardImpl; import mage.cards.CardSetInfo; import mage.constants.CardType; @@ -48,8 +48,8 @@ import mage.game.Game; import mage.game.permanent.Permanent; import mage.players.Player; import mage.target.TargetPermanent; - - +import mage.util.CardUtil; +import org.apache.log4j.Logger; /** * @@ -58,13 +58,13 @@ import mage.target.TargetPermanent; public class DetentionSphere extends CardImpl { static final protected FilterPermanent filter = new FilterNonlandPermanent("nonland permanent not named Detention Sphere"); + static { filter.add(Predicates.not(new NamePredicate("Detention Sphere"))); } public DetentionSphere(UUID ownerId, CardSetInfo setInfo) { - super(ownerId,setInfo,new CardType[]{CardType.ENCHANTMENT},"{1}{W}{U}"); - + super(ownerId, setInfo, new CardType[]{CardType.ENCHANTMENT}, "{1}{W}{U}"); // When Detention Sphere enters the battlefield, you may exile // target nonland permanent not named Detention Sphere and all @@ -73,7 +73,6 @@ public class DetentionSphere extends CardImpl { ability.addTarget(new TargetPermanent(filter)); this.addAbility(ability); - // When Detention Sphere leaves the battlefield, return the exiled // cards to the battlefield under their owner's control. this.addAbility(new LeavesBattlefieldTriggeredAbility(new DetentionSphereLeavesEffect(), false)); @@ -91,7 +90,6 @@ public class DetentionSphere extends CardImpl { class DetentionSphereEntersEffect extends OneShotEffect { - public DetentionSphereEntersEffect() { super(Outcome.Exile); staticText = "you may exile target nonland permanent not named Detention Sphere and all other permanents with the same name as that permanent"; @@ -103,7 +101,7 @@ class DetentionSphereEntersEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - UUID exileId = source.getSourceId(); + UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter()); Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source)); Player controller = game.getPlayer(source.getControllerId()); MageObject sourceObject = game.getObject(source.getSourceId()); @@ -143,15 +141,18 @@ class DetentionSphereLeavesEffect extends OneShotEffect { @Override public boolean apply(Game game, Ability source) { - UUID exileId = source.getSourceId(); - ExileZone exile = game.getExile().getExileZone(exileId); - if (exile != null) { - exile = exile.copy(); - for (UUID cardId : exile) { - Card card = game.getCard(cardId); - card.putOntoBattlefield(game, Zone.EXILED, source.getSourceId(), card.getOwnerId()); + Player controller = game.getPlayer(source.getControllerId()); + MageObject sourceObject = source.getSourceObject(game); + if (sourceObject != null && controller != null) { + Permanent permanentLeftBattlefield = (Permanent) getValue("permanentLeftBattlefield"); + if (permanentLeftBattlefield == null) { + Logger.getLogger(ReturnFromExileForSourceEffect.class).error("Permanent not found: " + sourceObject.getName()); + return false; + } + ExileZone exile = game.getExile().getExileZone(CardUtil.getExileZoneId(game, source.getSourceId(), permanentLeftBattlefield.getZoneChangeCounter(game))); + if (exile != null) { + controller.moveCards(exile.getCards(game), Zone.BATTLEFIELD, source, game, false, false, true, null); } - game.getExile().getExileZone(exileId).clear(); return true; } return false; @@ -161,4 +162,4 @@ class DetentionSphereLeavesEffect extends OneShotEffect { public DetentionSphereLeavesEffect copy() { return new DetentionSphereLeavesEffect(this); } -} \ No newline at end of file +}