Search in sources :

Example 21 with ReturnToBattlefieldUnderOwnerControlTargetEffect

use of mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect in project mage by magefree.

the class YorionSkyNomadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject == null || controller == null) {
        return false;
    }
    TargetPermanent target = new TargetPermanent(0, Integer.MAX_VALUE, filter, true);
    controller.choose(outcome, target, source.getSourceId(), game);
    Set<Card> toExile = target.getTargets().stream().map(game::getPermanent).collect(Collectors.toSet());
    UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
    controller.moveCardsToExile(toExile, source, game, true, exileId, sourceObject.getIdName());
    Cards cardsToReturn = new CardsImpl();
    for (Card exiled : toExile) {
        if (exiled instanceof PermanentMeld) {
            MeldCard meldCard = (MeldCard) ((PermanentCard) exiled).getCard();
            Card topCard = meldCard.getTopHalfCard();
            Card bottomCard = meldCard.getBottomHalfCard();
            if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter()) {
                cardsToReturn.add(topCard);
            }
            if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter()) {
                cardsToReturn.add(bottomCard);
            }
        } else if (exiled.getZoneChangeCounter(game) == game.getState().getZoneChangeCounter(exiled.getId()) - 1) {
            cardsToReturn.add(exiled);
        }
    }
    Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
    effect.setTargetPointer(new FixedTargets(cardsToReturn, game));
    AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : Player(mage.players.Player) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) PermanentCard(mage.game.permanent.PermanentCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) PermanentMeld(mage.game.permanent.PermanentMeld) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) TargetPermanent(mage.target.TargetPermanent) UUID(java.util.UUID)

Example 22 with ReturnToBattlefieldUnderOwnerControlTargetEffect

use of mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect in project mage by magefree.

the class LiberateEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (player == null || permanent == null) {
        return false;
    }
    Card card = permanent.getMainCard();
    player.moveCards(permanent, Zone.EXILED, source, game);
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false).setText("Return that card to the battlefield under its owner's control at the beginning of the next end step").setTargetPointer(new FixedTarget(card, game))), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) Card(mage.cards.Card)

Example 23 with ReturnToBattlefieldUnderOwnerControlTargetEffect

use of mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect in project mage by magefree.

the class SuddenDisappearanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller != null && sourceObject != null) {
        Set<Card> permsSet = new HashSet<>(game.getBattlefield().getAllActivePermanents(filter, source.getFirstTarget(), game));
        if (!permsSet.isEmpty()) {
            controller.moveCardsToExile(permsSet, source, game, true, source.getSourceId(), sourceObject.getIdName());
            Cards targets = new CardsImpl();
            for (Card card : permsSet) {
                targets.add(card.getId());
            }
            Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, true);
            effect.setText("Return the exiled cards to the battlefield under their owner's control at the beginning of the next end step");
            effect.setTargetPointer(new FixedTargets(targets, game));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
        }
        return true;
    }
    return false;
}
Also used : TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) HashSet(java.util.HashSet)

Example 24 with ReturnToBattlefieldUnderOwnerControlTargetEffect

use of mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect in project mage by magefree.

the class EerieInterludeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (sourceObject != null && controller != null) {
        Set<Card> toExile = new HashSet<>();
        for (UUID targetId : getTargetPointer().getTargets(game, source)) {
            Permanent targetCreature = game.getPermanent(targetId);
            if (targetCreature != null) {
                toExile.add(targetCreature);
            }
        }
        UUID exileId = CardUtil.getExileZoneId(game, source.getSourceId(), source.getSourceObjectZoneChangeCounter());
        controller.moveCardsToExile(toExile, source, game, true, exileId, sourceObject.getIdName());
        Cards cardsToReturn = new CardsImpl();
        for (Card exiled : toExile) {
            if (exiled instanceof PermanentMeld) {
                MeldCard meldCard = (MeldCard) ((PermanentCard) exiled).getCard();
                Card topCard = meldCard.getTopHalfCard();
                Card bottomCard = meldCard.getBottomHalfCard();
                if (topCard.getZoneChangeCounter(game) == meldCard.getTopLastZoneChangeCounter()) {
                    cardsToReturn.add(topCard);
                }
                if (bottomCard.getZoneChangeCounter(game) == meldCard.getBottomLastZoneChangeCounter()) {
                    cardsToReturn.add(bottomCard);
                }
            } else if (exiled.getZoneChangeCounter(game) == game.getState().getZoneChangeCounter(exiled.getId()) - 1) {
                cardsToReturn.add(exiled);
            }
        }
        Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
        effect.setTargetPointer(new FixedTargets(cardsToReturn, game));
        AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FixedTargets(mage.target.targetpointer.FixedTargets) MageObject(mage.MageObject) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) PermanentCard(mage.game.permanent.PermanentCard) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) PermanentMeld(mage.game.permanent.PermanentMeld) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 25 with ReturnToBattlefieldUnderOwnerControlTargetEffect

use of mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect in project mage by magefree.

the class KayaGhostAssassinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (controller != null && sourcePermanent != null) {
        if (getTargetPointer().getFirst(game, source) != null) {
            Permanent targetCreature = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (targetCreature != null) {
                int zcc = targetCreature.getZoneChangeCounter(game);
                if (controller.moveCards(targetCreature, Zone.EXILED, source, game)) {
                    Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
                    effect.setTargetPointer(new FixedTarget(targetCreature.getId(), zcc + 1));
                    AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(effect);
                    game.addDelayedTriggeredAbility(delayedAbility, source);
                }
            }
        } else {
            int zcc = sourcePermanent.getZoneChangeCounter(game);
            if (controller.moveCards(sourcePermanent, Zone.EXILED, source, game)) {
                Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
                effect.setTargetPointer(new FixedTarget(sourcePermanent.getId(), zcc + 1));
                AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(effect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
        }
        controller.loseLife(2, game, source, false);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) DiscardEachPlayerEffect(mage.abilities.effects.common.discard.DiscardEachPlayerEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) GainLifeEffect(mage.abilities.effects.common.GainLifeEffect) Effect(mage.abilities.effects.Effect) LoseLifeOpponentsEffect(mage.abilities.effects.common.LoseLifeOpponentsEffect) AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfYourNextUpkeepDelayedTriggeredAbility)

Aggregations

ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)31 Effect (mage.abilities.effects.Effect)28 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)27 OneShotEffect (mage.abilities.effects.OneShotEffect)27 FixedTarget (mage.target.targetpointer.FixedTarget)27 Permanent (mage.game.permanent.Permanent)25 Player (mage.players.Player)24 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)12 MageObject (mage.MageObject)11 UUID (java.util.UUID)9 TargetPermanent (mage.target.TargetPermanent)8 Card (mage.cards.Card)6 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)6 FilterPermanent (mage.filter.FilterPermanent)5 FixedTargets (mage.target.targetpointer.FixedTargets)4 HashSet (java.util.HashSet)3 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)2 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)2 FilterControlledPermanent (mage.filter.common.FilterControlledPermanent)2 PermanentCard (mage.game.permanent.PermanentCard)2