Search in sources :

Example 76 with DelayedTriggeredAbility

use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.

the class TatsumaTheDragonsFangTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    CreateTokenEffect effect = new CreateTokenEffect(new TatsumaDragonToken());
    effect.apply(game, source);
    for (UUID tokenId : effect.getLastAddedTokenIds()) {
        // by cards like Doubling Season multiple tokens can be added to the battlefield
        Permanent tokenPermanent = game.getPermanent(tokenId);
        if (tokenPermanent != null) {
            FixedTarget fixedTarget = new FixedTarget(tokenPermanent, game);
            Effect returnEffect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, false);
            returnEffect.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId())));
            DelayedTriggeredAbility delayedAbility = new TatsumaTheDragonsFangTriggeredAbility(fixedTarget, returnEffect);
            game.addDelayedTriggeredAbility(delayedAbility, source);
        }
    }
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) BoostEquippedEffect(mage.abilities.effects.common.continuous.BoostEquippedEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) TatsumaDragonToken(mage.game.permanent.token.TatsumaDragonToken) UUID(java.util.UUID)

Example 77 with DelayedTriggeredAbility

use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.

the class TheScorpionGodEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    // Create delayed triggered ability
    Effect effect = new ReturnToHandTargetEffect();
    effect.setText("return {this} to its owner's hand");
    effect.setTargetPointer(new FixedTarget(source.getSourceId(), source.getSourceObjectZoneChangeCounter()));
    DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) DrawCardSourceControllerEffect(mage.abilities.effects.common.DrawCardSourceControllerEffect) AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect)

Example 78 with DelayedTriggeredAbility

use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.

the class WakeTheDeadReturnFromGraveyardToBattlefieldTargetEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Cards cards = new CardsImpl(getTargetPointer().getTargets(game, source));
        controller.moveCards(cards, Zone.BATTLEFIELD, source, game);
        List<Permanent> toSacrifice = new ArrayList<>(cards.size());
        for (UUID targetId : cards) {
            Permanent creature = game.getPermanent(targetId);
            if (creature != null) {
                toSacrifice.add(creature);
            }
        }
        Effect effect = new SacrificeTargetEffect("Sacrifice those creatures at the beginning of the next end step", source.getControllerId());
        effect.setTargetPointer(new FixedTargets(toSacrifice, game));
        DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect);
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) ArrayList(java.util.ArrayList) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) UUID(java.util.UUID) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl)

Example 79 with DelayedTriggeredAbility

use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.

the class CreateDelayedTriggeredAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    DelayedTriggeredAbility delayedAbility = ability.copy();
    if (this.copyTargets) {
        if (source.getTargets().isEmpty()) {
            delayedAbility.getEffects().setTargetPointer(targetPointer);
        } else {
            delayedAbility.getTargets().addAll(source.getTargets());
            for (Effect effect : delayedAbility.getEffects()) {
                effect.getTargetPointer().init(game, source);
            }
        }
    }
    if (initAbility) {
        delayedAbility.init(game);
    }
    game.addDelayedTriggeredAbility(delayedAbility, source);
    return true;
}
Also used : DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Effect(mage.abilities.effects.Effect) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 80 with DelayedTriggeredAbility

use of mage.abilities.DelayedTriggeredAbility in project mage by magefree.

the class CogworkAssemblerCreateTokenEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent copiedPermanent = game.getPermanent(this.getTargetPointer().getFirst(game, source));
    if (copiedPermanent != null) {
        CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(null, CardType.ARTIFACT, true);
        if (effect.apply(game, source)) {
            for (Permanent copyPermanent : effect.getAddedPermanents()) {
                ExileTargetEffect exileEffect = new ExileTargetEffect();
                exileEffect.setTargetPointer(new FixedTarget(copyPermanent, game));
                DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
                game.addDelayedTriggeredAbility(delayedAbility, source);
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) TargetArtifactPermanent(mage.target.common.TargetArtifactPermanent) Permanent(mage.game.permanent.Permanent) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Aggregations

DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)88 Permanent (mage.game.permanent.Permanent)62 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)61 FixedTarget (mage.target.targetpointer.FixedTarget)61 Player (mage.players.Player)38 Card (mage.cards.Card)30 OneShotEffect (mage.abilities.effects.OneShotEffect)27 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)27 Effect (mage.abilities.effects.Effect)25 ContinuousEffect (mage.abilities.effects.ContinuousEffect)24 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)20 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)19 UUID (java.util.UUID)14 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)14 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)13 FilterCard (mage.filter.FilterCard)9 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)9 ReturnToHandTargetEffect (mage.abilities.effects.common.ReturnToHandTargetEffect)8 FilterCreatureCard (mage.filter.common.FilterCreatureCard)7 MageObjectReference (mage.MageObjectReference)6