Search in sources :

Example 11 with GameEvent

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

the class PersonalSanctuaryEffect 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 damage = event.getAmount();
        event.setAmount(0);
        game.informPlayers("Damage has been prevented: " + damage);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 12 with GameEvent

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

the class PsychicTheftWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.SPELL_CAST) {
        return;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null || spell.getCard() == null || spell.getCard().getMainCard() == null) {
        return;
    }
    map.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>()).add(new MageObjectReference(spell.getCard().getMainCard(), game));
}
Also used : java.util(java.util) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) Spell(mage.game.stack.Spell) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 13 with GameEvent

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

the class PreventDamageToTargetMultiAmountEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    int targetAmount = targetAmountMap.get(event.getTargetId());
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        if (event.getAmount() >= targetAmount) {
            event.setAmount(event.getAmount() - targetAmount);
            targetAmountMap.remove(event.getTargetId());
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), targetAmount));
        } else {
            int damage = event.getAmount();
            event.setAmount(0);
            targetAmountMap.put(event.getTargetId(), targetAmount - damage);
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        }
        if (targetAmountMap.isEmpty()) {
            this.used = true;
        }
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 14 with GameEvent

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

the class MadnessCastEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller == null) {
        return false;
    }
    Card card = game.getCard(event.getTargetId());
    if (card == null) {
        return false;
    }
    // TODO, deal with deprecated call
    if (controller.moveCardToExileWithInfo(card, source.getSourceId(), "Madness", source, game, ((ZoneChangeEvent) event).getFromZone(), true)) {
        // needed to add Madness ability to cards (e.g. by Falkenrath Gorger)
        game.applyEffects();
        GameEvent gameEvent = new MadnessCardExiledEvent(card.getId(), source, controller.getId());
        game.fireEvent(gameEvent);
    }
    return true;
}
Also used : Player(mage.players.Player) GameEvent(mage.game.events.GameEvent) MadnessCardExiledEvent(mage.game.events.MadnessCardExiledEvent) Card(mage.cards.Card)

Example 15 with GameEvent

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

the class VigorReplacementEffect 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 preventedDamage = event.getAmount();
        event.setAmount(0);
        Permanent permanent = game.getPermanent(event.getTargetId());
        if (permanent != null) {
            permanent.addCounters(CounterType.P1P1.createInstance(preventedDamage), source.getControllerId(), source, game);
        }
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), preventedDamage));
        return true;
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) 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