Search in sources :

Example 26 with ManaCost

use of mage.abilities.costs.mana.ManaCost 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

ManaCost (mage.abilities.costs.mana.ManaCost)26 Player (mage.players.Player)16 ManaCostsImpl (mage.abilities.costs.mana.ManaCostsImpl)11 Permanent (mage.game.permanent.Permanent)9 Card (mage.cards.Card)8 Cost (mage.abilities.costs.Cost)6 GenericManaCost (mage.abilities.costs.mana.GenericManaCost)6 UUID (java.util.UUID)4 Ability (mage.abilities.Ability)4 VariableManaCost (mage.abilities.costs.mana.VariableManaCost)4 TargetPermanent (mage.target.TargetPermanent)4 ArrayList (java.util.ArrayList)3 ActivatedManaAbilityImpl (mage.abilities.mana.ActivatedManaAbilityImpl)3 FilterPermanent (mage.filter.FilterPermanent)3 Iterator (java.util.Iterator)2 LinkedHashMap (java.util.LinkedHashMap)2 List (java.util.List)2 ApprovingObject (mage.ApprovingObject)2 Mana (mage.Mana)2 ObjectColor (mage.ObjectColor)2