Search in sources :

Example 6 with OneShotEffect

use of mage.abilities.effects.OneShotEffect in project mage by magefree.

the class DoUnlessControllerPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (controller != null && sourceObject != null) {
        String message;
        if (chooseUseText == null) {
            String effectText = executingEffects.getText(source.getModes().getMode());
            message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() - 1) + ")?";
        } else {
            message = chooseUseText;
        }
        message = CardUtil.replaceSourceName(message, sourceObject.getName());
        boolean result = true;
        boolean doEffect = true;
        // check if controller is willing to pay
        if (cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(Outcome.Detriment, message, source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, controller.getId(), false, null)) {
                if (!game.isSimulation()) {
                    game.informPlayers(controller.getLogName() + " pays the cost to prevent the effect");
                }
                doEffect = false;
            }
        }
        // do the effects if not paid
        if (doEffect) {
            for (Effect effect : executingEffects) {
                effect.setTargetPointer(this.targetPointer);
                if (effect instanceof OneShotEffect) {
                    result &= effect.apply(game, source);
                } else {
                    game.addEffect((ContinuousEffect) effect, source);
                }
            }
        }
        return result;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Effect(mage.abilities.effects.Effect) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 7 with OneShotEffect

use of mage.abilities.effects.OneShotEffect 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 8 with OneShotEffect

use of mage.abilities.effects.OneShotEffect in project mage by magefree.

the class KrovikanVampireDelayedTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent krovikanVampire = game.getPermanent(source.getSourceId());
    creaturesAffected = (Set<UUID>) game.getState().getValue(source.getSourceId() + "creatureToGainControl");
    if (creaturesAffected != null && controller != null && krovikanVampire != null) {
        creaturesAffected.stream().map((creatureId) -> {
            controller.moveCards(game.getCard(creatureId), Zone.BATTLEFIELD, source, game, false, false, false, null);
            return creatureId;
        }).map((creatureId) -> {
            OneShotEffect effect = new SacrificeTargetEffect();
            effect.setText("Sacrifice this if Krovikan Vampire leaves the battlefield or its current controller loses control of it.");
            effect.setTargetPointer(new FixedTarget(creatureId, game));
            return effect;
        }).map((effect) -> new KrovikanVampireDelayedTriggeredAbility(effect, krovikanVampire.getId())).forEachOrdered((dTA) -> {
            game.addDelayedTriggeredAbility(dTA, source);
        });
        creaturesAffected.clear();
        return true;
    }
    return false;
}
Also used : Condition(mage.abilities.condition.Condition) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) MageInt(mage.MageInt) BeginningOfEndStepTriggeredAbility(mage.abilities.common.BeginningOfEndStepTriggeredAbility) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) HashSet(java.util.HashSet) Game(mage.game.Game) Watcher(mage.watchers.Watcher) Effect(mage.abilities.effects.Effect) GameEvent(mage.game.events.GameEvent) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) mage.constants(mage.constants) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) Ability(mage.abilities.Ability) FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) SacrificeTargetEffect(mage.abilities.effects.common.SacrificeTargetEffect) UUID(java.util.UUID) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 9 with OneShotEffect

use of mage.abilities.effects.OneShotEffect in project mage by magefree.

the class PlaneswalkersMischiefCondition method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player opponent = game.getPlayer(source.getFirstTarget());
    if (opponent != null && opponent.getHand().size() > 0) {
        Card revealedCard = opponent.getHand().getRandom(game);
        if (revealedCard == null) {
            return false;
        }
        Cards cards = new CardsImpl(revealedCard);
        opponent.revealCards(source, cards, game);
        if (revealedCard.isInstant(game) || revealedCard.isSorcery(game)) {
            opponent.moveCardToExileWithInfo(revealedCard, source.getSourceId(), "Planeswalker's Mischief", source, game, Zone.HAND, true);
            AsThoughEffect effect = new PlaneswalkersMischiefCastFromExileEffect();
            effect.setTargetPointer(new FixedTarget(revealedCard.getId()));
            game.addEffect(effect, source);
            OneShotEffect effect2 = new ReturnFromExileEffect(Zone.HAND);
            Condition condition = new PlaneswalkersMischiefCondition(source.getSourceId(), revealedCard.getId());
            ConditionalOneShotEffect effect3 = new ConditionalOneShotEffect(effect2, condition, "if you haven't cast it, return it to its owner's hand.");
            DelayedTriggeredAbility delayedAbility = new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect3);
            delayedAbility.addWatcher(new SpellsCastWatcher());
            game.addDelayedTriggeredAbility(delayedAbility, source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Condition(mage.abilities.condition.Condition) Player(mage.players.Player) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) AsThoughEffect(mage.abilities.effects.AsThoughEffect) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect)

Example 10 with OneShotEffect

use of mage.abilities.effects.OneShotEffect in project mage by magefree.

the class DoUnlessAttachedControllerPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent aura = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (aura == null) {
        return false;
    }
    Permanent attachedTo = game.getPermanentOrLKIBattlefield(aura.getAttachedTo());
    if (attachedTo == null) {
        return false;
    }
    Player controllerOfAttachedTo = game.getPlayer(attachedTo.getControllerId());
    if (controllerOfAttachedTo != null) {
        String message;
        if (chooseUseText == null) {
            String effectText = executingEffects.getText(source.getModes().getMode());
            message = "Pay " + cost.getText() + " to prevent (" + effectText.substring(0, effectText.length() - 1) + ")?";
        } else {
            message = chooseUseText;
        }
        message = CardUtil.replaceSourceName(message, aura.getName());
        boolean result = true;
        boolean doEffect = true;
        // check if controller is willing to pay
        if (cost.canPay(source, source, controllerOfAttachedTo.getId(), game) && controllerOfAttachedTo.chooseUse(Outcome.Neutral, message, source, game)) {
            cost.clearPaid();
            if (cost.pay(source, game, source, controllerOfAttachedTo.getId(), false, null)) {
                if (!game.isSimulation()) {
                    game.informPlayers(controllerOfAttachedTo.getLogName() + " pays the cost to prevent the effect");
                }
                doEffect = false;
            }
        }
        // do the effects if not paid
        if (doEffect) {
            for (Effect effect : executingEffects) {
                effect.setTargetPointer(this.targetPointer);
                if (effect instanceof OneShotEffect) {
                    result &= effect.apply(game, source);
                } else {
                    game.addEffect((ContinuousEffect) effect, source);
                }
            }
        }
        return result;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) Effect(mage.abilities.effects.Effect) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect)

Aggregations

OneShotEffect (mage.abilities.effects.OneShotEffect)13 Player (mage.players.Player)11 Effect (mage.abilities.effects.Effect)9 MageObject (mage.MageObject)8 ContinuousEffect (mage.abilities.effects.ContinuousEffect)8 FixedTarget (mage.target.targetpointer.FixedTarget)5 UUID (java.util.UUID)3 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)3 Permanent (mage.game.permanent.Permanent)3 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)2 Condition (mage.abilities.condition.Condition)2 Cost (mage.abilities.costs.Cost)2 ConditionalOneShotEffect (mage.abilities.decorator.ConditionalOneShotEffect)2 SacrificeTargetEffect (mage.abilities.effects.common.SacrificeTargetEffect)2 HashSet (java.util.HashSet)1 Set (java.util.Set)1 MageInt (mage.MageInt)1 Ability (mage.abilities.Ability)1 BeginningOfEndStepTriggeredAbility (mage.abilities.common.BeginningOfEndStepTriggeredAbility)1 ConditionalContinuousEffect (mage.abilities.decorator.ConditionalContinuousEffect)1