Search in sources :

Example 1 with PreventDamageToTargetEffect

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

the class WojekApothecaryEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Permanent target = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (target != null) {
            ObjectColor color = target.getColor(game);
            for (Permanent permanent : game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), source.getSourceId(), game)) {
                if (permanent.getColor(game).shares(color)) {
                    ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
                    effect.setTargetPointer(new FixedTarget(permanent, game));
                    game.addEffect(effect, source);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) ObjectColor(mage.ObjectColor) ContinuousEffect(mage.abilities.effects.ContinuousEffect) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Example 2 with PreventDamageToTargetEffect

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

the class ErrantMinionEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Permanent errantMinion = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (errantMinion == null) {
        return false;
    }
    Permanent enchantedCreature = game.getPermanentOrLKIBattlefield(errantMinion.getAttachedTo());
    if (enchantedCreature == null) {
        return false;
    }
    Player controllerOfEnchantedCreature = game.getPlayer(enchantedCreature.getControllerId());
    if (controllerOfEnchantedCreature != null && controllerOfEnchantedCreature.canRespond()) {
        int manaPaid = ManaUtil.playerPaysXGenericMana(false, "Errant Minion", controllerOfEnchantedCreature, source, game);
        if (manaPaid > 0) {
            PreventDamageToTargetEffect effect = new PreventDamageToTargetEffect(Duration.OneUse, manaPaid);
            effect.setTargetPointer(new FixedTarget(controllerOfEnchantedCreature.getId()));
            game.addEffect(effect, source);
            DamageTargetEffect effect2 = new DamageTargetEffect(2);
            effect2.setTargetPointer(new FixedTarget(controllerOfEnchantedCreature.getId()));
            effect2.apply(game, source);
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Example 3 with PreventDamageToTargetEffect

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

the class GuardianAngelDelayedTriggeredAbility method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        String targetName = "";
        Player targetPlayer = game.getPlayer(getTargetPointer().getFirst(game, source));
        if (targetPlayer == null) {
            Permanent targetPermanent = game.getPermanent(getTargetPointer().getFirst(game, source));
            if (targetPermanent == null) {
                return true;
            }
            targetName = targetPermanent.getIdName();
        } else {
            targetName = "player " + targetPlayer.getName();
        }
        ContinuousEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, source.getManaCostsToPay().getX(), false);
        effect.setTargetPointer(getTargetPointer());
        game.addEffect(effect, source);
        SpecialAction specialAction = new GuardianAngelAction();
        specialAction.getEffects().get(0).setTargetPointer(getTargetPointer());
        specialAction.getEffects().get(0).setText("Prevent the next 1 damage that would be dealt to any target this turn (" + targetName + ").");
        new CreateSpecialActionEffect(specialAction).apply(game, source);
        // Create a hidden delayed triggered ability to remove the special action at end of turn.
        new CreateDelayedTriggeredAbilityEffect(new GuardianAngelDelayedTriggeredAbility(specialAction.getId()), false).apply(game, source);
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) SpecialAction(mage.abilities.SpecialAction) Permanent(mage.game.permanent.Permanent) CreateDelayedTriggeredAbilityEffect(mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect) ContinuousEffect(mage.abilities.effects.ContinuousEffect) CreateSpecialActionEffect(mage.abilities.effects.common.CreateSpecialActionEffect) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Example 4 with PreventDamageToTargetEffect

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

the class ElvishHealerEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int toPrevent = 1;
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null && permanent.isCreature(game) && permanent.getColor(game).isGreen()) {
        toPrevent = 2;
    }
    game.addEffect(new PreventDamageToTargetEffect(Duration.EndOfTurn, toPrevent).setTargetPointer(new FixedTarget(source.getFirstTarget(), game)), source);
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Example 5 with PreventDamageToTargetEffect

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

the class KitsunePalliatorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    PreventDamageToTargetEffect effect = new PreventDamageToTargetEffect(Duration.EndOfTurn, 1);
    List<Permanent> permanents = game.getBattlefield().getActivePermanents(StaticFilters.FILTER_PERMANENT_CREATURE, source.getControllerId(), game);
    for (Permanent permanent : permanents) {
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
    }
    for (UUID playerId : game.getState().getPlayersInRange(source.getControllerId(), game)) {
        Player player = game.getPlayer(playerId);
        if (player != null) {
            effect.setTargetPointer(new FixedTarget(player.getId()));
            game.addEffect(effect, source);
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) PreventDamageToTargetEffect(mage.abilities.effects.common.PreventDamageToTargetEffect)

Aggregations

PreventDamageToTargetEffect (mage.abilities.effects.common.PreventDamageToTargetEffect)6 Permanent (mage.game.permanent.Permanent)6 Player (mage.players.Player)5 FixedTarget (mage.target.targetpointer.FixedTarget)5 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 UUID (java.util.UUID)1 ObjectColor (mage.ObjectColor)1 SpecialAction (mage.abilities.SpecialAction)1 CreateDelayedTriggeredAbilityEffect (mage.abilities.effects.common.CreateDelayedTriggeredAbilityEffect)1 CreateSpecialActionEffect (mage.abilities.effects.common.CreateSpecialActionEffect)1 DamageTargetEffect (mage.abilities.effects.common.DamageTargetEffect)1 TargetPermanent (mage.target.TargetPermanent)1