Search in sources :

Example 1 with MillCardsCost

use of mage.abilities.costs.common.MillCardsCost in project mage by magefree.

the class CharmedPendantManaEffect method produceMana.

@Override
public Mana produceMana(Game game, Ability source) {
    Mana mana = new Mana();
    if (game == null) {
        return mana;
    }
    Player controller = game.getPlayer(source.getControllerId());
    if (controller != null) {
        for (Cost cost : source.getCosts()) {
            if (cost instanceof MillCardsCost) {
                Set<Card> cards = ((MillCardsCost) cost).getCardsMovedToGraveyard();
                if (!cards.isEmpty()) {
                    Card card = cards.iterator().next();
                    if (card != null && card.getManaCost() != null) {
                        ManaCosts<ManaCost> newManaCosts = new ManaCostsImpl<>();
                        for (ManaCost manaCost : card.getManaCost()) {
                            if (manaCost instanceof ColorlessManaCost || manaCost instanceof GenericManaCost || manaCost instanceof VariableManaCost) {
                                continue;
                            }
                            if (manaCost instanceof MonoHybridManaCost) {
                                newManaCosts.add(new ColoredManaCost(((MonoHybridManaCost) manaCost).getManaColor()));
                            } else {
                                newManaCosts.add(manaCost.copy());
                            }
                        }
                        ManaOptions manaOptions = newManaCosts.getOptions();
                        if (manaOptions.size() == 1) {
                            mana = newManaCosts.getMana();
                        } else {
                            Choice manaChoice = new ChoiceImpl(true);
                            manaChoice.setMessage("Select which mana you like to produce");
                            for (Mana manaOption : manaOptions) {
                                manaChoice.getChoices().add(manaOption.toString());
                            }
                            if (manaChoice.getChoices().isEmpty()) {
                                // no mana choices available
                                return mana;
                            }
                            if (controller.choose(outcome, manaChoice, game)) {
                                for (Mana manaOption : manaOptions) {
                                    if (manaChoice.getChoice().equals(manaOption.toString())) {
                                        mana = manaOption;
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
    }
    return mana;
}
Also used : ManaOptions(mage.abilities.mana.ManaOptions) Player(mage.players.Player) Mana(mage.Mana) MillCardsCost(mage.abilities.costs.common.MillCardsCost) Choice(mage.choices.Choice) MillCardsCost(mage.abilities.costs.common.MillCardsCost) Cost(mage.abilities.costs.Cost) TapSourceCost(mage.abilities.costs.common.TapSourceCost) Card(mage.cards.Card) ChoiceImpl(mage.choices.ChoiceImpl)

Aggregations

Mana (mage.Mana)1 Cost (mage.abilities.costs.Cost)1 MillCardsCost (mage.abilities.costs.common.MillCardsCost)1 TapSourceCost (mage.abilities.costs.common.TapSourceCost)1 ManaOptions (mage.abilities.mana.ManaOptions)1 Card (mage.cards.Card)1 Choice (mage.choices.Choice)1 ChoiceImpl (mage.choices.ChoiceImpl)1 Player (mage.players.Player)1