Search in sources :

Example 91 with Spell

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

the class ConvokeEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (controller != null && spell != null) {
        for (UUID creatureId : this.getTargetPointer().getTargets(game, source)) {
            Permanent perm = game.getPermanent(creatureId);
            if (perm == null) {
                continue;
            }
            String manaName;
            if (!perm.isTapped() && perm.tap(source, game)) {
                ManaPool manaPool = controller.getManaPool();
                Choice chooseManaType = buildChoice(perm.getColor(game), unpaid.getMana());
                if (!chooseManaType.getChoices().isEmpty()) {
                    if (chooseManaType.getChoices().size() > 1) {
                        chooseManaType.getChoices().add("Colorless");
                        chooseManaType.setMessage("Choose mana color to reduce from " + perm.getName());
                        if (!controller.choose(Outcome.Benefit, chooseManaType, game)) {
                            return false;
                        }
                    } else {
                        chooseManaType.setChoice(chooseManaType.getChoices().iterator().next());
                    }
                    if (chooseManaType.getChoice().equals("Black")) {
                        manaPool.addMana(Mana.BlackMana(1), game, source);
                        manaPool.unlockManaType(ManaType.BLACK);
                    }
                    if (chooseManaType.getChoice().equals("Blue")) {
                        manaPool.addMana(Mana.BlueMana(1), game, source);
                        manaPool.unlockManaType(ManaType.BLUE);
                    }
                    if (chooseManaType.getChoice().equals("Green")) {
                        manaPool.addMana(Mana.GreenMana(1), game, source);
                        manaPool.unlockManaType(ManaType.GREEN);
                    }
                    if (chooseManaType.getChoice().equals("White")) {
                        manaPool.addMana(Mana.WhiteMana(1), game, source);
                        manaPool.unlockManaType(ManaType.WHITE);
                    }
                    if (chooseManaType.getChoice().equals("Red")) {
                        manaPool.addMana(Mana.RedMana(1), game, source);
                        manaPool.unlockManaType(ManaType.RED);
                    }
                    if (chooseManaType.getChoice().equals("Colorless")) {
                        manaPool.addMana(Mana.ColorlessMana(1), game, source);
                        manaPool.unlockManaType(ManaType.COLORLESS);
                    }
                    manaName = chooseManaType.getChoice().toLowerCase(Locale.ENGLISH);
                } else {
                    manaPool.addMana(Mana.ColorlessMana(1), game, source);
                    manaPool.unlockManaType(ManaType.COLORLESS);
                    manaName = "colorless";
                }
                game.fireEvent(GameEvent.getEvent(GameEvent.EventType.CONVOKED, perm.getId(), source, source.getControllerId()));
                game.informPlayers("Convoke: " + controller.getLogName() + " taps " + perm.getLogName() + " to pay one " + manaName + " mana");
                // can't use mana abilities after that (convoke cost must be payed after mana abilities only)
                spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
            }
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) Choice(mage.choices.Choice) FilterControlledCreaturePermanent(mage.filter.common.FilterControlledCreaturePermanent) Permanent(mage.game.permanent.Permanent) TargetControlledCreaturePermanent(mage.target.common.TargetControlledCreaturePermanent) ManaPool(mage.players.ManaPool) UUID(java.util.UUID) Spell(mage.game.stack.Spell)

Example 92 with Spell

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

the class CommanderStormEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    MageObjectReference spellRef = (MageObjectReference) this.getValue("StormSpellRef");
    if (spellRef == null) {
        return false;
    }
    Player player = game.getPlayer(source.getControllerId());
    if (player == null) {
        return false;
    }
    CommanderPlaysCountWatcher watcher = game.getState().getWatcher(CommanderPlaysCountWatcher.class);
    if (watcher == null) {
        return false;
    }
    int stormCount = game.getCommandersIds(player, CommanderCardType.COMMANDER_OR_OATHBREAKER, false).stream().mapToInt(watcher::getPlaysCount).sum();
    if (stormCount == 0) {
        return true;
    }
    Spell spell = (Spell) this.getValue("StormSpell");
    if (spell == null) {
        return false;
    }
    game.informPlayers(spell.getLogName() + " will be copied " + stormCount + " time" + (stormCount > 1 ? "s" : ""));
    spell.createCopyOnStack(game, source, source.getControllerId(), true, stormCount);
    return true;
}
Also used : Player(mage.players.Player) CommanderPlaysCountWatcher(mage.watchers.common.CommanderPlaysCountWatcher) MageObjectReference(mage.MageObjectReference) Spell(mage.game.stack.Spell)

Example 93 with Spell

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

the class CommanderStormEffect method checkTrigger.

@Override
public boolean checkTrigger(GameEvent event, Game game) {
    if (!event.getSourceId().equals(getSourceId())) {
        return false;
    }
    StackObject spell = game.getStack().getStackObject(getSourceId());
    if (!(spell instanceof Spell)) {
        return false;
    }
    for (Effect effect : this.getEffects()) {
        effect.setValue("StormSpell", spell);
        effect.setValue("StormSpellRef", new MageObjectReference(spell.getId(), game));
    }
    return true;
}
Also used : StackObject(mage.game.stack.StackObject) OneShotEffect(mage.abilities.effects.OneShotEffect) Effect(mage.abilities.effects.Effect) Spell(mage.game.stack.Spell) MageObjectReference(mage.MageObjectReference)

Example 94 with Spell

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

the class DelveEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Player controller = game.getPlayer(source.getControllerId());
    Spell spell = game.getStack().getSpell(source.getSourceId());
    if (controller != null && spell != null) {
        ExileFromGraveCost exileFromGraveCost = (ExileFromGraveCost) source.getCosts().get(0);
        List<Card> exiledCards = exileFromGraveCost.getExiledCards();
        if (!exiledCards.isEmpty()) {
            Cards toDelve = new CardsImpl();
            for (Card card : exiledCards) {
                toDelve.add(card);
            }
            ManaPool manaPool = controller.getManaPool();
            manaPool.addMana(Mana.ColorlessMana(toDelve.size()), game, source);
            manaPool.unlockManaType(ManaType.COLORLESS);
            String keyString = CardUtil.getCardZoneString("delvedCards", source.getSourceId(), game);
            @SuppressWarnings("unchecked") Cards delvedCards = (Cards) game.getState().getValue(keyString);
            if (delvedCards == null) {
                game.getState().setValue(keyString, toDelve);
            } else {
                delvedCards.addAll(toDelve);
            }
            // can't use mana abilities after that (delve cost must be payed after mana abilities only)
            spell.setCurrentActivatingManaAbilitiesStep(ActivationManaAbilityStep.AFTER);
        }
        return true;
    }
    return false;
}
Also used : Player(mage.players.Player) ExileFromGraveCost(mage.abilities.costs.common.ExileFromGraveCost) ManaPool(mage.players.ManaPool) Spell(mage.game.stack.Spell) Cards(mage.cards.Cards) CardsImpl(mage.cards.CardsImpl) Card(mage.cards.Card) FilterCard(mage.filter.FilterCard)

Example 95 with Spell

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

the class DivertEffect method apply.

@Override
public boolean apply(Game game, Ability source) {
    Spell spell = game.getStack().getSpell(source.getFirstTarget());
    Cost cost = ManaUtil.createManaCost(2, false);
    if (spell != null) {
        Player player = game.getPlayer(spell.getControllerId());
        if (player != null) {
            if (!cost.pay(source, game, source, spell.getControllerId(), false, null)) {
                return spell.chooseNewTargets(game, source.getControllerId(), true, true, null);
            }
        }
    }
    return false;
}
Also used : Player(mage.players.Player) Cost(mage.abilities.costs.Cost) Spell(mage.game.stack.Spell) TargetSpell(mage.target.TargetSpell)

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