* Ghostly Flicker - Reworked effect code.
*/
package mage.cards.g;
-import mage.constants.CardType;
+import java.util.HashSet;
+import java.util.Set;
+import java.util.UUID;
+import mage.MageObject;
import mage.abilities.Ability;
import mage.abilities.effects.OneShotEffect;
import mage.cards.Card;
import mage.cards.CardImpl;
import mage.cards.CardSetInfo;
+import mage.constants.CardType;
import mage.constants.Outcome;
import mage.constants.Zone;
import mage.filter.common.FilterControlledPermanent;
@@ -40,10 +44,9 @@ import mage.filter.predicate.Predicates;
import mage.filter.predicate.mageobject.CardTypePredicate;
import mage.game.Game;
import mage.game.permanent.Permanent;
+import mage.players.Player;
import mage.target.common.TargetControlledPermanent;
-import java.util.UUID;
-
/**
* @author noxx
*/
@@ -61,7 +64,6 @@ public class GhostlyFlicker extends CardImpl {
public GhostlyFlicker(UUID ownerId, CardSetInfo setInfo) {
super(ownerId, setInfo, new CardType[]{CardType.INSTANT}, "{2}{U}");
-
// Exile two target artifacts, creatures, and/or lands you control, then return those cards to the battlefield under your control.
this.getSpellAbility().addTarget(new TargetControlledPermanent(2, 2, filter, false));
this.getSpellAbility().addEffect(new GhostlyFlickerEffect());
@@ -95,20 +97,22 @@ class GhostlyFlickerEffect extends OneShotEffect {
@Override
public boolean apply(Game game, Ability source) {
- UUID exileId = source.getSourceId();
+ Player controller = game.getPlayer(source.getControllerId());
+ MageObject sourceObject = source.getSourceObject(game);
+ if (controller != null && sourceObject != null) {
+ UUID exileId = UUID.randomUUID();
+ Set<Card> toExile = new HashSet<>();
for (UUID permanentId : targetPointer.getTargets(game, source)) {
Permanent target = game.getPermanent(permanentId);
if (target != null) {
- target.moveToExile(exileId, "Ghostly Flicker", source.getSourceId(), game);
- Card card = game.getCard(target.getId());
- if (card != null) {
- Zone currentZone = game.getState().getZone(card.getId());
- card.putOntoBattlefield(game, currentZone, source.getSourceId(), source.getControllerId());
- }
+ toExile.add(target);
}
}
-
+ controller.moveCardsToExile(toExile, source, game, true, exileId, sourceObject.getIdName());
+ game.applyEffects();
+ controller.moveCards(game.getExile().getExileZone(exileId).getCards(game), Zone.BATTLEFIELD, source, game);
return true;
}
+ return false;
+ }
}
-
