Search in sources :

Example 11 with ReturnToBattlefieldUnderOwnerControlTargetEffect

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

the class GhostwayEffect 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<>();
        toExile.addAll(game.getBattlefield().getActivePermanents(filter, source.getControllerId(), game));
        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.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) 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) UUID(java.util.UUID) HashSet(java.util.HashSet)

Example 12 with ReturnToBattlefieldUnderOwnerControlTargetEffect

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

the class VizierOfDefermentEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    AttackedThisTurnWatcher watcherAttacked = game.getState().getWatcher(AttackedThisTurnWatcher.class);
    BlockedThisTurnWatcher watcherBlocked = game.getState().getWatcher(BlockedThisTurnWatcher.class);
    boolean attackedOrBlocked = false;
    if (watcherAttacked != null && watcherAttacked.checkIfAttacked(permanent, game)) {
        attackedOrBlocked = true;
    }
    if (watcherBlocked != null && watcherBlocked.checkIfBlocked(permanent, game)) {
        attackedOrBlocked = true;
    }
    if (controller != null && attackedOrBlocked && sourcePermanent != null) {
        if (controller.moveCardToExileWithInfo(permanent, source.getSourceId(), sourcePermanent.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
            Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
            effect.setText("Return that card to the battlefield under its owner's control at the beginning of the next end step");
            effect.setTargetPointer(new FixedTarget(source.getFirstTarget(), game));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) AttackedThisTurnWatcher(mage.watchers.common.AttackedThisTurnWatcher) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) BlockedThisTurnWatcher(mage.watchers.common.BlockedThisTurnWatcher)

Example 13 with ReturnToBattlefieldUnderOwnerControlTargetEffect

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

the class CosmicInterventionReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent permanent = game.getPermanent(event.getTargetId());
        if (permanent != null) {
            Card card = game.getCard(event.getTargetId());
            if (card != null) {
                ExileTargetForSourceEffect exileEffect = new ExileTargetForSourceEffect();
                exileEffect.setTargetPointer(new FixedTarget(card.getId(), game));
                exileEffect.apply(game, source);
                Effect returnEffect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
                returnEffect.setTargetPointer(new FixedTarget(card.getId(), game));
                AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(returnEffect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ExileTargetForSourceEffect(mage.abilities.effects.common.ExileTargetForSourceEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) Effect(mage.abilities.effects.Effect) ExileTargetForSourceEffect(mage.abilities.effects.common.ExileTargetForSourceEffect) Card(mage.cards.Card)

Example 14 with ReturnToBattlefieldUnderOwnerControlTargetEffect

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

the class FleetingSpiritEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (controller == null || permanent == null) {
        return false;
    }
    int zcc = permanent.getZoneChangeCounter(game);
    if (!controller.moveCards(permanent, Zone.EXILED, source, game)) {
        return false;
    }
    Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
    effect.setTargetPointer(new FixedTarget(permanent.getId(), zcc + 1));
    AtTheBeginOfNextEndStepDelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
    game.addDelayedTriggeredAbility(delayedAbility, 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) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) GainAbilitySourceEffect(mage.abilities.effects.common.continuous.GainAbilitySourceEffect)

Example 15 with ReturnToBattlefieldUnderOwnerControlTargetEffect

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

the class AgyremRestrictionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(getTargetPointer().getFirst(game, source));
    if (card != null) {
        Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
        effect.setTargetPointer(new FixedTarget(card, game));
        effect.setText("return that card to the battlefield under its owner's control at the beginning of the next end step");
        game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect, TargetController.ANY), source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) RollPlanarDieEffect(mage.abilities.effects.common.RollPlanarDieEffect) RestrictionEffect(mage.abilities.effects.RestrictionEffect) PlanarDieRollCostIncreasingEffect(mage.abilities.effects.common.cost.PlanarDieRollCostIncreasingEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ReturnFromGraveyardToHandTargetEffect(mage.abilities.effects.common.ReturnFromGraveyardToHandTargetEffect) Effect(mage.abilities.effects.Effect) Card(mage.cards.Card)

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