Search in sources :

Example 16 with Spell

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

the class KrarkTheThumblessEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player player = game.getPlayer(source.getControllerId());
    Spell spell = game.getSpellOrLKIStack(getTargetPointer().getFirst(game, source));
    if (player == null || spell == null) {
        return false;
    }
    if (player.flipCoin(source, game, true)) {
        spell.createCopyOnStack(game, source, player.getId(), true);
        return true;
    }
    if (spell.isCopy()) {
        game.getStack().remove(spell, game);
        return true;
    }
    return game.getSpell(spell.getId()) != null && player.moveCards(spell, Zone.HAND, source, game);
}
Also used : Player(mage.players.Player) Spell(mage.game.stack.Spell)

Example 17 with Spell

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

the class ManaCanBeSpentAsAnyColorEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        ObjectColor colorless = new ObjectColor();
        // permaments
        for (Permanent perm : game.getBattlefield().getActivePermanents(source.getControllerId(), game)) {
            perm.getColor(game).setColor(colorless);
        }
        List<Card> affectedCards = new ArrayList<>();
        // spells
        for (MageObject object : game.getStack()) {
            if (object instanceof Spell) {
                game.getState().getCreateMageObjectAttribute(object, game).getColor().setColor(colorless);
                Card card = ((Spell) object).getCard();
                affectedCards.add(card);
            }
        }
        // exile
        affectedCards.addAll(game.getExile().getAllCardsByRange(game, controller.getId()));
        for (UUID playerId : game.getState().getPlayersInRange(controller.getId(), game)) {
            Player player = game.getPlayer(playerId);
            if (player == null) {
                continue;
            }
            // command
            affectedCards.addAll(game.getCommanderCardsFromCommandZone(player, CommanderCardType.ANY));
            // hand
            affectedCards.addAll(player.getHand().getCards(game));
            // library
            affectedCards.addAll(player.getLibrary().getCards(game));
            // graveyard
            affectedCards.addAll(player.getGraveyard().getCards(game));
        }
        // apply colors to all cards
        affectedCards.forEach(card -> {
            game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
            // mdf cards
            if (card instanceof ModalDoubleFacesCard) {
                ModalDoubleFacesCardHalf leftHalfCard = ((ModalDoubleFacesCard) card).getLeftHalfCard();
                ModalDoubleFacesCardHalf rightHalfCard = ((ModalDoubleFacesCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
            }
            // split cards
            if (card instanceof SplitCard) {
                SplitCardHalf leftHalfCard = ((SplitCard) card).getLeftHalfCard();
                SplitCardHalf rightHalfCard = ((SplitCard) card).getRightHalfCard();
                game.getState().getCreateMageObjectAttribute(leftHalfCard, game).getColor().setColor(colorless);
                game.getState().getCreateMageObjectAttribute(rightHalfCard, game).getColor().setColor(colorless);
            }
            // double faces cards
            if (card.getSecondCardFace() != null) {
                game.getState().getCreateMageObjectAttribute(card, game).getColor().setColor(colorless);
            }
        });
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Permanent(mage.game.permanent.Permanent) ArrayList(java.util.ArrayList) MageObject(mage.MageObject) Spell(mage.game.stack.Spell) ObjectColor(mage.ObjectColor) UUID(java.util.UUID)

Example 18 with Spell

use of mage.game.stack.Spell 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 19 with Spell

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

the class NovaPentacleEffect method applies.

@Override
public boolean applies(GameEvent event, Ability source, Game game) {
    // check source
    MageObject object = game.getObject(event.getSourceId());
    if (object == null) {
        game.informPlayers("Couldn't find source of damage");
        return false;
    }
    if (!object.getId().equals(damageSource.getFirstTarget()) && (!(object instanceof Spell) || !((Spell) object).getSourceId().equals(damageSource.getFirstTarget()))) {
        return false;
    }
    this.redirectTarget = source.getTargets().get(0);
    // check player
    Player player = game.getPlayer(event.getTargetId());
    if (player != null) {
        return player.getId().equals(source.getControllerId());
    }
    return false;
}
Also used : Player(mage.players.Player) MageObject(mage.MageObject) Spell(mage.game.stack.Spell)

Example 20 with Spell

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

the class PsychicTheftWatcher method watch.

@Override
public void watch(GameEvent event, Game game) {
    if (event.getType() != GameEvent.EventType.SPELL_CAST) {
        return;
    }
    Spell spell = game.getSpell(event.getTargetId());
    if (spell == null || spell.getCard() == null || spell.getCard().getMainCard() == null) {
        return;
    }
    map.computeIfAbsent(event.getPlayerId(), x -> new HashSet<>()).add(new MageObjectReference(spell.getCard().getMainCard(), game));
}
Also used : java.util(java.util) ReturnFromExileEffect(mage.abilities.effects.common.ReturnFromExileEffect) Condition(mage.abilities.condition.Condition) MageObjectReference(mage.MageObjectReference) OneShotEffect(mage.abilities.effects.OneShotEffect) CardUtil(mage.util.CardUtil) TargetPlayer(mage.target.TargetPlayer) Player(mage.players.Player) CardSetInfo(mage.cards.CardSetInfo) Game(mage.game.Game) Watcher(mage.watchers.Watcher) GameEvent(mage.game.events.GameEvent) CardImpl(mage.cards.CardImpl) TargetCard(mage.target.TargetCard) FilterInstantOrSorceryCard(mage.filter.common.FilterInstantOrSorceryCard) ConditionalOneShotEffect(mage.abilities.decorator.ConditionalOneShotEffect) Spell(mage.game.stack.Spell) Card(mage.cards.Card) mage.constants(mage.constants) Ability(mage.abilities.Ability) AtTheBeginOfNextEndStepDelayedTriggeredAbility(mage.abilities.common.delayed.AtTheBeginOfNextEndStepDelayedTriggeredAbility) 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