Search in sources :

Example 1 with PreventionEffectData

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

the class BoneMaskEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!this.used && super.applies(event, source, game)) {
        if (event.getTargetId().equals(source.getControllerId()) && event.getSourceId().equals(source.getFirstTarget())) {
            PreventionEffectData preventionData = preventDamageAction(event, source, game);
            this.used = true;
            this.discard();
            if (preventionData.getPreventedDamage() > 0) {
                Player controller = game.getPlayer(source.getControllerId());
                if (controller != null) {
                    Set<Card> cardsToMoveToExileFromTopOfLibrary = controller.getLibrary().getTopCards(game, preventionData.getPreventedDamage());
                    controller.moveCards(cardsToMoveToExileFromTopOfLibrary, Zone.EXILED, source, game);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Card(mage.cards.Card)

Example 2 with PreventionEffectData

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

the class DeflectingPalmEffect 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) {
        MageObject damageDealingObject = game.getObject(target.getFirstTarget());
        UUID objectControllerId = null;
        if (damageDealingObject instanceof Permanent) {
            objectControllerId = ((Permanent) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Ability) {
            objectControllerId = ((Ability) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Spell) {
            objectControllerId = ((Spell) damageDealingObject).getControllerId();
        }
        if (objectControllerId != null) {
            Player objectController = game.getPlayer(objectControllerId);
            if (objectController != null) {
                objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Ability(mage.abilities.Ability) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 3 with PreventionEffectData

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

the class AweStrikeEffect method replaceEvent.

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

Example 4 with PreventionEffectData

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

the class ComeuppanceEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    if (preventionData.getPreventedDamage() > 0) {
        MageObject damageDealingObject = game.getObject(event.getSourceId());
        UUID objectControllerId = null;
        if (damageDealingObject instanceof Permanent) {
            if (damageDealingObject.isCreature(game)) {
                ((Permanent) damageDealingObject).damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            } else {
                objectControllerId = ((Permanent) damageDealingObject).getControllerId();
            }
        } else if (damageDealingObject instanceof Ability) {
            objectControllerId = ((Ability) damageDealingObject).getControllerId();
        } else if (damageDealingObject instanceof Spell) {
            objectControllerId = ((Spell) damageDealingObject).getControllerId();
        }
        if (objectControllerId != null) {
            Player objectController = game.getPlayer(objectControllerId);
            if (objectController != null) {
                objectController.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
            }
        }
    }
    return true;
}
Also used : Ability(mage.abilities.Ability) PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) MageObject(mage.MageObject) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 5 with PreventionEffectData

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

the class HallowPreventDamageByTargetEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionEffectData = preventDamageAction(event, source, game);
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        controller.gainLife(preventionEffectData.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