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;
}
Aggregations