Search in sources :

Example 16 with AtTheEndOfCombatDelayedTriggeredAbility

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

the class CreateTokenEffect method exileTokensCreatedAtEndOfCombat.

public void exileTokensCreatedAtEndOfCombat(Game game, Ability source) {
    for (UUID tokenId : this.getLastAddedTokenIds()) {
        Permanent tokenPermanent = game.getPermanent(tokenId);
        if (tokenPermanent != null) {
            ExileTargetEffect exileEffect = new ExileTargetEffect(null, "", Zone.BATTLEFIELD);
            exileEffect.setTargetPointer(new FixedTarget(tokenPermanent, game));
            game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
        }
    }
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) UUID(java.util.UUID)

Example 17 with AtTheEndOfCombatDelayedTriggeredAbility

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

the class MyriadEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourceObject = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && sourceObject != null) {
        UUID defendingPlayerId = game.getCombat().getDefendingPlayerId(source.getSourceId(), game);
        if (defendingPlayerId == null) {
            Logger.getLogger(MyriadEffect.class).error("defending player == null source: " + sourceObject.getName() + " attacking: " + (sourceObject.isAttacking() ? "Y" : "N"));
            return false;
        }
        List<Permanent> tokens = new ArrayList<>();
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            if (!playerId.equals(defendingPlayerId) && controller.hasOpponent(playerId, game)) {
                Player opponent = game.getPlayer(playerId);
                if (opponent != null && controller.chooseUse(Outcome.PutCreatureInPlay, "Put a copy of " + sourceObject.getIdName() + " onto battlefield attacking " + opponent.getName() + '?', source, game)) {
                    CreateTokenCopyTargetEffect effect = new CreateTokenCopyTargetEffect(controller.getId(), null, false, 1, true, true, playerId);
                    effect.setTargetPointer(new FixedTarget(sourceObject, game));
                    effect.apply(game, source);
                    tokens.addAll(effect.getAddedPermanents());
                }
            }
        }
        if (!tokens.isEmpty()) {
            ExileTargetEffect exileEffect = new ExileTargetEffect();
            exileEffect.setTargetPointer(new FixedTargets(tokens, game));
            game.addDelayedTriggeredAbility(new AtTheEndOfCombatDelayedTriggeredAbility(exileEffect), source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) FixedTargets(mage.target.targetpointer.FixedTargets) ArrayList(java.util.ArrayList) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) UUID(java.util.UUID) CreateTokenCopyTargetEffect(mage.abilities.effects.common.CreateTokenCopyTargetEffect) ExileTargetEffect(mage.abilities.effects.common.ExileTargetEffect)

Example 18 with AtTheEndOfCombatDelayedTriggeredAbility

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

the class ClockworkDragonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent p = game.getPermanent(source.getSourceId());
    if (p != null) {
        AtTheEndOfCombatDelayedTriggeredAbility ability = new AtTheEndOfCombatDelayedTriggeredAbility(new RemoveCounterSourceEffect(CounterType.P1P1.createInstance()));
        game.addDelayedTriggeredAbility(ability, source);
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility) RemoveCounterSourceEffect(mage.abilities.effects.common.counter.RemoveCounterSourceEffect)

Example 19 with AtTheEndOfCombatDelayedTriggeredAbility

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

the class ContemptEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent contempt = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (contempt != null) {
        Permanent attachedToPermanent = game.getPermanent(contempt.getAttachedTo());
        if (attachedToPermanent != null) {
            Effect effect = new ReturnToHandTargetEffect();
            effect.setTargetPointer(new FixedTarget(attachedToPermanent.getId(), game)).setText("return " + attachedToPermanent.getName() + " to owner's hand.");
            AtTheEndOfCombatDelayedTriggeredAbility ability = new AtTheEndOfCombatDelayedTriggeredAbility(effect);
            game.addDelayedTriggeredAbility(ability, source);
        }
        Effect effect = new ReturnToHandSourceEffect();
        AtTheEndOfCombatDelayedTriggeredAbility ability = new AtTheEndOfCombatDelayedTriggeredAbility(effect);
        game.addDelayedTriggeredAbility(ability, source);
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) ReturnToHandSourceEffect(mage.abilities.effects.common.ReturnToHandSourceEffect) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) OneShotEffect(mage.abilities.effects.OneShotEffect) ReturnToHandSourceEffect(mage.abilities.effects.common.ReturnToHandSourceEffect) Effect(mage.abilities.effects.Effect) AttachEffect(mage.abilities.effects.common.AttachEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) AtTheEndOfCombatDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)

Aggregations

AtTheEndOfCombatDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheEndOfCombatDelayedTriggeredAbility)19 Permanent (mage.game.permanent.Permanent)14 FixedTarget (mage.target.targetpointer.FixedTarget)10 Effect (mage.abilities.effects.Effect)6 OneShotEffect (mage.abilities.effects.OneShotEffect)6 ExileTargetEffect (mage.abilities.effects.common.ExileTargetEffect)6 CreateTokenCopyTargetEffect (mage.abilities.effects.common.CreateTokenCopyTargetEffect)5 Player (mage.players.Player)5 FixedTargets (mage.target.targetpointer.FixedTargets)5 UUID (java.util.UUID)4 TargetPermanent (mage.target.TargetPermanent)4 MageObjectReference (mage.MageObjectReference)3 RemoveCounterSourceEffect (mage.abilities.effects.common.counter.RemoveCounterSourceEffect)3 CreateDelayedTriggeredAbilityEffect (mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect)2 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)2 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)2 Card (mage.cards.Card)2 Token (mage.game.permanent.token.Token)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 ArrayList (java.util.ArrayList)1