Search in sources :

Example 1 with CounterTargetWithReplacementEffect

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

the class DelayEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(getTargetPointer().getFirst(game, source));
    if (controller != null && spell != null) {
        Effect effect = new CounterTargetWithReplacementEffect(Zone.EXILED);
        effect.setTargetPointer(targetPointer);
        Card card = game.getCard(spell.getSourceId());
        if (card != null && effect.apply(game, source) && game.getState().getZone(card.getId()) == Zone.EXILED) {
            boolean hasSuspend = card.getAbilities(game).containsClass(SuspendAbility.class);
            UUID exileId = SuspendAbility.getSuspendExileId(controller.getId(), game);
            if (controller.moveCardToExileWithInfo(card, exileId, "Suspended cards of " + controller.getLogName(), source, game, Zone.HAND, true)) {
                card.addCounters(CounterType.TIME.createInstance(3), source.getControllerId(), source, game);
                if (!hasSuspend) {
                    game.addEffect(new GainSuspendEffect(new MageObjectReference(card, game)), source);
                }
                game.informPlayers(controller.getLogName() + " suspends 3 - " + card.getName());
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) CounterTargetWithReplacementEffect(mage.abilities.effects.common.CounterTargetWithReplacementEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CounterTargetWithReplacementEffect(mage.abilities.effects.common.CounterTargetWithReplacementEffect) GainSuspendEffect(mage.abilities.effects.common.continuous.GainSuspendEffect) UUID(java.util.UUID) GainSuspendEffect(mage.abilities.effects.common.continuous.GainSuspendEffect) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell) MageObjectReference(mage.MageObjectReference) Card(mage.cards.Card)

Aggregations

UUID (java.util.UUID)1 MageObjectReference (mage.MageObjectReference)1 Effect (mage.abilities.effects.Effect)1 OneShotEffect (mage.abilities.effects.OneShotEffect)1 CounterTargetWithReplacementEffect (mage.abilities.effects.common.CounterTargetWithReplacementEffect)1 GainSuspendEffect (mage.abilities.effects.common.continuous.GainSuspendEffect)1 Card (mage.cards.Card)1 Spell (mage.game.stack.Spell)1 Player (mage.players.Player)1 TargetSpell (mage.target.TargetSpell)1