Search in sources :

Example 6 with PreventedDamageEvent

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

the class VigorReplacementEffect 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 preventedDamage = event.getAmount();
        event.setAmount(0);
        Permanent permanent = game.getPermanent(event.getTargetId());
        if (permanent != null) {
            permanent.addCounters(CounterType.P1P1.createInstance(preventedDamage), source.getControllerId(), source, game);
        }
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), preventedDamage));
        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 7 with PreventedDamageEvent

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

the class StonewiseFortifierPreventAllDamageToEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), event.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int preventedDamage = event.getAmount();
        MageObject damageSource = game.getObject(event.getSourceId());
        MageObject preventionSource = game.getObject(source.getSourceId());
        if (damageSource != null && preventionSource != null) {
            String message = " damage from " + damageSource.getName() + " prevented " + '(' + preventionSource + ')';
            game.informPlayers(message);
        }
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), preventedDamage));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) MageObject(mage.MageObject) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 8 with PreventedDamageEvent

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

the class PilgrimOfVirtueEffect 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);
        // one time use
        this.used = true;
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        return true;
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 9 with PreventedDamageEvent

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

the class PhyrexianHydraEffect method replaceEvent.

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

Example 10 with PreventedDamageEvent

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

the class PilgrimOfJusticeEffect 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);
        // one time use
        this.used = true;
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        return 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