Search in sources :

Example 11 with OneShotEffect

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

the class DoIfClashWonEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = getPayingPlayer(game, source);
    MageObject mageObject = game.getObject(source.getSourceId());
    if (player != null && mageObject != null) {
        String message = null;
        if (chooseUseText != null) {
            message = chooseUseText;
            message = CardUtil.replaceSourceName(message, mageObject.getLogName());
        }
        if (chooseUseText == null || player.chooseUse(executingEffect.getOutcome(), message, source, game)) {
            if (ClashEffect.getInstance().apply(game, source)) {
                if (setTargetPointerToClashedOpponent) {
                    Object opponent = getValue("clashOpponent");
                    if (opponent instanceof Player) {
                        executingEffect.setTargetPointer(new FixedTarget(((Player) opponent).getId()));
                    }
                } else {
                    executingEffect.setTargetPointer(this.targetPointer);
                }
                if (executingEffect instanceof OneShotEffect) {
                    return executingEffect.apply(game, source);
                } else {
                    game.addEffect((ContinuousEffect) executingEffect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) MageObject(mage.MageObject) MageObject(mage.MageObject) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 12 with OneShotEffect

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

the class DoUnlessAnyPlayerPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    Cost costToPay;
    String costValueMessage;
    if (controller != null && sourceObject != null) {
        if (cost != null) {
            costToPay = cost.copy();
            costValueMessage = costToPay.getText();
        } else {
            costToPay = ManaUtil.createManaCost(genericMana, game, source, this);
            costValueMessage = "{" + genericMana.calculate(game, source, this) + "}";
        }
        String message;
        if (chooseUseText == null) {
            String effectText = executingEffects.getText(source.getModes().getMode());
            message = "Pay " + costValueMessage + " 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 any player is willing to pay
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player != null && player.canRespond() && costToPay.canPay(source, source, player.getId(), game) && player.chooseUse(Outcome.Detriment, message, source, game)) {
                costToPay.clearPaid();
                if (costToPay.pay(source, game, source, player.getId(), false, null)) {
                    if (!game.isSimulation()) {
                        game.informPlayers(player.getLogName() + " pays the cost to prevent the effect");
                    }
                    doEffect = false;
                    break;
                }
            }
        }
        // do the effects if nobody 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) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 13 with OneShotEffect

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

the class AbilityImpl method resolveMode.

private boolean resolveMode(Game game) {
    boolean result = true;
    for (Effect effect : getEffects()) {
        if (game.inCheckPlayableState() && !(effect instanceof ManaEffect)) {
            // Ignored non mana effects - see GameEvent.TAPPED_FOR_MANA
            continue;
        }
        if (effect instanceof OneShotEffect) {
            boolean effectResult = effect.apply(game, this);
            result &= effectResult;
            if (logger.isDebugEnabled()) {
                if (this.getAbilityType() != AbilityType.MANA) {
                    if (!effectResult) {
                        if (this.getSourceId() != null) {
                            MageObject mageObject = game.getObject(this.getSourceId());
                            if (mageObject != null) {
                                logger.debug("AbilityImpl.resolve: object: " + mageObject.getName());
                            }
                        }
                        logger.debug("AbilityImpl.resolve: effect returned false -" + effect.getText(this.getModes().getMode()));
                    }
                }
            }
        } else {
            game.addEffect((ContinuousEffect) effect, this);
        }
        /**
         * All restrained trigger events are fired now. To restrain the
         * events is mainly neccessary because of the movement of multiple
         * object at once. If the event is fired directly as one object
         * moved, other objects are not already in the correct zone to check
         * for their effects. (e.g. Valakut, the Molten Pinnacle)
         */
        game.getState().handleSimultaneousEvent(game);
        game.resetShortLivingLKI();
        /**
         * game.applyEffects() has to be done at least for every effect that
         * moves cards/permanent between zones, or changes control of
         * objects so Static effects work as intended if dependant from the
         * moved objects zone it is in Otherwise for example were static
         * abilities with replacement effects deactivated too late Example:
         * {@link org.mage.test.cards.replacement.DryadMilitantTest#testDiesByDestroy testDiesByDestroy}
         */
        game.applyEffects();
        game.getState().getTriggers().checkStateTriggers(game);
    }
    return result;
}
Also used : ManaEffect(mage.abilities.effects.mana.ManaEffect) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ManaEffect(mage.abilities.effects.mana.ManaEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) 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