- Deduce the number of {X} shards in cost to properly adjust PayX for basic spell costs (e.g. Hangarback Walker, Walking Ballista) in CountersPutAi.

- The game did not used to require this, why does it need it now? Maybe there's a better solution that needs to be applied elsewhere?
This commit is contained in:
Agetian
2017-01-28 14:13:11 +00:00
parent ae4e7c252a
commit 10101b5f01

View File

@@ -10,6 +10,7 @@ import com.google.common.collect.Iterables;
import com.google.common.collect.Lists;
import forge.ai.*;
import forge.card.CardStateName;
import forge.game.Game;
import forge.game.GameEntity;
import forge.game.ability.AbilityUtils;
@@ -291,6 +292,10 @@ public class CountersPutAi extends SpellAbilityAi {
}
}
if (sa.hasParam("Monstrosity")) {
return true;
}
PhaseHandler ph = ai.getGame().getPhaseHandler();
if (!ai.getGame().getStack().isEmpty() && !SpellAbilityAi.isSorcerySpeed(sa)) {
@@ -564,8 +569,24 @@ public class CountersPutAi extends SpellAbilityAi {
list = new CardCollection(AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), sa));
if (amountStr.equals("X") && ((sa.hasParam(amountStr) && sa.getSVar(amountStr).equals("Count$xPaid")) || source.getSVar(amountStr).equals("Count$xPaid") )) {
// detect if there's more than one X in the cost (Hangarback Walker, Walking Ballista, etc.)
SpellAbility testSa = sa;
int countX = 0;
while (testSa != null && testSa.getPayCosts() != null && countX == 0) {
countX = testSa.getPayCosts().getTotalMana().countX();
testSa = testSa.getSubAbility();
}
if (countX == 0) {
// try determining it from the card itself if neither SA has "X" in the cost
countX = source.getState(CardStateName.Original).getManaCost().countX();
}
// Spend all remaining mana to add X counters (eg. Hero of Leina Tower)
source.setSVar("PayX", Integer.toString(ComputerUtilMana.determineLeftoverMana(sa, ai)));
int payX = ComputerUtilMana.determineLeftoverMana(sa, ai);
if (countX > 1) { payX /= countX; }
source.setSVar("PayX", Integer.toString(payX));
}
if (!mandatory) {