Search in sources :

Example 6 with PreventionEffectData

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

the class HonorablePassageEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    int damage = event.getAmount();
    PreventionEffectData preventEffectData = preventDamageAction(event, source, game);
    if (preventEffectData.getPreventedDamage() > 0) {
        MageObject sourceObject = game.getObject(event.getSourceId());
        if (sourceObject != null && sourceObject.getColor(game).isRed()) {
            UUID sourceControllerId = game.getControllerId(event.getSourceId());
            if (sourceControllerId != null) {
                Player sourceController = game.getPlayer(sourceControllerId);
                if (sourceController != null) {
                    sourceController.damage(damage, source.getSourceId(), source, game);
                }
            }
        }
        this.used = true;
    }
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) MageObject(mage.MageObject) UUID(java.util.UUID)

Example 7 with PreventionEffectData

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

the class ReverseDamageEffect 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)

Example 8 with PreventionEffectData

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

the class SamiteMinistrationEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionData = preventDamageAction(event, source, game);
    MageObject sourceObject = game.getObject(event.getSourceId());
    if (sourceObject != null && (sourceObject.getColor(game).isBlack() || sourceObject.getColor(game).isRed())) {
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            player.gainLife(preventionData.getPreventedDamage(), game, source);
        }
    }
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) MageObject(mage.MageObject)

Example 9 with PreventionEffectData

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

the class SoltariGuerrillasReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionResult = preventDamageAction(event, source, game);
    if (preventionResult.getPreventedDamage() > 0) {
        Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (redirectTo != null) {
            game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + redirectTo.getLogName() + " instead.");
            DamageEvent damageEvent = (DamageEvent) event;
            redirectTo.damage(preventionResult.getPreventedDamage(), event.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
        }
        // (only once)
        discard();
    }
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DamageEvent(mage.game.events.DamageEvent)

Example 10 with PreventionEffectData

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

the class RefractionTrapPreventDamageEffect 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) {
        UUID damageTarget = getTargetPointer().getFirst(game, source);
        Permanent permanent = game.getPermanent(damageTarget);
        if (permanent != null) {
            game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + permanent.getLogName());
            permanent.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game, false, true);
        }
        Player player = game.getPlayer(damageTarget);
        if (player != null) {
            game.informPlayers("Dealing " + preventionData.getPreventedDamage() + " to " + player.getLogName());
            player.damage(preventionData.getPreventedDamage(), source.getSourceId(), source, game);
        }
    }
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) UUID(java.util.UUID)

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