Search in sources :

Example 21 with DamageEvent

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

the class SivvisValorEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
    if (controller != null && targetPermanent != null) {
        return targetPermanent.getId().equals(damageEvent.getTargetId());
    }
    return false;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) TargetControlledPermanent(mage.target.common.TargetControlledPermanent) DamageEvent(mage.game.events.DamageEvent)

Example 22 with DamageEvent

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

the class OpalEyeKondasYojimboRedirectionEffect 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
        discard();
        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 23 with DamageEvent

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

the class ReverberationEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Spell targetSpell = game.getStack().getSpell(source.getFirstTarget());
    if (targetSpell != null) {
        return damageEvent.getAmount() > 0;
    }
    return false;
}
Also used : DamageEvent(mage.game.events.DamageEvent) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 24 with DamageEvent

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

the class ShieldDancerRedirectionEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (event.getTargetId().equals(source.getSourceId()) && event.getSourceId().equals(source.getTargets().get(0).getFirstTarget())) {
        DamageEvent damageEvent = (DamageEvent) event;
        if (damageEvent.isCombatDamage()) {
            TargetPermanent target = new TargetPermanent();
            target.add(source.getTargets().get(0).getFirstTarget(), game);
            redirectTarget = target;
        }
        return true;
    }
    return false;
}
Also used : TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent)

Example 25 with DamageEvent

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

the class JadeMonolithRedirectionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    Permanent targetCreature = game.getPermanent(source.getFirstTarget());
    MageObject sourceObject = game.getObject(source.getSourceId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (controller != null && targetCreature != null && sourceObject != null) {
        controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
        StringBuilder sb = new StringBuilder(sourceObject.getLogName());
        sb.append(": ").append(damageEvent.getAmount()).append(" damage redirected from ").append(targetCreature.getLogName());
        sb.append(" to ").append(controller.getLogName());
        game.informPlayers(sb.toString());
        // only one use
        discard();
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) MageObject(mage.MageObject) 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