Search in sources :

Example 36 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class CemeteryGatekeeperTriggeredAbility method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    Effect effect = getEffects().get(0);
    UUID targetId = (UUID) effect.getValue("targetId");
    GameEvent.EventType eventType = (GameEvent.EventType) effect.getValue("eventType");
    UUID exileId = (UUID) effect.getValue("exileId");
    if (targetId != null && eventType != null && exileId != null) {
        if (eventType == GameEvent.EventType.LAND_PLAYED) {
            Permanent permanent = game.getPermanent(targetId);
            return permanent != null && checkCardTypes(permanent.getCardType(game), exileId, game);
        } else if (eventType == GameEvent.EventType.SPELL_CAST) {
            Spell spell = game.getSpellOrLKIStack(targetId);
            return spell != null && checkCardTypes(spell.getCardType(game), exileId, game);
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) DamageTargetEffect(mage.abilities.effects.common.DamageTargetEffect) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 37 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class CemeteryProtectorTriggeredAbility method checkInterveningIfClause.

@Override
public boolean checkInterveningIfClause(Game game) {
    Effect effect = getEffects().get(0);
    UUID targetId = (UUID) effect.getValue("targetId");
    GameEvent.EventType eventType = (GameEvent.EventType) effect.getValue("eventType");
    UUID exileId = (UUID) effect.getValue("exileId");
    if (targetId != null && eventType != null && exileId != null) {
        if (eventType == GameEvent.EventType.LAND_PLAYED) {
            Permanent permanent = game.getPermanent(targetId);
            return permanent != null && checkCardTypes(permanent.getCardType(game), exileId, game);
        } else if (eventType == GameEvent.EventType.SPELL_CAST) {
            Spell spell = game.getSpellOrLKIStack(targetId);
            return spell != null && checkCardTypes(spell.getCardType(game), exileId, game);
        }
    }
    return false;
}
Also used : Permanent(mage.game.permanent.Permanent) GameEvent(mage.game.events.GameEvent) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) CreateTokenEffect(mage.abilities.effects.common.CreateTokenEffect) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 38 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class CephalidShrineEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    Spell spell = game.getStack().getSpell(event.getTargetId());
    MageObject mageObject = game.getObject(sourceId);
    if (spell != null && mageObject != null) {
        game.getState().setValue("cephalidShrine" + mageObject, spell);
        return true;
    }
    return false;
}
Also used : MageObject(mage.MageObject) Spell(mage.game.stack.Spell)

Example 39 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class CephalidShrineEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    int count = 0;
    MageObject mageObject = game.getObject(source.getSourceId());
    if (mageObject != null) {
        Spell spell = (Spell) game.getState().getValue("cephalidShrine" + mageObject);
        if (spell != null) {
            Player controller = game.getPlayer(spell.getControllerId());
            if (controller != null) {
                String name = spell.getName();
                FilterCard filterCardName = new FilterCard();
                filterCardName.add(new NamePredicate(name));
                for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
                    Player player = game.getPlayer(playerId);
                    if (player != null) {
                        count += player.getGraveyard().count(filterCardName, game);
                    }
                }
                // even if the cost is 0, we still offer
                Cost cost = ManaUtil.createManaCost(count, true);
                if (game.getStack().contains(spell) && cost.canPay(source, source, controller.getId(), game) && controller.chooseUse(outcome, "Pay " + cost.getText() + " to prevent countering " + spell.getName() + "?", source, game) && cost.pay(source, game, source, controller.getId(), false) && cost.isPaid()) {
                    return false;
                } else {
                    game.getStack().counter(spell.getId(), source, game);
                    game.informPlayers(spell.getName() + " has been countered due to " + controller.getName() + " not paying " + cost.getText());
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : FilterCard(mage.filter.FilterCard) Player(mage.players.Player) NamePredicate(mage.filter.predicate.mageobject.NamePredicate) MageObject(mage.MageObject) UUID(java.util.UUID) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell)

Example 40 with Spell

use of mage.game.stack.Spell in project mage by magefree.

the class CavernOfSoulsCantCounterEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    CavernOfSoulsWatcher watcher = game.getState().getWatcher(CavernOfSoulsWatcher.class, source.getSourceId());
    Spell spell = game.getStack().getSpell(event.getTargetId());
    return spell != null && watcher != null && watcher.spellCantBeCountered(new MageObjectReference(spell, game));
}
Also used : Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Aggregations

Spell (mage.game.stack.Spell)311 Player (mage.players.Player)155 Permanent (mage.game.permanent.Permanent)90 UUID (java.util.UUID)79 MageObject (mage.MageObject)69 Card (mage.cards.Card)51 TargetSpell (mage.target.TargetSpell)48 StackObject (mage.game.stack.StackObject)42 FilterCard (mage.filter.FilterCard)38 FilterSpell (mage.filter.FilterSpell)36 FixedTarget (mage.target.targetpointer.FixedTarget)33 MageObjectReference (mage.MageObjectReference)24 Effect (mage.abilities.effects.Effect)22 OneShotEffect (mage.abilities.effects.OneShotEffect)22 Target (mage.target.Target)22 Ability (mage.abilities.Ability)20 SpellAbility (mage.abilities.SpellAbility)16 FilterPermanent (mage.filter.FilterPermanent)15 TargetCard (mage.target.TargetCard)15 TargetPlayer (mage.target.TargetPlayer)14