Search in sources :

Example 16 with PreventionEffectData

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

the class SwansOfBrynArgollEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionEffectData = preventDamageAction(event, source, game);
    if (preventionEffectData.getPreventedDamage() > 0) {
        boolean passed = false;
        MageObject sourceOfDamage = game.getObject(event.getSourceId());
        if (sourceOfDamage != null) {
            Spell spell = game.getStack().getSpell(sourceOfDamage.getId());
            Permanent permanent = game.getPermanentOrLKIBattlefield(sourceOfDamage.getId());
            CommandObject emblem = (CommandObject) game.getEmblem(sourceOfDamage.getId());
            if (spell != null) {
                Player controllerOfSpell = game.getPlayer(spell.getControllerId());
                if (controllerOfSpell != null) {
                    // original event is not a draw event, so skip it in params
                    controllerOfSpell.drawCards(preventionEffectData.getPreventedDamage(), source, game);
                    passed = true;
                }
            }
            if (permanent != null) {
                Player controllerOfPermanent = game.getPlayer(permanent.getControllerId());
                if (controllerOfPermanent != null) {
                    // original event is not a draw event, so skip it in params
                    controllerOfPermanent.drawCards(preventionEffectData.getPreventedDamage(), source, game);
                    passed = true;
                }
            }
            if (emblem != null) {
                Player controllerOfEmblem = game.getPlayer(emblem.getControllerId());
                if (controllerOfEmblem != null) {
                    // original event is not a draw event, so skip it in params
                    controllerOfEmblem.drawCards(preventionEffectData.getPreventedDamage(), source, game);
                }
                passed = true;
            }
            if (!passed) {
                // Needed for cards that do damage from hand e.g. Gempalm Incinerator
                Card cardSource = game.getCard(event.getSourceId());
                if (cardSource != null) {
                    Player owner = game.getPlayer(cardSource.getOwnerId());
                    if (owner != null) {
                        // original event is not a draw event, so skip it in params
                        owner.drawCards(preventionEffectData.getPreventedDamage(), source, game);
                    }
                }
            }
        }
    }
    return preventionEffectData.isReplaced();
}
Also used : CommandObject(mage.game.command.CommandObject) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) Card(mage.cards.Card)

Example 17 with PreventionEffectData

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

the class VengefulArchonEffect method preventDamageAction.

@Override
protected PreventionEffectData preventDamageAction(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionEffectData = super.preventDamageAction(event, source, game);
    int damage = preventionEffectData.getPreventedDamage();
    if (damage > 0) {
        game.damagePlayerOrPlaneswalker(source.getFirstTarget(), damage, source.getSourceId(), source, game, false, true);
    }
    return preventionEffectData;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData)

Example 18 with PreventionEffectData

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

the class ChannelHarmEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player sourceController = game.getPlayer(source.getControllerId());
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    if (preventionData.getPreventedDamage() > 0) {
        Permanent targetCreature = game.getPermanent(source.getFirstTarget());
        if (targetCreature != null) {
            if (sourceController != null && sourceController.chooseUse(outcome, "Have " + preventionData.getPreventedDamage() + " damage dealt to " + targetCreature.getLogName() + "?", source, game)) {
                targetCreature.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game, false, true);
            }
        }
    }
    return true;
}
Also used : Player(mage.players.Player) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent)

Example 19 with PreventionEffectData

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

the class ChantOfVituGhaziPreventEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.gainLife(preventionData.getPreventedDamage(), game, source);
    }
    // damage amount is reduced or set to 0 so complete replacement of damage event is never neccessary
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player)

Example 20 with PreventionEffectData

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

the class ChoArrimAlchemistEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    this.used = true;
    // only one use
    this.discard();
    if (preventionData.getPreventedDamage() > 0) {
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            player.gainLife(preventionData.getPreventedDamage(), game, source);
        }
    }
    return true;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player)

Aggregations

PreventionEffectData (mage.abilities.effects.PreventionEffectData)20 Player (mage.players.Player)17 Permanent (mage.game.permanent.Permanent)8 MageObject (mage.MageObject)6 UUID (java.util.UUID)5 Spell (mage.game.stack.Spell)3 Ability (mage.abilities.Ability)2 Card (mage.cards.Card)2 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)2 CommandObject (mage.game.command.CommandObject)1 DamageEvent (mage.game.events.DamageEvent)1 TargetPlayer (mage.target.TargetPlayer)1