Search in sources :

Example 31 with DamageEvent

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

the class TreacherousLinkEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    // In the case that the enchantment is blinked
    Permanent enchantment = (Permanent) game.getLastKnownInformation(source.getSourceId(), Zone.BATTLEFIELD);
    if (enchantment == null) {
        // It was not blinked, use the standard method
        enchantment = game.getPermanentOrLKIBattlefield(source.getSourceId());
    }
    Player controller = game.getPlayer(source.getControllerId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (controller != null && enchantment != null) {
        Permanent enchantedCreature = game.getPermanentOrLKIBattlefield(enchantment.getAttachedTo());
        if (enchantedCreature != null) {
            return enchantedCreature.getId().equals(damageEvent.getTargetId());
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent)

Example 32 with DamageEvent

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

the class TreacherousLinkEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    Permanent enchantedCreature = game.getPermanentOrLKIBattlefield(damageEvent.getTargetId());
    if (enchantedCreature == null) {
        return false;
    }
    Player controller = game.getPlayer(enchantedCreature.getControllerId());
    if (controller == null) {
        return false;
    }
    controller.damage(damageEvent.getAmount(), damageEvent.getSourceId(), source, game, damageEvent.isCombatDamage(), damageEvent.isPreventable(), damageEvent.getAppliedEffects());
    return true;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent)

Example 33 with DamageEvent

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

the class PlaneswalkerRedirectionEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    DamageEvent damageEvent = (DamageEvent) event;
    UUID playerId = getSourceControllerId(event.getSourceId(), game);
    if (!damageEvent.isCombatDamage() && game.getOpponents(event.getTargetId()).contains(playerId)) {
        Player target = game.getPlayer(event.getTargetId());
        Player player = game.getPlayer(playerId);
        if (target != null && player != null) {
            int numPlaneswalkers = game.getBattlefield().countAll(StaticFilters.FILTER_PERMANENT_PLANESWALKER, target.getId(), game);
            if (numPlaneswalkers > 0 && player.chooseUse(outcome, "Redirect damage to planeswalker?", source, game)) {
                redirectTarget = new TargetPermanent(StaticFilters.FILTER_PERMANENT_PLANESWALKER);
                if (numPlaneswalkers == 1) {
                    List<Permanent> planeswalker = game.getBattlefield().getAllActivePermanents(StaticFilters.FILTER_PERMANENT_PLANESWALKER, target.getId(), game);
                    if (!planeswalker.isEmpty()) {
                        redirectTarget.add(planeswalker.get(0).getId(), game);
                    }
                } else {
                    player.choose(Outcome.Damage, redirectTarget, null, game);
                }
                if (!game.isSimulation()) {
                    Permanent redirectTo = game.getPermanent(redirectTarget.getFirstTarget());
                    if (redirectTo != null) {
                        game.informPlayers(player.getLogName() + " redirects " + event.getAmount() + " damage to " + redirectTo.getLogName());
                    }
                }
                return true;
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) TargetPermanent(mage.target.TargetPermanent) TargetPermanent(mage.target.TargetPermanent) DamageEvent(mage.game.events.DamageEvent) UUID(java.util.UUID)

Example 34 with DamageEvent

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

the class EyeForAnEyeEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    DamageEvent damageEvent = (DamageEvent) event;
    if (controller != null) {
        if (controller.getId().equals(damageEvent.getTargetId()) && damageEvent.getSourceId().equals(damageSource.getFirstTarget())) {
            this.discard();
            return true;
        }
    }
    return false;
}
Also used : Player(mage.players.Player) DamageEvent(mage.game.events.DamageEvent)

Example 35 with DamageEvent

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

the class GoblinPsychopathEffect 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 || !(this.applies(event, source, game) && event instanceof DamageEvent && event.getAmount() > 0)) {
        return false;
    }
    DamageEvent damageEvent = (DamageEvent) event;
    if (!damageEvent.isCombatDamage() || wonFlip) {
        return false;
    }
    // TODO: make this redirect damage from all blockers
    controller.damage(event.getAmount(), source.getSourceId(), source, game);
    String sourceLogName = game.getObject(source.getSourceId()).getLogName() + ": ";
    game.informPlayers(sourceLogName + "Redirected " + event.getAmount() + " damage to " + controller.getLogName());
    this.discard();
    return true;
}
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