Search in sources :

Example 16 with PreventedDamageEvent

use of mage.game.events.PreventedDamageEvent in project mage by magefree.

the class MagebaneArmorPreventionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent equipment = game.getPermanent(source.getSourceId());
    if (equipment != null && equipment.getAttachedTo() != null) {
        GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
        if (!game.replaceEvent(preventEvent)) {
            int damage = event.getAmount();
            event.setAmount(0);
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
            return true;
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 17 with PreventedDamageEvent

use of mage.game.events.PreventedDamageEvent in project mage by magefree.

the class ShieldOfTheAvatarPreventionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean result = false;
    Permanent equipment = game.getPermanent(source.getSourceId());
    if (equipment != null && equipment.getAttachedTo() != null) {
        int numberOfCreaturesControlled = CreaturesYouControlCount.instance.calculate(game, source, this);
        int toPrevent = Math.min(numberOfCreaturesControlled, event.getAmount());
        GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage());
        if (!game.replaceEvent(preventEvent)) {
            if (event.getAmount() >= toPrevent) {
                event.setAmount(event.getAmount() - toPrevent);
            } else {
                event.setAmount(0);
                result = true;
            }
            if (toPrevent > 0) {
                game.informPlayers("Shield of the Avatar " + "prevented " + toPrevent + " damage to " + game.getPermanent(equipment.getAttachedTo()).getName());
                game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent));
            }
        }
    }
    return result;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent) CreaturesYouControlHint(mage.abilities.hint.common.CreaturesYouControlHint)

Example 18 with PreventedDamageEvent

use of mage.game.events.PreventedDamageEvent in project mage by magefree.

the class NineLivesStateTriggeredAbility method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int damage = event.getAmount();
        Player player = game.getPlayer(source.getControllerId());
        if (player != null) {
            Permanent nineLives = source.getSourcePermanentIfItStillExists(game);
            if (nineLives != null) {
                nineLives.addCounters(CounterType.INCARNATION.createInstance(1), source.getControllerId(), source, game);
            }
        }
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 19 with PreventedDamageEvent

use of mage.game.events.PreventedDamageEvent in project mage by magefree.

the class TestOfFaithPreventDamageTargetEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int prevented = 0;
        if (event.getAmount() >= this.amount) {
            int damage = amount;
            event.setAmount(event.getAmount() - amount);
            this.used = true;
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
            prevented = damage;
        } else {
            int damage = event.getAmount();
            event.setAmount(0);
            amount -= damage;
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
            prevented = damage;
        }
        // add counters now
        if (prevented > 0) {
            Permanent targetPermanent = game.getPermanent(source.getTargets().getFirstTarget());
            if (targetPermanent != null) {
                targetPermanent.addCounters(CounterType.P1P1.createInstance(prevented), source.getControllerId(), source, game);
                game.informPlayers("Test of Faith: Prevented " + prevented + " damage ");
                game.informPlayers("Test of Faith: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 20 with PreventedDamageEvent

use of mage.game.events.PreventedDamageEvent in project mage by magefree.

the class GhostsOfTheInnocentPreventDamageEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    int amount = (int) Math.ceil(event.getAmount() / 2.0);
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), amount, ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        event.setAmount(event.getAmount() - amount);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), amount));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Aggregations

PreventDamageEvent (mage.game.events.PreventDamageEvent)24 PreventedDamageEvent (mage.game.events.PreventedDamageEvent)24 GameEvent (mage.game.events.GameEvent)23 Permanent (mage.game.permanent.Permanent)11 Player (mage.players.Player)5 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)4 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)2 MageObject (mage.MageObject)1 PermanentsOnBattlefieldCount (mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount)1 CreaturesYouControlHint (mage.abilities.hint.common.CreaturesYouControlHint)1 CardsImpl (mage.cards.CardsImpl)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1 DamageEvent (mage.game.events.DamageEvent)1 TargetCardInYourGraveyard (mage.target.common.TargetCardInYourGraveyard)1