Search in sources :

Example 1 with PreventDamageEvent

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

the class AuriokReplicaEffect 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();
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return true;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 2 with PreventDamageEvent

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

the class HeartOfLightEffect 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();
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 3 with PreventDamageEvent

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

the class HazeFrogEffect 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();
        Permanent permanent = game.getPermanent(event.getSourceId());
        StringBuilder message = new StringBuilder();
        if (permanent != null) {
            message.append(" from ").append(permanent.getName());
        }
        message.insert(0, "Damage").append(" has been prevented: ").append(damage);
        event.setAmount(0);
        game.informPlayers(message.toString());
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    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 4 with PreventDamageEvent

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

the class PersonalSanctuaryEffect 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();
        event.setAmount(0);
        game.informPlayers("Damage has been prevented: " + damage);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 5 with PreventDamageEvent

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

the class PreventDamageToTargetMultiAmountEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    int targetAmount = targetAmountMap.get(event.getTargetId());
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        if (event.getAmount() >= targetAmount) {
            event.setAmount(event.getAmount() - targetAmount);
            targetAmountMap.remove(event.getTargetId());
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), targetAmount));
        } else {
            int damage = event.getAmount();
            event.setAmount(0);
            targetAmountMap.put(event.getTargetId(), targetAmount - damage);
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        }
        if (targetAmountMap.isEmpty()) {
            this.used = true;
        }
    }
    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