Search in sources :

Example 1 with SpellsCastWatcher

use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.

the class NullstoneGargoyleTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Spell spell = game.getSpell(event.getTargetId());
    if (spell.isCreature(game)) {
        return false;
    }
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (watcher != null && watcher.getNumberOfNonCreatureSpells() == 1) {
        for (Effect effect : getEffects()) {
            effect.setTargetPointer(new FixedTarget(event.getTargetId()));
        }
        return true;
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) CounterTargetEffect(mage.abilities.effects.common.CounterTargetEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell)

Example 2 with SpellsCastWatcher

use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.

the class ArchfiendsVesselEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (super.checkTrigger(event, game)) {
        if (event.getType() == GameEvent.EventType.ENTERS_THE_BATTLEFIELD) {
            EntersTheBattlefieldEvent entersTheBattlefieldEvent = (EntersTheBattlefieldEvent) event;
            if (entersTheBattlefieldEvent.getTargetId().equals(getSourceId()) && entersTheBattlefieldEvent.getFromZone() == Zone.GRAVEYARD) {
                return true;
            } else {
                SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
                List<Spell> spellsCastFromGraveyard = watcher.getSpellsCastFromGraveyardThisTurn(getControllerId());
                if (spellsCastFromGraveyard != null) {
                    return spellsCastFromGraveyard.stream().anyMatch(spell -> spell.getMainCard().getId().equals((entersTheBattlefieldEvent.getTarget().getMainCard().getId())));
                }
            }
        }
    }
    return false;
}
Also used : EntersTheBattlefieldEvent(mage.game.events.EntersTheBattlefieldEvent) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) Spell(mage.game.stack.Spell)

Example 3 with SpellsCastWatcher

use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.

the class ShowOfConfidenceEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = (Spell) getValue("spellCast");
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (spell == null || watcher == null) {
        return false;
    }
    int copies = watcher.getSpellsCastThisTurn(source.getControllerId()).stream().filter(Objects::nonNull).filter(spell1 -> spell1.isInstantOrSorcery(game)).filter(s -> !s.getSourceId().equals(source.getSourceId()) || s.getZoneChangeCounter(game) != source.getSourceObjectZoneChangeCounter()).mapToInt(x -> 1).sum();
    if (copies > 0) {
        spell.createCopyOnStack(game, source, source.getControllerId(), true, copies);
    }
    return true;
}
Also used : AddCountersTargetEffect(mage.abilities.effects.common.counter.AddCountersTargetEffect) Outcome(mage.constants.Outcome) OneShotEffect(mage.abilities.effects.OneShotEffect) UUID(java.util.UUID) CastSourceTriggeredAbility(mage.abilities.effects.common.CastSourceTriggeredAbility) CardSetInfo(mage.cards.CardSetInfo) Objects(java.util.Objects) Duration(mage.constants.Duration) Game(mage.game.Game) VigilanceAbility(mage.abilities.keyword.VigilanceAbility) CardImpl(mage.cards.CardImpl) TargetCreaturePermanent(mage.target.common.TargetCreaturePermanent) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) CardType(mage.constants.CardType) Spell(mage.game.stack.Spell) CounterType(mage.counters.CounterType) Ability(mage.abilities.Ability) GainAbilityTargetEffect(mage.abilities.effects.common.continuous.GainAbilityTargetEffect) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) Objects(java.util.Objects) Spell(mage.game.stack.Spell)

Example 4 with SpellsCastWatcher

use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.

the class CurseOfShakenFaithEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Permanent enchantment = game.getPermanentOrLKIBattlefield(sourceId);
    if (enchantment != null) {
        UUID enchantedPlayerId = enchantment.getAttachedTo();
        Spell spell = game.getSpell(event.getTargetId());
        if (spell != null && spell.isControlledBy(enchantedPlayerId)) {
            if (event.getType() == GameEvent.EventType.COPIED_STACKOBJECT) {
                return true;
            }
            SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
            if (watcher != null) {
                return watcher.getSpellsCastThisTurn(enchantedPlayerId).size() > 1;
            }
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 5 with SpellsCastWatcher

use of mage.watchers.common.SpellsCastWatcher in project mage by magefree.

the class EsperSentinelEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Player controller = game.getPlayer(getControllerId());
    Spell spell = game.getSpell(event.getTargetId());
    SpellsCastWatcher watcher = game.getState().getWatcher(SpellsCastWatcher.class);
    if (controller != null && spell != null && watcher != null && !spell.isCreature(game) && controller.hasOpponent(spell.getControllerId(), game)) {
        int nonCreatureSpells = 0;
        for (Spell spellCastThisTurn : watcher.getSpellsCastThisTurn(spell.getControllerId())) {
            if (!spellCastThisTurn.isCreature(game) && ++nonCreatureSpells > 1) {
                break;
            }
        }
        if (nonCreatureSpells == 1) {
            for (Effect effect : getEffects()) {
                effect.setTargetPointer(new FixedTarget(spell.getControllerId()));
            }
            return true;
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Player(mage.players.Player) SpellsCastWatcher(mage.watchers.common.SpellsCastWatcher) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell)

Aggregations

SpellsCastWatcher (mage.watchers.common.SpellsCastWatcher)10 Spell (mage.game.stack.Spell)7 UUID (java.util.UUID)4 OneShotEffect (mage.abilities.effects.OneShotEffect)3 Player (mage.players.Player)3 FixedTarget (mage.target.targetpointer.FixedTarget)3 Effect (mage.abilities.effects.Effect)2 Card (mage.cards.Card)2 Permanent (mage.game.permanent.Permanent)2 ArrayList (java.util.ArrayList)1 Objects (java.util.Objects)1 ApprovingObject (mage.ApprovingObject)1 Ability (mage.abilities.Ability)1 DelayedTriggeredAbility (mage.abilities.DelayedTriggeredAbility)1 AtTheBeginOfNextEndStepDelayedTriggeredAbility (mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility)1 Condition (mage.abilities.condition.Condition)1 ConditionalOneShotEffect (mage.abilities.decorator.ConditionalOneShotEffect)1 AsThoughEffect (mage.abilities.effects.AsThoughEffect)1 CastSourceTriggeredAbility (mage.abilities.effects.common.CastSourceTriggeredAbility)1 CounterTargetEffect (mage.abilities.effects.common.CounterTargetEffect)1