Search in sources :

Example 6 with DamageEvent

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

the class SavingGraceReplacementEffect 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) {
        Permanent creature = game.getPermanent(sourcePermanent.getAttachedTo());
        if (creature == null) {
            return false;
        }
        // Name of old target
        Permanent targetPermanent = game.getPermanent(event.getTargetId());
        StringBuilder message = new StringBuilder();
        message.append(creature.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
        creature.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) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent)

Example 7 with DamageEvent

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

the class TargetControlledSource method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    MageObject object = game.getObject(event.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null && object != null) {
        if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0) {
            if (wonFlip) {
                event.setAmount(CardUtil.overflowMultiply(event.getAmount(), 2));
                this.discard();
            } else {
                preventDamageAction(event, source, game);
                this.discard();
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) DamageEvent(mage.game.events.DamageEvent)

Example 8 with DamageEvent

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

the class DralnuLichLordFlashbackEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    new SacrificeControllerEffect(new FilterPermanent(), damageEvent.getAmount(), "").apply(game, source);
    return true;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) SacrificeControllerEffect(mage.abilities.effects.common.SacrificeControllerEffect) DamageEvent(mage.game.events.DamageEvent)

Example 9 with DamageEvent

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

the class OraclesAttendantsReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Permanent permanent = game.getPermanent(source.getSourceId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (permanent != null) {
        permanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable());
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DamageEvent(mage.game.events.DamageEvent)

Example 10 with DamageEvent

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

the class SivvisValorEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (controller != null) {
        controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
        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