Search in sources :

Example 46 with Spell

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

the class InvokePrejudiceEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (game.getOpponents(getControllerId()).contains(event.getPlayerId())) {
        Spell spell = (Spell) game.getObject(event.getTargetId());
        if (spell != null && spell.isCreature(game)) {
            boolean creatureSharesAColor = false;
            ObjectColor spellColor = spell.getColor(game);
            for (Permanent permanent : game.getBattlefield().getAllActivePermanents(new FilterControlledCreaturePermanent(), getControllerId(), game)) {
                if (spellColor.shares(permanent.getColor(game))) {
                    creatureSharesAColor = true;
                    break;
                }
            }
            if (!creatureSharesAColor) {
                for (Effect effect : getEffects()) {
                    effect.setTargetPointer(new FixedTarget(event.getTargetId()));
                }
                return true;
            }
        }
    }
    return false;
}
Also used : FixedTarget(mage.target.targetpointer.FixedTarget) Permanent(mage.game.permanent.Permanent) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) ObjectColor(mage.ObjectColor) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Effect(mage.abilities.effects.Effect) CounterUnlessPaysEffect(mage.abilities.effects.common.CounterUnlessPaysEffect) Spell(mage.game.stack.Spell)

Example 47 with Spell

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

the class MaelstromNexusGainCascadeFirstSpellEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (StackObject stackObject : game.getStack()) {
            // only spells cast, so no copies of spells
            if ((stackObject instanceof Spell) && !stackObject.isCopy() && stackObject.isControlledBy(source.getControllerId())) {
                Spell spell = (Spell) stackObject;
                FirstSpellCastThisTurnWatcher watcher = game.getState().getWatcher(FirstSpellCastThisTurnWatcher.class);
                if (watcher != null && spell.getId().equals(watcher.getIdOfFirstCastSpell(source.getControllerId()))) {
                    game.getState().addOtherAbility(spell.getCard(), cascadeAbility);
                }
            }
        }
        return true;
    }
    return false;
}
Also used : FirstSpellCastThisTurnWatcher(mage.watchers.common.FirstSpellCastThisTurnWatcher) Player(mage.players.Player) StackObject(mage.game.stack.StackObject) Spell(mage.game.stack.Spell)

Example 48 with Spell

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

the class MuldrothaTheGravetideWatcher method addPermanentTypes.

private void addPermanentTypes(GameEvent event, Card mageObject, Game game) {
    if (mageObject != null && event.getAdditionalReference() != null && MageIdentifier.MuldrothaTheGravetideWatcher.equals(event.getAdditionalReference().getApprovingAbility().getIdentifier())) {
        UUID playerId = null;
        if (mageObject instanceof Spell) {
            playerId = ((Spell) mageObject).getControllerId();
        } else if (mageObject instanceof Permanent) {
            playerId = ((Permanent) mageObject).getControllerId();
        }
        if (playerId != null) {
            Set<CardType> permanentTypes = sourcePlayedPermanentTypes.get(event.getAdditionalReference().getApprovingMageObjectReference());
            if (permanentTypes == null) {
                permanentTypes = EnumSet.noneOf(CardType.class);
                sourcePlayedPermanentTypes.put(event.getAdditionalReference().getApprovingMageObjectReference(), permanentTypes);
            }
            Set<CardType> typesNotCast = EnumSet.noneOf(CardType.class);
            for (CardType cardType : mageObject.getCardType(game)) {
                if (cardType.isPermanentType()) {
                    if (!permanentTypes.contains(cardType)) {
                        typesNotCast.add(cardType);
                    }
                }
            }
            if (typesNotCast.size() <= 1) {
                permanentTypes.addAll(typesNotCast);
            } else {
                Player player = game.getPlayer(playerId);
                if (player != null) {
                    Choice typeChoice = new ChoiceImpl(true);
                    typeChoice.setMessage("Choose permanent type you consume for casting from graveyard.");
                    for (CardType cardType : typesNotCast) {
                        typeChoice.getChoices().add(cardType.toString());
                    }
                    if (player.choose(Outcome.Detriment, typeChoice, game)) {
                        String typeName = typeChoice.getChoice();
                        CardType chosenType = null;
                        for (CardType cardType : CardType.values()) {
                            if (cardType.toString().equals(typeName)) {
                                chosenType = cardType;
                                break;
                            }
                        }
                        if (chosenType != null) {
                            permanentTypes.add(chosenType);
                        }
                    }
                }
            }
        }
    }
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) Permanent(mage.game.permanent.Permanent) CardType(mage.constants.CardType) ChoiceImpl(mage.choices.ChoiceImpl) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 49 with Spell

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

the class MultanisPresenceWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (GameEvent.EventType.SPELL_CAST == event.getType()) {
        Spell spell = game.getSpellOrLKIStack(event.getTargetId());
        if (spell != null) {
            List<UUID> spellIds;
            if (!spellsCast.containsKey(spell.getControllerId())) {
                spellIds = new ArrayList<>();
            } else {
                spellIds = spellsCast.get(spell.getControllerId());
            }
            spellIds.add(spell.getId());
            spellsCast.put(spell.getControllerId(), spellIds);
        }
    }
}
Also used : Spell(mage.game.stack.Spell)

Example 50 with Spell

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

the class ParadisePlumeSpellCastTriggeredAbility method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    ObjectColor color = (ObjectColor) game.getState().getValue(getSourceId() + "_color");
    if (color != null) {
        FilterSpell filter = new FilterSpell();
        filter.add(new ColorPredicate(color));
        Spell spell = game.getStack().getSpell(event.getTargetId());
        return (spell != null && filter.match(spell, getSourceId(), getControllerId(), game));
    }
    return false;
}
Also used : ColorPredicate(mage.filter.predicate.mageobject.ColorPredicate) FilterSpell(mage.filter.FilterSpell) ObjectColor(mage.ObjectColor) FilterSpell(mage.filter.FilterSpell) Spell(mage.game.stack.Spell)

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