Search in sources :

Example 96 with Effect

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

the class VoyagerStaffEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
    Player controller = game.getPlayer(source.getControllerId());
    Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (controller != null && creature != null && sourcePermanent != null) {
        if (controller.moveCardToExileWithInfo(creature, source.getSourceId(), sourcePermanent.getIdName(), source, game, Zone.BATTLEFIELD, true)) {
            // create delayed triggered ability
            Effect effect = new ReturnToBattlefieldUnderOwnerControlTargetEffect(false, true);
            effect.setText("Return the exiled card to the battlefield under its owner's control at the beginning of the next end step");
            effect.setTargetPointer(new FixedTarget(creature.getId(), game.getState().getZoneChangeCounter(creature.getId())));
            game.addDelayedTriggeredAbility(new AtTheBeginOfNextEndStepDelayedTriggeredAbility(effect), 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) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) ReturnToBattlefieldUnderOwnerControlTargetEffect(mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect)

Example 97 with Effect

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

the class VraskaTheUnseenTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (((DamagedEvent) event).isCombatDamage() && getSourceId().equals(event.getTargetId())) {
        Permanent sourceOfDamage = game.getPermanent(event.getSourceId());
        if (sourceOfDamage != null && sourceOfDamage.isCreature(game)) {
            Effect effect = this.getEffects().get(0);
            effect.setTargetPointer(new FixedTarget(sourceOfDamage.getId(), game));
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) TargetNonlandPermanent(mage.target.common.TargetNonlandPermanent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect)

Example 98 with Effect

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

the class DoIfCostPaid 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;
        if (chooseUseText == null) {
            String effectText = executingEffects.getText(source.getModes().getMode());
            if (!effectText.isEmpty() && effectText.charAt(effectText.length() - 1) == '.') {
                effectText = effectText.substring(0, effectText.length() - 1);
            }
            message = CardUtil.addCostVerb(cost.getText()) + (effectText.isEmpty() ? "" : " and " + effectText) + "?";
            message = Character.toUpperCase(message.charAt(0)) + message.substring(1);
        } else {
            message = chooseUseText;
        }
        message = CardUtil.replaceSourceName(message, mageObject.getName());
        boolean result = true;
        Outcome payOutcome = executingEffects.getOutcome(source, this.outcome);
        if (cost.canPay(source, source, player.getId(), game) && (!optional || player.chooseUse(payOutcome, message, source, game))) {
            cost.clearPaid();
            int bookmark = game.bookmarkState();
            if (cost.pay(source, game, source, player.getId(), false)) {
                game.informPlayers(player.getLogName() + " paid for " + mageObject.getLogName() + " - " + message);
                if (!executingEffects.isEmpty()) {
                    for (Effect effect : executingEffects) {
                        effect.setTargetPointer(this.targetPointer);
                        if (effect instanceof OneShotEffect) {
                            result &= effect.apply(game, source);
                        } else {
                            game.addEffect((ContinuousEffect) effect, source);
                        }
                    }
                }
                // otherwise you can e.g. undo card drawn with Mentor of the Meek
                player.resetStoredBookmark(game);
            } else {
                // Paying cost was cancels so try to undo payment so far
                player.restoreState(bookmark, DoIfCostPaid.class.getName(), game);
                if (!otherwiseEffects.isEmpty()) {
                    for (Effect effect : otherwiseEffects) {
                        effect.setTargetPointer(this.targetPointer);
                        if (effect instanceof OneShotEffect) {
                            result &= effect.apply(game, source);
                        } else {
                            game.addEffect((ContinuousEffect) effect, source);
                        }
                    }
                }
            }
        } else if (!otherwiseEffects.isEmpty()) {
            for (Effect effect : otherwiseEffects) {
                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) Outcome(mage.constants.Outcome) MageObject(mage.MageObject) Effect(mage.abilities.effects.Effect) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 99 with Effect

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

the class DoUnlessTargetPlayerOrTargetsControllerPaysEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(this.getTargetPointer().getFirst(game, source));
    Permanent targetPermanent = game.getPermanentOrLKIBattlefield(this.getTargetPointer().getFirst(game, source));
    if (targetPermanent != null) {
        player = game.getPlayer(targetPermanent.getControllerId());
    }
    MageObject sourceObject = game.getObject(source.getSourceId());
    if (player != null && sourceObject != null) {
        Cost costToPay;
        String costValueMessage;
        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 targetController is willing to pay
        if (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;
            }
        }
        // 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);
                }
            }
        } else if (otherwiseEffect != null) {
            otherwiseEffect.setTargetPointer(this.targetPointer);
            if (otherwiseEffect instanceof OneShotEffect) {
                result &= otherwiseEffect.apply(game, source);
            } else {
                game.addEffect((ContinuousEffect) otherwiseEffect, source);
            }
        }
        return result;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) OneShotEffect(mage.abilities.effects.OneShotEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Effect(mage.abilities.effects.Effect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) OneShotEffect(mage.abilities.effects.OneShotEffect)

Example 100 with Effect

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

the class FlipCoinEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject mageObject = game.getObject(source.getSourceId());
    if (controller == null || mageObject == null) {
        return false;
    }
    boolean result = true;
    for (Effect effect : controller.flipCoin(source, game, true) ? executingEffectsWon : executingEffectsLost) {
        effect.setTargetPointer(this.targetPointer);
        if (effect instanceof OneShotEffect) {
            result &= effect.apply(game, source);
        } else {
            game.addEffect((ContinuousEffect) effect, source);
        }
    }
    return result;
}
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)

Aggregations

Effect (mage.abilities.effects.Effect)328 OneShotEffect (mage.abilities.effects.OneShotEffect)254 FixedTarget (mage.target.targetpointer.FixedTarget)224 Permanent (mage.game.permanent.Permanent)180 Player (mage.players.Player)167 UUID (java.util.UUID)75 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)60 Card (mage.cards.Card)57 MageObject (mage.MageObject)41 ContinuousEffect (mage.abilities.effects.ContinuousEffect)40 TargetPermanent (mage.target.TargetPermanent)39 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)38 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)38 FilterPermanent (mage.filter.FilterPermanent)29 ReturnToBattlefieldUnderOwnerControlTargetEffect (mage.abilities.effects.common.ReturnToBattlefieldUnderOwnerControlTargetEffect)28 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)27 AddCountersTargetEffect (mage.abilities.effects.common.counter.AddCountersTargetEffect)25 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)24 AttachEffect (mage.abilities.effects.common.AttachEffect)23 Target (mage.target.Target)22