Search in sources :

Example 66 with GameEvent

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

the class GhostsOfTheInnocentPreventDamageEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    int amount = (int) Math.ceil(event.getAmount() / 2.0);
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), amount, ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        event.setAmount(event.getAmount() - amount);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), amount));
    }
    return false;
}
Also used : GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 67 with GameEvent

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

the class IsshinTwoHeavensAsOneEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    NumberOfTriggersEvent numberOfTriggersEvent = (NumberOfTriggersEvent) event;
    Permanent sourcePermanent = game.getPermanent(numberOfTriggersEvent.getSourceId());
    if (sourcePermanent == null || !sourcePermanent.isControlledBy(source.getControllerId())) {
        return false;
    }
    GameEvent sourceEvent = numberOfTriggersEvent.getSourceEvent();
    switch(sourceEvent.getType()) {
        case ATTACKER_DECLARED:
        case DECLARED_ATTACKERS:
        case DEFENDER_ATTACKED:
            return true;
    }
    return false;
}
Also used : NumberOfTriggersEvent(mage.game.events.NumberOfTriggersEvent) Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent)

Example 68 with GameEvent

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

the class QuartzwoodCrasherWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() == GameEvent.EventType.COMBAT_DAMAGE_STEP_POST) {
        damageMap.clear();
        return;
    }
    if (event.getType() != GameEvent.EventType.DAMAGED_PLAYER || !((DamagedPlayerEvent) event).isCombatDamage()) {
        return;
    }
    Permanent creature = game.getPermanent(event.getSourceId());
    if (creature == null || !creature.hasAbility(TrampleAbility.getInstance(), game)) {
        return;
    }
    damageMap.computeIfAbsent(event.getTargetId(), x -> new HashMap<>()).compute(creature.getControllerId(), (uuid, i) -> i == null ? event.getAmount() : event.getAmount() + i);
}
Also used : java.util(java.util) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) MageInt(mage.MageInt) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) DinosaurBeastToken(mage.game.permanent.token.DinosaurBeastToken) CardImpl(mage.cards.CardImpl) Permanent(mage.game.permanent.Permanent) TrampleAbility(mage.abilities.keyword.TrampleAbility) mage.constants(mage.constants) Ability(mage.abilities.Ability) Permanent(mage.game.permanent.Permanent) DamagedPlayerEvent(mage.game.events.DamagedPlayerEvent)

Example 69 with GameEvent

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

the class ReflectiveGolemTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!isControlledBy(event.getPlayerId())) {
        return false;
    }
    Spell spell = game.getSpellOrLKIStack(event.getTargetId());
    if (spell == null || !spell.isInstantOrSorcery(game)) {
        return false;
    }
    if (spell.getSpellAbilities().stream().map(AbilityImpl::getModes).flatMap(m -> m.getSelectedModes().stream().map(m::get)).filter(Objects::nonNull).map(Mode::getTargets).flatMap(Collection::stream).filter(t -> !t.isNotTarget()).map(Target::getTargets).flatMap(Collection::stream).filter(Objects::nonNull).distinct().filter(getSourceId()::equals).count() != 1) {
        return false;
    }
    this.getEffects().setTargetPointer(new FixedTarget(spell, game));
    return true;
}
Also used : Target(mage.target.Target) Zone(mage.constants.Zone) CopyTargetSpellEffect(mage.abilities.effects.common.CopyTargetSpellEffect) DoIfCostPaid(mage.abilities.effects.common.DoIfCostPaid) Collection(java.util.Collection) UUID(java.util.UUID) MageInt(mage.MageInt) SubType(mage.constants.SubType) Mode(mage.abilities.Mode) FixedTarget(mage.target.targetpointer.FixedTarget) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) Game(mage.game.Game) AbilityImpl(mage.abilities.AbilityImpl) GenericManaCost(mage.abilities.costs.mana.GenericManaCost) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) FixedTarget(mage.target.targetpointer.FixedTarget) TriggeredAbilityImpl(mage.abilities.TriggeredAbilityImpl) AbilityImpl(mage.abilities.AbilityImpl) Target(mage.target.Target) FixedTarget(mage.target.targetpointer.FixedTarget) Objects(java.util.Objects) Collection(java.util.Collection) Spell(mage.game.stack.Spell)

Example 70 with GameEvent

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

the class YarokTheDesecratedEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    if (!(event instanceof NumberOfTriggersEvent)) {
        return false;
    }
    NumberOfTriggersEvent numberOfTriggersEvent = (NumberOfTriggersEvent) event;
    if (!source.isControlledBy(event.getPlayerId())) {
        return false;
    }
    GameEvent sourceEvent = numberOfTriggersEvent.getSourceEvent();
    // Only EtB triggers
    if (sourceEvent == null || sourceEvent.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD || !(sourceEvent instanceof EntersTheBattlefieldEvent)) {
        return false;
    }
    // Only for triggers of permanents
    return game.getPermanent(numberOfTriggersEvent.getSourceId()) != null;
}
Also used : NumberOfTriggersEvent(mage.game.events.NumberOfTriggersEvent) EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) GameEvent(mage.game.events.GameEvent)

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