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