Search in sources :

Example 86 with AtTheBeginOfNextEndStepDelayedTriggeredAbility

use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.

the class SithMagicReplacementEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Card card = game.getCard(this.getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && card != null) {
        if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
            Permanent creature = game.getPermanent(card.getId());
            if (creature != null) {
                // gains haste
                ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
                effect.setTargetPointer(new FixedTarget(creature, game));
                game.addEffect(effect, source);
                // gains lifelink
                effect = new GainAbilityTargetEffect(LifelinkAbility.getInstance(), Duration.Custom);
                effect.setTargetPointer(new FixedTarget(creature, game));
                game.addEffect(effect, source);
                // Exile at begin of next end step
                ExileTargetEffect exileEffect = new ExileTargetEffect(null, null, Zone.BATTLEFIELD);
                exileEffect.setTargetPointer(new FixedTarget(creature, game));
                DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
                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) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Card(mage.cards.Card) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 87 with AtTheBeginOfNextEndStepDelayedTriggeredAbility

use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.

the class ThroughTheBreachEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        if (controller.chooseUse(Outcome.PutCreatureInPlay, choiceText, source, game)) {
            TargetCardInHand target = new TargetCardInHand(StaticFilters.FILTER_CARD_CREATURE);
            if (controller.choose(Outcome.PutCreatureInPlay, target, source.getSourceId(), game)) {
                Card card = game.getCard(target.getFirstTarget());
                if (card != null) {
                    if (controller.moveCards(card, Zone.BATTLEFIELD, source, game)) {
                        Permanent permanent = game.getPermanent(card.getId());
                        if (permanent != null) {
                            ContinuousEffect effect = new GainAbilityTargetEffect(HasteAbility.getInstance(), Duration.Custom);
                            effect.setTargetPointer(new FixedTarget(permanent, game));
                            game.addEffect(effect, source);
                            SacrificeTargetEffect sacrificeEffect = new SacrificeTargetEffect("sacrifice " + card.getName(), source.getControllerId());
                            sacrificeEffect.setTargetPointer(new FixedTarget(permanent, game));
                            DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(sacrificeEffect);
                            game.addDelayedTriggeredAbility(delayedAbility, source);
                            return true;
                        }
                    }
                }
                return false;
            }
        }
        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) TargetCardInHand(mage.target.common.TargetCardInHand) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) Card(mage.cards.Card)

Example 88 with AtTheBeginOfNextEndStepDelayedTriggeredAbility

use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.

the class TwinflameCopyEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        List<Permanent> toExile = new ArrayList<>();
        for (UUID creatureId : this.getTargetPointer().getTargets(game, source)) {
            Permanent creature = game.getPermanentOrLKIBattlefield(creatureId);
            if (creature != null) {
                CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(source.getControllerId(), null, true);
                effect.setTargetPointer(new FixedTarget(creature, game));
                effect.apply(game, source);
                toExile.addAll(effect.getAddedPermanents());
            }
        }
        ExileTargetEffect exileEffect = new ExileTargetEffect();
        exileEffect.setTargetPointer(new FixedTargets(toExile, game));
        DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(exileEffect);
        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) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) FixedTargets(mage.target.targetpointer.FixedTargets) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ArrayList(java.util.ArrayList) UUID(java.util.UUID) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 89 with AtTheBeginOfNextEndStepDelayedTriggeredAbility

use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.

the class DashAddDelayedTriggeredAbilityEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    if (game.getPermanentEntering(source.getSourceId()) != null) {
        OneShotEffect returnToHandEffect = new ReturnToHandTargetEffect();
        ConditionalOneShotEffect mustBeOnBattlefieldToReturn = new ConditionalOneShotEffect(returnToHandEffect, DashAddDelayedTriggeredAbilityEffect::check);
        mustBeOnBattlefieldToReturn.setText("return the dashed creature from the battlefield to its owner's hand");
        // init target pointer now because the dashed creature will only be returned from battlefield zone (now in entering state so zone change counter is not raised yet)
        mustBeOnBattlefieldToReturn.setTargetPointer(new FixedTarget(source.getSourceId(), game.getState().getZoneChangeCounter(source.getSourceId()) + 1));
        DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(mustBeOnBattlefieldToReturn);
        game.addDelayedTriggeredAbility(delayedAbility, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Example 90 with AtTheBeginOfNextEndStepDelayedTriggeredAbility

use of mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility in project mage by magefree.

the class FeatherTheRedeemedEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Spell sourceSpell = game.getStack().getSpell(event.getTargetId());
    if (sourceSpell == null || sourceSpell.isCopy()) {
        return false;
    }
    Player player = game.getPlayer(sourceSpell.getOwnerId());
    if (player == null) {
        return false;
    }
    Effect effect = new ReturnToHandTargetEffect().setText("return " + sourceSpell.getName() + " to its owner's hand");
    player.moveCards(sourceSpell, Zone.EXILED, source, game);
    effect.setTargetPointer(new FixedTarget(event.getTargetId(), game));
    game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Effect(mage.abilities.effects.Effect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) Spell(mage.game.stack.Spell)

Aggregations

AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)143 FixedTarget (mage.target.targetpointer.FixedTarget)115 Permanent (mage.game.permanent.Permanent)101 Player (mage.players.Player)86 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)61 Effect (mage.abilities.effects.Effect)60 OneShotEffect (mage.abilities.effects.OneShotEffect)60 Card (mage.cards.Card)57 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)33 ContinuousEffect (mage.abilities.effects.ContinuousEffect)32 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)31 GainAbilityTargetEffect (mage.abilities.effects.common.continuous.GainAbilityTargetEffect)29 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)27 UUID (java.util.UUID)24 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)21 MageObject (mage.MageObject)20 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)17 FilterCard (mage.filter.FilterCard)16 TargetPermanent (mage.target.TargetPermanent)16 FixedTargets (mage.target.targetpointer.FixedTargets)14