Search in sources :

Example 1 with VariableCost

use of mage.abilities.costs.VariableCost in project mage by magefree.

the class SpellAbility method getConvertedXManaCost.

public int getConvertedXManaCost(Card card) {
    int xMultiplier = 0;
    int amount = 0;
    if (card == null) {
        return 0;
    }
    // mana cost instances
    for (ManaCost manaCost : card.getManaCost()) {
        if (manaCost instanceof VariableManaCost) {
            xMultiplier = ((VariableManaCost) manaCost).getXInstancesCount();
            break;
        }
    }
    // mana cost final X value
    boolean hasNonManaXCost = false;
    for (Cost cost : getCosts()) {
        if (cost instanceof VariableCost) {
            hasNonManaXCost = true;
            amount = ((VariableCost) cost).getAmount();
            break;
        }
    }
    if (!hasNonManaXCost) {
        amount = getManaCostsToPay().getX();
    }
    return amount * xMultiplier;
}
Also used : VariableCost(mage.abilities.costs.VariableCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) Cost(mage.abilities.costs.Cost) VariableCost(mage.abilities.costs.VariableCost) ManaCost(mage.abilities.costs.mana.ManaCost) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Example 2 with VariableCost

use of mage.abilities.costs.VariableCost in project mage by magefree.

the class CardUtil method adjustCost.

/**
 * Adjusts spell or ability cost to be paid by colored and generic mana.
 *
 * @param spellAbility
 * @param manaCostsToReduce costs to reduce
 * @param convertToGeneric  colored mana does reduce generic mana if no
 *                          appropriate colored mana is in the costs
 *                          included
 */
public static void adjustCost(SpellAbility spellAbility, ManaCosts<ManaCost> manaCostsToReduce, boolean convertToGeneric) {
    ManaCosts<ManaCost> previousCost = spellAbility.getManaCostsToPay();
    ManaCosts<ManaCost> adjustedCost = new ManaCostsImpl<>();
    // save X value (e.g. convoke ability)
    for (VariableCost vCost : previousCost.getVariableCosts()) {
        if (vCost instanceof VariableManaCost) {
            adjustedCost.add((VariableManaCost) vCost);
        }
    }
    Mana reduceMana = new Mana();
    for (ManaCost manaCost : manaCostsToReduce) {
        if (manaCost instanceof MonoHybridManaCost) {
            reduceMana.add(Mana.GenericMana(2));
        } else {
            reduceMana.add(manaCost.getMana());
        }
    }
    ManaCosts<ManaCost> manaCostToCheckForGeneric = new ManaCostsImpl<>();
    // subtract non-generic mana
    for (ManaCost newManaCost : previousCost) {
        Mana mana = newManaCost.getMana();
        if (!(newManaCost instanceof MonoHybridManaCost) && mana.getGeneric() > 0) {
            manaCostToCheckForGeneric.add(newManaCost);
            continue;
        }
        boolean hybridMana = newManaCost instanceof HybridManaCost;
        if (mana.getBlack() > 0 && reduceMana.getBlack() > 0) {
            if (reduceMana.getBlack() > mana.getBlack()) {
                reduceMana.setBlack(reduceMana.getBlack() - mana.getBlack());
                mana.setBlack(0);
            } else {
                mana.setBlack(mana.getBlack() - reduceMana.getBlack());
                reduceMana.setBlack(0);
            }
            if (hybridMana) {
                continue;
            }
        }
        if (mana.getRed() > 0 && reduceMana.getRed() > 0) {
            if (reduceMana.getRed() > mana.getRed()) {
                reduceMana.setRed(reduceMana.getRed() - mana.getRed());
                mana.setRed(0);
            } else {
                mana.setRed(mana.getRed() - reduceMana.getRed());
                reduceMana.setRed(0);
            }
            if (hybridMana) {
                continue;
            }
        }
        if (mana.getBlue() > 0 && reduceMana.getBlue() > 0) {
            if (reduceMana.getBlue() > mana.getBlue()) {
                reduceMana.setBlue(reduceMana.getBlue() - mana.getBlue());
                mana.setBlue(0);
            } else {
                mana.setBlue(mana.getBlue() - reduceMana.getBlue());
                reduceMana.setBlue(0);
            }
            if (hybridMana) {
                continue;
            }
        }
        if (mana.getGreen() > 0 && reduceMana.getGreen() > 0) {
            if (reduceMana.getGreen() > mana.getGreen()) {
                reduceMana.setGreen(reduceMana.getGreen() - mana.getGreen());
                mana.setGreen(0);
            } else {
                mana.setGreen(mana.getGreen() - reduceMana.getGreen());
                reduceMana.setGreen(0);
            }
            if (hybridMana) {
                continue;
            }
        }
        if (mana.getWhite() > 0 && reduceMana.getWhite() > 0) {
            if (reduceMana.getWhite() > mana.getWhite()) {
                reduceMana.setWhite(reduceMana.getWhite() - mana.getWhite());
                mana.setWhite(0);
            } else {
                mana.setWhite(mana.getWhite() - reduceMana.getWhite());
                reduceMana.setWhite(0);
            }
            if (hybridMana) {
                continue;
            }
        }
        if (mana.getColorless() > 0 && reduceMana.getColorless() > 0) {
            if (reduceMana.getColorless() > mana.getColorless()) {
                reduceMana.setColorless(reduceMana.getColorless() - mana.getColorless());
                mana.setColorless(0);
            } else {
                mana.setColorless(mana.getColorless() - reduceMana.getColorless());
                reduceMana.setColorless(0);
            }
        }
        if (mana.count() > 0) {
            if (newManaCost instanceof MonoHybridManaCost) {
                if (mana.count() == 2) {
                    reduceMana.setGeneric(reduceMana.getGeneric() - 2);
                    continue;
                }
            }
            manaCostToCheckForGeneric.add(newManaCost);
        }
    }
    // subtract colorless mana, use all mana that is left
    int reduceAmount;
    if (convertToGeneric) {
        reduceAmount = reduceMana.count();
    } else {
        reduceAmount = reduceMana.getGeneric();
    }
    if (reduceAmount > 0) {
        for (ManaCost newManaCost : manaCostToCheckForGeneric) {
            Mana mana = newManaCost.getMana();
            if (mana.getGeneric() == 0 || reduceAmount == 0) {
                adjustedCost.add(newManaCost);
                continue;
            }
            if (newManaCost instanceof MonoHybridManaCost) {
                if (reduceAmount > 1) {
                    reduceAmount -= 2;
                    mana.clear();
                }
                continue;
            }
            if (mana.getGeneric() > 0) {
                if (reduceAmount > mana.getGeneric()) {
                    reduceAmount -= mana.getGeneric();
                    mana.setGeneric(0);
                } else {
                    mana.setGeneric(mana.getGeneric() - reduceAmount);
                    reduceAmount = 0;
                }
            }
            if (mana.count() > 0) {
                adjustedCost.add(0, new GenericManaCost(mana.count()));
            }
        }
    } else {
        adjustedCost.addAll(manaCostToCheckForGeneric);
    }
    if (adjustedCost.isEmpty()) {
        // neede to check if cost was reduced to 0
        adjustedCost.add(new GenericManaCost(0));
    }
    // keep mana source restrictions
    adjustedCost.setSourceFilter(previousCost.getSourceFilter());
    spellAbility.getManaCostsToPay().clear();
    spellAbility.getManaCostsToPay().addAll(adjustedCost);
}
Also used : VariableCost(mage.abilities.costs.VariableCost) Mana(mage.Mana) Hint(mage.abilities.hint.Hint)

Aggregations

VariableCost (mage.abilities.costs.VariableCost)2 Mana (mage.Mana)1 Cost (mage.abilities.costs.Cost)1 ManaCost (mage.abilities.costs.mana.ManaCost)1 VariableManaCost (mage.abilities.costs.mana.VariableManaCost)1 Hint (mage.abilities.hint.Hint)1