Search in sources :

Example 6 with CreateDelayedTriggeredAbilityEffect

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

the class GuardianAngelDelayedTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        String targetName = "";
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (targetPlayer == null) {
            Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (targetPermanent == null) {
                return true;
            }
            targetName = targetPermanent.getIdName();
        } else {
            targetName = "player " + targetPlayer.getName();
        }
        ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, source.getManaCostsToPay().getX(), false);
        effect.setTargetPointer(getTargetPointer());
        game.addEffect(effect, source);
        SpecialAction specialAction = new GuardianAngelAction();
        specialAction.getEffects().get(0).setTargetPointer(getTargetPointer());
        specialAction.getEffects().get(0).setText("Prevent the next 1 damage that would be dealt to any target this turn (" + targetName + ").");
        new CreateSpecialActionEffect(specialAction).apply(game, source);
        // Create a hidden delayed triggered ability to remove the special action at end of turn.
        new CreateDelayedTriggeredAbilityEffect(new GuardianAngelDelayedTriggeredAbility(specialAction.getId()), false).apply(game, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SpecialAction(mage.abilities.SpecialAction) Permanent(mage.game.permanent.Permanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CreateSpecialActionEffect(mage.abilities.effects.common.CreateSpecialActionEffect) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Example 7 with CreateDelayedTriggeredAbilityEffect

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

the class TimeToFeedDiesTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (creature != null) {
        DelayedTriggeredAbility ability = new TimeToFeedDiesTriggeredAbility(creature.getId(), creature.getZoneChangeCounter(game));
        new CreateDelayedTriggeredAbilityEffect(ability, false).apply(game, source);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility)

Example 8 with CreateDelayedTriggeredAbilityEffect

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

the class LatNamsLegacyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && !controller.getHand().isEmpty()) {
        TargetCard target = new TargetCard(Zone.HAND, new FilterCard("card to shuffle into your library"));
        controller.choose(Outcome.Detriment, controller.getHand(), target, game);
        Card card = controller.getHand().get(target.getFirstTarget(), game);
        if (card != null) {
            boolean successful = controller.moveCards(card, Zone.LIBRARY, source, game);
            controller.shuffleLibrary(source, game);
            if (successful) {
                new CreateDelayedTriggeredAbilityEffect(new AtTheBeginOfNextUpkeepDelayedTriggeredAbility(new DrawCardSourceControllerEffect(2)), false).apply(game, source);
            }
        }
        return true;
    }
    return true;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) AtTheBeginOfNextUpkeepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextUpkeepDelayedTriggeredAbility) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) TargetCard(mage.target.TargetCard) FilterCard(mage.filter.FilterCard) TargetCard(mage.target.TargetCard) Card(mage.cards.Card)

Example 9 with CreateDelayedTriggeredAbilityEffect

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

the class DeputyOfDetentionExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    Permanent targeted = game.getPermanent(source.getFirstTarget());
    if (permanent == null || controller == null || targeted == null) {
        return false;
    }
    FilterPermanent filter = new FilterNonlandPermanent();
    filter.add(new ControllerIdPredicate(targeted.getControllerId()));
    filter.add(new NamePredicate(targeted.getName()));
    Set<Card> toExile = new LinkedHashSet<>();
    for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), game)) {
        toExile.add(creature);
    }
    if (!toExile.isEmpty()) {
        controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
        new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
    }
    return true;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) FilterPermanent(mage.filter.FilterPermanent) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ControllerIdPredicate(mage.filter.predicate.permanent.ControllerIdPredicate) FilterNonlandPermanent(mage.filter.common.FilterNonlandPermanent) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Example 10 with CreateDelayedTriggeredAbilityEffect

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

the class AlignedHedronNetworkExileEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent permanent = game.getPermanent(source.getSourceId());
    // the target creature won't be exiled.
    if (controller != null && permanent != null) {
        Set<Card> toExile = new LinkedHashSet<>();
        for (Permanent creature : game.getBattlefield().getActivePermanents(filter, controller.getId(), source.getSourceId(), game)) {
            toExile.add(creature);
        }
        if (!toExile.isEmpty()) {
            controller.moveCardsToExile(toExile, source, game, true, CardUtil.getCardExileZoneId(game, source), permanent.getIdName());
            new CreateDelayedTriggeredAbilityEffect(new OnLeaveReturnExiledToBattlefieldAbility()).apply(game, source);
        }
        return true;
    }
    return false;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) OnLeaveReturnExiledToBattlefieldAbility(mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility) Card(mage.cards.Card)

Aggregations

CreateDelayedTriggeredAbilityEffect (mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect)11 Player (mage.players.Player)8 Permanent (mage.game.permanent.Permanent)7 Card (mage.cards.Card)5 LinkedHashSet (java.util.LinkedHashSet)3 OnLeaveReturnExiledToBattlefieldAbility (mage.abilities.common.delayed.OnLeaveReturnExiledToBattlefieldAbility)3 SpecialAction (mage.abilities.SpecialAction)2 AtTheEndOfCombatDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)2 Effect (mage.abilities.effects.Effect)2 OneShotEffect (mage.abilities.effects.OneShotEffect)2 CreateSpecialActionEffect (mage.abilities.effects.common.CreateSpecialActionEffect)2 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)2 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)2 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 TargetPermanent (mage.target.TargetPermanent)2 FixedTarget (mage.target.targetpointer.FixedTarget)2 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 SimpleActivatedAbility (mage.abilities.common.SimpleActivatedAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 AtTheBeginOfNextUpkeepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextUpkeepDelayedTriggeredAbility)1