Search in sources :

Example 36 with DamageEvent

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

the class ImmortalCoilPreventionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (game.replaceEvent(new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage()))) {
        return false;
    }
    int damage = event.getAmount();
    Player player = game.getPlayer(source.getControllerId());
    if (player != null) {
        TargetCardInYourGraveyard target = new TargetCardInYourGraveyard(Math.min(damage, player.getGraveyard().size()), StaticFilters.FILTER_CARD);
        target.setNotTarget(true);
        player.choose(outcome, target, source.getSourceId(), game);
        player.moveCards(new CardsImpl(target.getTargets()), Zone.EXILED, source, game);
    }
    event.setAmount(0);
    game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    return false;
}
Also used : Player(mage.players.Player) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) TargetCardInYourGraveyard(mage.target.common.TargetCardInYourGraveyard) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) DamageEvent(mage.game.events.DamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent) CardsImpl(mage.cards.CardsImpl)

Example 37 with DamageEvent

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

the class MirrorStrikeEffect 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) {
        Permanent targetPermanent = game.getPermanent(source.getFirstTarget());
        if (targetPermanent != null) {
            Player targetsController = game.getPlayer(targetPermanent.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) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) DamageEvent(mage.game.events.DamageEvent)

Example 38 with DamageEvent

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

the class RedirectionEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    int damageToRedirect = event.getAmount();
    if (damageToRedirect < 1) {
        // if multiple replacement effect apply, the rest damage can be 0, so the effect is not applied/replaced
        return false;
    }
    String sourceLogName = source != null ? game.getObject(source.getSourceId()).getLogName() + ": " : "";
    DamageEvent damageEvent = (DamageEvent) event;
    int restDamage = 0;
    if (damageEvent.getAmount() > amountToRedirect) {
        restDamage = damageEvent.getAmount() - amountToRedirect;
        damageToRedirect = amountToRedirect;
    }
    if (damageToRedirect > 0 && usageType != UsageType.ACCORDING_DURATION) {
        if (UsageType.ONE_USAGE_ABSOLUTE == usageType) {
            this.discard();
        }
        if (applyEffectsCounter > 0) {
            if (applyEffectsCounter < game.getState().getApplyEffectsCounter()) {
                this.discard();
                return false;
            }
        } else {
            applyEffectsCounter = game.getState().getApplyEffectsCounter();
        }
    }
    Permanent permanent = game.getPermanent(redirectTarget.getFirstTarget());
    if (permanent != null) {
        permanent.damage(damageToRedirect, event.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
        game.informPlayers(sourceLogName + "Redirected " + damageToRedirect + " damage" + getRedirectedFromText(event, game) + " to " + permanent.getLogName());
    } else {
        Player player = game.getPlayer(redirectTarget.getFirstTarget());
        if (player != null) {
            player.damage(damageToRedirect, event.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), event.getAppliedEffects());
            game.informPlayers(sourceLogName + "Redirected " + damageToRedirect + " damage" + getRedirectedFromText(event, game) + " to " + player.getLogName());
        }
    }
    if (restDamage > 0) {
        damageEvent.setAmount(restDamage);
        return false;
    }
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent)

Example 39 with DamageEvent

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

the class CamelEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (super.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0) {
        DamageEvent damageEvent = (DamageEvent) event;
        Permanent sourcePermanent = game.getPermanentOrLKIBattlefield(source.getSourceId());
        if (sourcePermanent != null && sourcePermanent.isAttacking() && (event.getTargetId().equals(source.getSourceId()) || sourcePermanent.getBandedCards().contains(event.getTargetId()))) {
            Permanent permanent = game.getPermanentOrLKIBattlefield(damageEvent.getSourceId());
            if (filter.match(permanent, game)) {
                return true;
            }
        }
    }
    return false;
}
Also used : FilterPermanent(mage.filter.FilterPermanent) Permanent(mage.game.permanent.Permanent) DamageEvent(mage.game.events.DamageEvent)

Example 40 with DamageEvent

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

the class BloodOfTheMartyrEffect 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