Search in sources :

Example 11 with DamageEvent

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

the class EyeForAnEyeEffect 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());
        UUID sourceControllerId = game.getControllerId(damageEvent.getSourceId());
        if (sourceControllerId != null) {
            Player sourceController = game.getPlayer(sourceControllerId);
            if (sourceController != null) {
                sourceController.damage(damageEvent.getAmount(), source.getSourceId(), source, game);
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) DamageEvent(mage.game.events.DamageEvent) UUID(java.util.UUID)

Example 12 with DamageEvent

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

the class ReverberationEffect 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) {
        Spell targetSpell = game.getStack().getSpell(source.getFirstTarget());
        if (targetSpell != null) {
            Player targetsController = game.getPlayer(targetSpell.getControllerId());
            if (targetsController != null) {
                targetsController.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) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

Example 13 with DamageEvent

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

the class SoulEchoReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    int damage = damageEvent.getAmount();
    Permanent permanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
    Player controller = game.getPlayer(source.getControllerId());
    if (permanent != null && controller != null) {
        permanent.removeCounters(CounterType.ECHO.createInstance(damage), source, game);
        game.informPlayers(controller.getLogName() + ": " + damage + " damage replaced with " + permanent.getLogName());
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent)

Example 14 with DamageEvent

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

the class SoltariGuerrillasReplacementEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    PreventionEffectData preventionResult = preventDamageAction(event, source, game);
    if (preventionResult.getPreventedDamage() > 0) {
        Permanent redirectTo = game.getPermanent(getTargetPointer().getFirst(game, source));
        if (redirectTo != null) {
            game.informPlayers("Dealing " + preventionResult.getPreventedDamage() + " to " + redirectTo.getLogName() + " instead.");
            DamageEvent damageEvent = (DamageEvent) event;
            redirectTo.damage(preventionResult.getPreventedDamage(), event.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
        }
        // (only once)
        discard();
    }
    return false;
}
Also used : PreventionEffectData(mage.abilities.effects.PreventionEffectData) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) DamageEvent(mage.game.events.DamageEvent)

Example 15 with DamageEvent

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

the class WallOfShadowsEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!super.applies(event, source, game) || !(event instanceof DamageEvent) || event.getAmount() <= 0) {
        return false;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    if (!event.getTargetId().equals(source.getSourceId())) {
        return false;
    }
    Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
    FilterCreaturePermanent filter = new FilterCreaturePermanent();
    filter.add(new BlockedByIdPredicate(source.getSourceId()));
    return permanent != null && filter.match(permanent, game);
}
Also used : FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) FilterPermanent(mage.filter.FilterPermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent) BlockedByIdPredicate(mage.filter.predicate.permanent.BlockedByIdPredicate)

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