Search in sources :

Example 26 with GameEvent

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

the class StrictProctorTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    GameEvent triggeringEvent = (GameEvent) game.getState().getValue(event.getId().toString());
    if (triggeringEvent == null || triggeringEvent.getType() != GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
        return false;
    }
    getEffects().setTargetPointer(new FixedTarget(triggeringEvent.getTargetId(), game));
    return true;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) GameEvent(mage.game.events.GameEvent)

Example 27 with GameEvent

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

the class TemperPreventDamageTargetEffect method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    if (!initialized) {
        amount = dVal.calculate(game, source, this);
        initialized = true;
    }
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    if (!game.replaceEvent(preventEvent)) {
        int prevented = 0;
        if (event.getAmount() >= this.amount) {
            int damage = amount;
            event.setAmount(event.getAmount() - amount);
            this.used = true;
            game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
            prevented = damage;
        } else {
            int damage = event.getAmount();
            event.setAmount(0);
            amount -= damage;
            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("Temper: Prevented " + prevented + " damage ");
                game.informPlayers("Temper: Adding " + prevented + " +1/+1 counters to " + targetPermanent.getName());
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 28 with GameEvent

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

the class UginTheIneffableLookAtFaceDownEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ZoneChangeEvent zEvent = ((ZoneChangeEvent) event);
    if (zEvent.getToZone() == Zone.BATTLEFIELD || tokenRefs.stream().noneMatch(tokenRef -> tokenRef.refersTo(zEvent.getTarget(), game))) {
        return false;
    }
    this.getEffects().clear();
    Effect effect = new ReturnToHandTargetEffect();
    effect.setTargetPointer(new FixedTarget(cardRef));
    this.addEffect(effect);
    return true;
}
Also used : SimpleStaticAbility(mage.abilities.common.SimpleStaticAbility) UginTheIneffableToken(mage.game.permanent.token.UginTheIneffableToken) MageObjectReference(mage.MageObjectReference) Predicates(mage.filter.predicate.Predicates) FilterPermanent(mage.filter.FilterPermanent) Player(mage.players.Player) FixedTarget(mage.target.targetpointer.FixedTarget) HashSet(java.util.HashSet) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) MageObject(mage.MageObject) Card(mage.cards.Card) mage.constants(mage.constants) FilterCard(mage.filter.FilterCard) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) Set(java.util.Set) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) UUID(java.util.UUID) LoyaltyAbility(mage.abilities.LoyaltyAbility) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) AsThoughEffectImpl(mage.abilities.effects.AsThoughEffectImpl) Effect(mage.abilities.effects.Effect) GameEvent(mage.game.events.GameEvent) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) InfoEffect(mage.abilities.effects.common.InfoEffect) CardImpl(mage.cards.CardImpl) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) ColorlessPredicate(mage.filter.predicate.mageobject.ColorlessPredicate) Benefit(mage.constants.Outcome.Benefit) DelayedTriggeredAbility(mage.abilities.DelayedTriggeredAbility) TargetPermanent(mage.target.TargetPermanent) Ability(mage.abilities.Ability) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) FixedTarget(mage.target.targetpointer.FixedTarget) ZoneChangeEvent(mage.game.events.ZoneChangeEvent) DestroyTargetEffect(mage.abilities.effects.common.DestroyTargetEffect) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) InfoEffect(mage.abilities.effects.common.InfoEffect) SpellsCostReductionControllerEffect(mage.abilities.effects.common.cost.SpellsCostReductionControllerEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) ReturnToHandTargetEffect(mage.abilities.effects.common.ReturnToHandTargetEffect)

Example 29 with GameEvent

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

the class UnbreathingHordeEffect2 method replaceEvent.

@Override
public boolean replaceEvent(GameEvent event, Ability source, Game game) {
    boolean retValue = false;
    GameEvent preventEvent = new PreventDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), event.getAmount(), ((DamageEvent) event).isCombatDamage());
    int damage = event.getAmount();
    if (!game.replaceEvent(preventEvent)) {
        event.setAmount(0);
        game.fireEvent(new PreventedDamageEvent(event.getTargetId(), source.getSourceId(), source, source.getControllerId(), damage));
        retValue = true;
    }
    Permanent permanent = game.getPermanent(source.getSourceId());
    if (permanent != null) {
        permanent.removeCounters(CounterType.P1P1.createInstance(), source, game);
    }
    return retValue;
}
Also used : Permanent(mage.game.permanent.Permanent) FilterCreaturePermanent(mage.filter.common.FilterCreaturePermanent) GameEvent(mage.game.events.GameEvent) PreventedDamageEvent(mage.game.events.PreventedDamageEvent) PreventDamageEvent(mage.game.events.PreventDamageEvent)

Example 30 with GameEvent

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

the class WulfgarOfIcewindDaleEffect 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:
            return source.isControlledBy(sourceEvent.getPlayerId());
        case DECLARED_ATTACKERS:
            return game.getCombat().getAttackers().stream().map(game::getControllerId).anyMatch(source::isControlledBy);
        case DEFENDER_ATTACKED:
            return ((DefenderAttackedEvent) sourceEvent).getAttackers(game).stream().map(Controllable::getControllerId).anyMatch(source::isControlledBy);
    }
    return false;
}
Also used : NumberOfTriggersEvent(mage.game.events.NumberOfTriggersEvent) Permanent(mage.game.permanent.Permanent) 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