Search in sources :

Example 21 with PreventDamageEvent

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

the class ImmortalCoilPreventionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (game.replaceEvent(new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()))) {
        return false;
    }
    int damage = event.getAmount();
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(Math.min(damage, player.getGraveyard().size()), StaticFilters.FILTER_CARD);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        player.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, 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) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) DamageEvent(mage.game.events.DamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent) CardsImpl(mage.cards.CardsImpl)

Example 22 with PreventDamageEvent

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

the class AcolytesRewardEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean result = false;
    int toPrevent = amount;
    if (event.getAmount() < this.amount) {
        toPrevent = event.getAmount();
        amount -= event.getAmount();
    } else {
        amount = 0;
    }
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage());
    if (game.replaceEvent(preventEvent)) {
        return result;
    }
    Permanent targetCreature = game.getPermanent(event.getTargetId());
    if (targetCreature == null) {
        return result;
    }
    if (amount == 0) {
        this.used = true;
        this.discard();
    }
    if (event.getAmount() >= toPrevent) {
        event.setAmount(event.getAmount() - toPrevent);
    } else {
        event.setAmount(0);
        result = true;
    }
    if (toPrevent == 0) {
        return result;
    }
    game.informPlayers("Acolyte's Reward prevented " + toPrevent + " to " + targetCreature.getName());
    game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent));
    Player targetPlayer = game.getPlayer(source.getTargets().get(1).getFirstTarget());
    if (targetPlayer != null) {
        targetPlayer.damage(toPrevent, source.getSourceId(), source, game);
        game.informPlayers("Acolyte's Reward deals " + toPrevent + " damage to " + targetPlayer.getLogName());
        return result;
    }
    Permanent targetDamageCreature = game.getPermanent(source.getTargets().get(1).getFirstTarget());
    if (targetDamageCreature == null) {
        return result;
    }
    targetDamageCreature.damage(toPrevent, source.getSourceId(), source, game, false, true);
    game.informPlayers("Acolyte's Reward deals " + toPrevent + " damage to " + targetDamageCreature.getName());
    return result;
}
Also used : Player(mage.players.Player) 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 23 with PreventDamageEvent

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

the class BraceForImpactPreventDamageTargetEffect 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;
        int damage = event.getAmount();
        event.setAmount(0);
        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("Brace for Impact: Prevented " + prevented + " damage ");
                game.informPlayers("Brace for Impact: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 24 with PreventDamageEvent

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

the class BattletideAlchemistEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean result = false;
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(event.getTargetId());
    if (controller != null && targetPlayer != null) {
        int numberOfClericsControlled = new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent(SubType.CLERIC, "Clerics")).calculate(game, source, this);
        int toPrevent = Math.min(numberOfClericsControlled, event.getAmount());
        if (toPrevent > 0 && controller.chooseUse(Outcome.PreventDamage, "Prevent " + toPrevent + " damage to " + targetPlayer.getName() + '?', source, game)) {
            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;
                }
                game.informPlayers("Battletide Alchemist prevented " + toPrevent + " damage to " + targetPlayer.getName());
                game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent));
            }
        }
    }
    return result;
}
Also used : Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) GameEvent(mage.game.events.GameEvent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) 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