Search in sources :

Example 6 with VariableManaCost

use of mage.abilities.costs.mana.VariableManaCost in project mage by magefree.

the class AbilityImpl method handleManaXCosts.

/**
 * Handles X mana costs and sets manaCostsToPay.
 *
 * @param game
 * @param noMana
 * @param controller
 * @return variableManaCost for posting to log later
 */
protected VariableManaCost handleManaXCosts(Game game, boolean noMana, Player controller) {
    // 20210723 - 601.2b
    // If the spell has alternative or additional costs that will
    // be paid as it’s being cast such as buyback or kicker costs (see rules 118.8 and 118.9),
    // the player announces their intentions to pay any or all of those costs (see rule 601.2f).
    // A player can’t apply two alternative methods of casting or two alternative costs to a
    // single spell. If the spell has a variable cost that will be paid as it’s being cast
    // (such as an {X} in its mana cost; see rule 107.3), the player announces the value of that
    // variable. If the value of that variable is defined in the text of the spell by a choice
    // that player would make later in the announcement or resolution of the spell, that player
    // makes that choice at this time instead of that later time.
    // TODO: Handle announcing other variable costs here like: RemoveVariableCountersSourceCost
    VariableManaCost variableManaCost = null;
    for (ManaCost cost : manaCostsToPay) {
        if (cost instanceof VariableManaCost) {
            if (variableManaCost == null) {
                variableManaCost = (VariableManaCost) cost;
            } else {
                // only one VariableManCost per spell (or is it possible to have more?)
                logger.error("Variable mana cost allowes only in one instance per ability: " + this);
            }
        }
    }
    if (variableManaCost != null) {
        if (!variableManaCost.isPaid()) {
            // should only happen for human players
            int xValue;
            int xValueMultiplier = handleManaXMultiplier(game, 1);
            if (!noMana || variableManaCost.getCostType().canUseAnnounceOnFreeCast()) {
                xValue = controller.announceXMana(variableManaCost.getMinX(), variableManaCost.getMaxX(), xValueMultiplier, "Announce the value for " + variableManaCost.getText(), game, this);
                int amountMana = xValue * variableManaCost.getXInstancesCount();
                StringBuilder manaString = threadLocalBuilder.get();
                if (variableManaCost.getFilter() == null || variableManaCost.getFilter().isGeneric()) {
                    manaString.append('{').append(amountMana).append('}');
                } else {
                    String manaSymbol = null;
                    if (variableManaCost.getFilter().isBlack()) {
                        if (variableManaCost.getFilter().isRed()) {
                            manaSymbol = "B/R";
                        } else {
                            manaSymbol = "B";
                        }
                    } else if (variableManaCost.getFilter().isRed()) {
                        manaSymbol = "R";
                    } else if (variableManaCost.getFilter().isBlue()) {
                        manaSymbol = "U";
                    } else if (variableManaCost.getFilter().isGreen()) {
                        manaSymbol = "G";
                    } else if (variableManaCost.getFilter().isWhite()) {
                        manaSymbol = "W";
                    }
                    if (manaSymbol == null) {
                        throw new UnsupportedOperationException("ManaFilter is not supported: " + this);
                    }
                    for (int i = 0; i < amountMana; i++) {
                        manaString.append('{').append(manaSymbol).append('}');
                    }
                }
                manaCostsToPay.add(new ManaCostsImpl(manaString.toString()));
                manaCostsToPay.setX(xValue * xValueMultiplier, amountMana);
            }
            variableManaCost.setPaid();
        }
    }
    return variableManaCost;
}
Also used : ThreadLocalStringBuilder(mage.util.ThreadLocalStringBuilder) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Hint(mage.abilities.hint.Hint) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Example 7 with VariableManaCost

use of mage.abilities.costs.mana.VariableManaCost in project mage by magefree.

the class SimulatedPlayer2 method addVariableXOptions.

@Override
protected void addVariableXOptions(List<Ability> options, Ability ability, int targetNum, Game game) {
    // calculate the mana that can be used for the x part
    int numAvailable = getAvailableManaProducers(game).size() - ability.getManaCosts().manaValue();
    Card card = game.getCard(ability.getSourceId());
    if (card != null && numAvailable > 0) {
        // check if variable mana costs is included and get the multiplier
        VariableManaCost variableManaCost = null;
        for (ManaCost cost : ability.getManaCostsToPay()) {
            if (cost instanceof VariableManaCost && !cost.isPaid()) {
                variableManaCost = (VariableManaCost) cost;
                // only one VariableManCost per spell (or is it possible to have more?)
                break;
            }
        }
        if (variableManaCost != null) {
            int xInstancesCount = variableManaCost.getXInstancesCount();
            for (int mana = variableManaCost.getMinX(); mana <= numAvailable; mana++) {
                if (mana % xInstancesCount == 0) {
                    // use only values dependant from multiplier
                    // find possible X value to pay
                    int xAnnounceValue = mana / xInstancesCount;
                    Ability newAbility = ability.copy();
                    VariableManaCost varCost = null;
                    for (ManaCost cost : newAbility.getManaCostsToPay()) {
                        if (cost instanceof VariableManaCost && !cost.isPaid()) {
                            varCost = (VariableManaCost) cost;
                            // only one VariableManCost per spell (or is it possible to have more?)
                            break;
                        }
                    }
                    // find real X value after replace events
                    int xMultiplier = 1;
                    if (newAbility instanceof AbilityImpl) {
                        xMultiplier = ((AbilityImpl) newAbility).handleManaXMultiplier(game, xMultiplier);
                    }
                    newAbility.getManaCostsToPay().add(new ManaCostsImpl(new StringBuilder("{").append(xAnnounceValue).append('}').toString()));
                    newAbility.getManaCostsToPay().setX(xAnnounceValue * xMultiplier, xAnnounceValue * xInstancesCount);
                    if (varCost != null) {
                        varCost.setPaid();
                    }
                    card.adjustTargets(newAbility, game);
                    // add the different possible target option for the specific X value
                    if (!newAbility.getTargets().getUnchosen().isEmpty()) {
                        addTargetOptions(options, newAbility, targetNum, game);
                    }
                }
            }
        }
    }
}
Also used : PassAbility(mage.abilities.common.PassAbility) StackAbility(mage.game.stack.StackAbility) TriggeredAbility(mage.abilities.TriggeredAbility) ActivatedAbility(mage.abilities.ActivatedAbility) Ability(mage.abilities.Ability) AbilityImpl(mage.abilities.AbilityImpl) VariableManaCost(mage.abilities.costs.mana.VariableManaCost) ManaCost(mage.abilities.costs.mana.ManaCost) ManaCostsImpl(mage.abilities.costs.mana.ManaCostsImpl) Card(mage.cards.Card) VariableManaCost(mage.abilities.costs.mana.VariableManaCost)

Aggregations

VariableManaCost (mage.abilities.costs.mana.VariableManaCost)7 ManaCost (mage.abilities.costs.mana.ManaCost)4 Hint (mage.abilities.hint.Hint)3 UUID (java.util.UUID)2 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)2 Card (mage.cards.Card)2 Player (mage.players.Player)2 ThreadLocalStringBuilder (mage.util.ThreadLocalStringBuilder)2 MageObject (mage.MageObject)1 Ability (mage.abilities.Ability)1 AbilityImpl (mage.abilities.AbilityImpl)1 ActivatedAbility (mage.abilities.ActivatedAbility)1 TriggeredAbility (mage.abilities.TriggeredAbility)1 PassAbility (mage.abilities.common.PassAbility)1 Cost (mage.abilities.costs.Cost)1 VariableCost (mage.abilities.costs.VariableCost)1 PayLifeCost (mage.abilities.costs.common.PayLifeCost)1 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)1 Cards (mage.cards.Cards)1 CardsImpl (mage.cards.CardsImpl)1