Search in sources :

Example 1 with PreventDamageByTargetEffect

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

the class FeintEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent creature = game.getPermanent(getTargetPointer().getFirst(game, source));
    if (controller != null && creature != null) {
        for (CombatGroup combatGroup : game.getCombat().getGroups()) {
            if (combatGroup.getAttackers().contains(creature.getId())) {
                for (UUID blockerId : combatGroup.getBlockers()) {
                    Permanent blocker = game.getPermanent(blockerId);
                    if (blocker != null) {
                        blocker.tap(source, game);
                        PreventionEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, true);
                        effect.setTargetPointer(new FixedTarget(blocker.getId(), game));
                        game.addEffect(effect, source);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID) CombatGroup(mage.game.combat.CombatGroup) PreventionEffect(mage.abilities.effects.PreventionEffect)

Example 2 with PreventDamageByTargetEffect

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

the class PowerLeakEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(game.getActivePlayerId());
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    if (player == null || permanent == null) {
        return false;
    }
    ManaCosts<ManaCost> cost = new ManaCostsImpl<>("{X}");
    String message = "Pay {X} to prevent X damage from " + permanent.getLogName() + "?";
    int xValue = 0;
    if (player.chooseUse(Outcome.Neutral, message, source, game)) {
        xValue = player.announceXMana(0, Integer.MAX_VALUE, "Choose the amount of mana to pay", game, source);
        cost.add(new GenericManaCost(xValue));
        if (cost.pay(source, game, source, player.getId(), false, null)) {
            game.informPlayers(player.getLogName() + " paid {" + xValue + "} for " + permanent.getLogName());
        } else {
            game.informPlayers(player.getLogName() + " didn't pay {X} for " + permanent.getLogName());
        }
    } else {
        game.informPlayers(player.getLogName() + " didn't pay {X} for " + permanent.getLogName());
    }
    PreventDamageByTargetEffect effect = new PreventDamageByTargetEffect(Duration.OneUse, xValue, false);
    if (xValue != 0 && cost.isPaid()) {
        effect.setTargetPointer(new FixedTarget(permanent, game));
        game.addEffect(effect, source);
    }
    player.damage(2, source.getSourceId(), source, game);
    effect.discard();
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) Player(mage.players.Player) TargetEnchantmentPermanent(mage.target.common.TargetEnchantmentPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 3 with PreventDamageByTargetEffect

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

the class FightingChanceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        for (UUID blocker : game.getCombat().getBlockers()) {
            if (player.flipCoin(source, game, true)) {
                PreventDamageByTargetEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, true);
                effect.setTargetPointer(new FixedTarget(blocker, game));
                game.addEffect(effect, source);
            }
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) Player(mage.players.Player) UUID(java.util.UUID)

Example 4 with PreventDamageByTargetEffect

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

the class HeroismEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        Player player = game.getPlayer(game.getActivePlayerId());
        Cost cost = new ManaCostsImpl("{2}{R}");
        List<Permanent> permanentsToPrevent = new ArrayList<>();
        for (Permanent permanent : game.getState().getBattlefield().getAllActivePermanents(filter, game.getActivePlayerId(), game)) {
            cost.clearPaid();
            String message = "Pay " + cost.getText() + "? If you don't, " + permanent.getLogName() + "'s combat damage will be prevented this turn.";
            if (player != null) {
                if (player.chooseUse(Outcome.Neutral, message, source, game)) {
                    if (cost.pay(source, game, source, player.getId(), false, null)) {
                        game.informPlayers(player.getLogName() + " paid " + cost.getText() + " for " + permanent.getLogName());
                    } else {
                        game.informPlayers(player.getLogName() + " didn't pay " + cost.getText() + " for " + permanent.getLogName());
                        permanentsToPrevent.add(permanent);
                    }
                } else {
                    game.informPlayers(player.getLogName() + " didn't pay " + cost.getText() + " for " + permanent.getLogName());
                    permanentsToPrevent.add(permanent);
                }
            }
        }
        for (Permanent permanent : permanentsToPrevent) {
            ContinuousEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn, Integer.MAX_VALUE, true);
            effect.setTargetPointer(new FixedTarget(permanent, game));
            game.addEffect(effect, source);
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ArrayList(java.util.ArrayList) ContinuousEffect(mage.abilities.effects.ContinuousEffect) Cost(mage.abilities.costs.Cost) SacrificeTargetCost(mage.abilities.costs.common.SacrificeTargetCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl)

Example 5 with PreventDamageByTargetEffect

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

the class ChainOfSilenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = source.getSourceObject(game);
    if (controller == null || sourceObject == null) {
        return false;
    }
    Permanent permanent = game.getPermanent(source.getFirstTarget());
    if (permanent != null) {
        ContinuousEffect effect = new PreventDamageByTargetEffect(Duration.EndOfTurn);
        game.addEffect(effect, source);
        Player player = game.getPlayer(permanent.getControllerId());
        TargetControlledPermanent target = new TargetControlledPermanent(0, 1, new FilterControlledLandPermanent("a land to sacrifice (to be able to copy " + sourceObject.getName() + ')'), true);
        if (player != null && player.chooseTarget(Outcome.Sacrifice, target, source, game)) {
            Permanent land = game.getPermanent(target.getFirstTarget());
            if (land != null && land.sacrifice(source, game)) {
                if (player.chooseUse(outcome, "Copy the spell?", source, game)) {
                    Spell spell = game.getStack().getSpell(source.getSourceId());
                    if (spell != null) {
                        spell.createCopyOnStack(game, source, player.getId(), true);
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PreventDamageByTargetEffect(mage.abilities.effects.common.PreventDamageByTargetEffect) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) MageObject(mage.MageObject) ContinuousEffect(mage.abilities.effects.ContinuousEffect) FilterControlledLandPermanent(mage.filter.common.FilterControlledLandPermanent) Spell(mage.game.stack.Spell)

Aggregations

PreventDamageByTargetEffect (mage.abilities.effects.common.PreventDamageByTargetEffect)5 Player (mage.players.Player)5 Permanent (mage.game.permanent.Permanent)4 FixedTarget (mage.target.targetpointer.FixedTarget)4 UUID (java.util.UUID)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2 ContinuousEffect (mage.abilities.effects.ContinuousEffect)2 ArrayList (java.util.ArrayList)1 MageObject (mage.MageObject)1 Cost (mage.abilities.costs.Cost)1 SacrificeTargetCost (mage.abilities.costs.common.SacrificeTargetCost)1 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)1 ManaCost (mage.abilities.costs.mana.ManaCost)1 PreventionEffect (mage.abilities.effects.PreventionEffect)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 FilterControlledLandPermanent (mage.filter.common.FilterControlledLandPermanent)1 CombatGroup (mage.game.combat.CombatGroup)1 Spell (mage.game.stack.Spell)1 TargetPermanent (mage.target.TargetPermanent)1 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)1