Search in sources :

Example 81 with GameEvent

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

the class BraceForImpactPreventDamageTargetEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int prevented = 0;
        int damage = event.getAmount();
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        prevented = damage;
        // add counters now
        if (prevented > 0) {
            Permanent targetPermanent = game.getPermanent(source.getTargets().getFirstTarget());
            if (targetPermanent != null) {
                targetPermanent.addCounters(CounterType.P1P1.createInstance(prevented), source.getControllerId(), source, game);
                game.informPlayers("Brace for Impact: Prevented " + prevented + " damage ");
                game.informPlayers("Brace for Impact: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 82 with GameEvent

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

the class BattletideAlchemistEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean result = false;
    Player controller = game.getPlayer(source.getControllerId());
    Player targetPlayer = game.getPlayer(event.getTargetId());
    if (controller != null && targetPlayer != null) {
        int numberOfClericsControlled = new PermanentsOnBattlefieldCount(new FilterControlledCreaturePermanent(SubType.CLERIC, "Clerics")).calculate(game, source, this);
        int toPrevent = Math.min(numberOfClericsControlled, event.getAmount());
        if (toPrevent > 0 && controller.chooseUse(Outcome.PreventDamage, "Prevent " + toPrevent + " damage to " + targetPlayer.getName() + '?', source, game)) {
            GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent, ((DamageEvent) event).isCombatDamage());
            if (!game.replaceEvent(preventEvent)) {
                if (event.getAmount() >= toPrevent) {
                    event.setAmount(event.getAmount() - toPrevent);
                } else {
                    event.setAmount(0);
                    result = true;
                }
                game.informPlayers("Battletide Alchemist prevented " + toPrevent + " damage to " + targetPlayer.getName());
                game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), toPrevent));
            }
        }
    }
    return result;
}
Also used : Player(mage.players.Player) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) GameEvent(mage.game.events.GameEvent) PermanentsOnBattlefieldCount(mage.abilities.dynamicvalue.common.PermanentsOnBattlefieldCount) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Aggregations

GameEvent (mage.game.events.GameEvent)82 Permanent (mage.game.permanent.Permanent)28 Player (mage.players.Player)24 PreventDamageEvent (mage.game.events.PreventDamageEvent)23 PreventedDamageEvent (mage.game.events.PreventedDamageEvent)23 Game (mage.game.Game)22 Ability (mage.abilities.Ability)15 MageInt (mage.MageInt)13 CardImpl (mage.cards.CardImpl)13 CardSetInfo (mage.cards.CardSetInfo)13 java.util (java.util)12 OneShotEffect (mage.abilities.effects.OneShotEffect)12 Watcher (mage.watchers.Watcher)12 MageObjectReference (mage.MageObjectReference)11 Card (mage.cards.Card)11 UUID (java.util.UUID)10 TriggeredAbilityImpl (mage.abilities.TriggeredAbilityImpl)10 mage.constants (mage.constants)10 MageObject (mage.MageObject)9 Spell (mage.game.stack.Spell)9