Search in sources :

Example 26 with DamageEvent

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

the class KithkinArmorPreventionEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0 && !this.used) {
        UUID enchantedCreatureId = (UUID) game.getState().getValue(source.getSourceId().toString() + "attachedToPermanent");
        DamageEvent damageEvent = (DamageEvent) event;
        if (enchantedCreatureId != null && event.getTargetId().equals(enchantedCreatureId) && damageEvent.getSourceId().equals(source.getFirstTarget())) {
            this.used = true;
            this.discard();
            return true;
        }
    }
    return false;
}
Also used : DamageEvent(mage.game.events.DamageEvent) UUID(java.util.UUID)

Example 27 with DamageEvent

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

the class LichenthropeEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent p = game.getPermanent(source.getSourceId());
    if (p != null) {
        p.addCounters(CounterType.M1M1.createInstance(damageEvent.getAmount()), source.getControllerId(), source, game);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent)

Example 28 with DamageEvent

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

the class PalisadeGiantReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent sourcePermanent = game.getPermanent(source.getSourceId());
    if (sourcePermanent != null) {
        // get name of old target
        Permanent targetPermanent = game.getPermanent(event.getTargetId());
        StringBuilder message = new StringBuilder();
        message.append(sourcePermanent.getName()).append(": gets ");
        message.append(damageEvent.getAmount()).append(" damage redirected from ");
        if (targetPermanent != null) {
            message.append(targetPermanent.getName());
        } else {
            Player targetPlayer = game.getPlayer(event.getTargetId());
            if (targetPlayer != null) {
                message.append(targetPlayer.getLogName());
            } else {
                message.append("unknown");
            }
        }
        game.informPlayers(message.toString());
        // redirect damage
        sourcePermanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent)

Example 29 with DamageEvent

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

the class PhytohydraEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent p = game.getPermanent(source.getSourceId());
    if (p != null) {
        p.addCounters(CounterType.P1P1.createInstance(damageEvent.getAmount()), source.getControllerId(), source, game);
    }
    return true;
}
Also used : Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent)

Example 30 with DamageEvent

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

the class PhyrexianUnlifeEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!event.getPlayerId().equals(source.getControllerId())) {
        return false;
    }
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    // and all damage in the same step has to be handled the same beause by the rules it's all done at once
    if (((DamageEvent) event).isCombatDamage()) {
        if (lastCheckedDamageStepNum != game.getState().getStepNum()) {
            lastCheckedDamageStepNum = game.getState().getStepNum();
            startedWithLifeAboveZero = player.getLife() > 0;
        }
        if (startedWithLifeAboveZero) {
            return false;
        }
    }
    if (player.getLife() < 1) {
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) DamageEvent(mage.game.events.DamageEvent)

Aggregations

DamageEvent (mage.game.events.DamageEvent)41 Player (mage.players.Player)25 Permanent (mage.game.permanent.Permanent)22 TargetCreaturePermanent (mage.target.common.TargetCreaturePermanent)8 TargetPermanent (mage.target.TargetPermanent)7 MageObject (mage.MageObject)6 FilterPermanent (mage.filter.FilterPermanent)5 FilterCreaturePermanent (mage.filter.common.FilterCreaturePermanent)4 UUID (java.util.UUID)3 AddCountersSourceEffect (mage.abilities.effects.common.counter.AddCountersSourceEffect)2 FilterSpell (mage.filter.FilterSpell)2 BlockedByIdPredicate (mage.filter.predicate.permanent.BlockedByIdPredicate)2 Spell (mage.game.stack.Spell)2 TargetSpell (mage.target.TargetSpell)2 TargetControlledCreaturePermanent (mage.target.common.TargetControlledCreaturePermanent)2 PreventionEffectData (mage.abilities.effects.PreventionEffectData)1 SacrificeControllerEffect (mage.abilities.effects.common.SacrificeControllerEffect)1 CardsImpl (mage.cards.CardsImpl)1 FilterInPlay (mage.filter.FilterInPlay)1 FilterControlledCreaturePermanent (mage.filter.common.FilterControlledCreaturePermanent)1