This commit is contained in:
Evan Kranzler 2017-08-27 14:09:03 -04:00
parent b888e8e634
commit e52e7f23e9

View file

@ -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;