Search in sources :

Example 16 with DamageEvent

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

the class AscentOfTheWorthyReturnEffect method replaceEvent.

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

Example 17 with DamageEvent

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

the class DarkSpherePreventionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    MageObject sourceObject = game.getObject(source.getSourceId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (controller != null) {
        controller.damage((int) Math.ceil(damageEvent.getAmount() / 2.0), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
        StringBuilder sb = new StringBuilder(sourceObject != null ? sourceObject.getLogName() : "");
        sb.append(": ").append(damageEvent.getAmount() / 2).append(" damage prevented");
        sb.append(" from ").append(controller.getLogName());
        game.informPlayers(sb.toString());
        // only one use
        discard();
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) DamageEvent(mage.game.events.DamageEvent)

Example 18 with DamageEvent

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

the class GideonsSacrificeEffectReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent permanent = mor.getPermanent(game);
    if (permanent == null) {
        return false;
    }
    // Name of old target
    Permanent targetPermanent = game.getPermanent(event.getTargetId());
    StringBuilder message = new StringBuilder();
    message.append(permanent.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
    permanent.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
    return true;
}
Also used : Player(mage.players.Player) FilterPermanent(mage.filter.FilterPermanent) FilterControlledPermanent(mage.filter.common.FilterControlledPermanent) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent)

Example 19 with DamageEvent

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

the class MirrorStrikeEffect 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 (damageEvent.isCombatDamage() && Objects.equals(controller.getId(), damageEvent.getTargetId()) && Objects.equals(targetPermanent.getId(), damageEvent.getSourceId()));
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamageEvent(mage.game.events.DamageEvent)

Example 20 with DamageEvent

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

the class ImpulsiveManeuversEffect 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) {
            DamageEvent damageEvent = (DamageEvent) event;
            if (damageEvent.isCombatDamage()) {
                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)

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