From 10101b5f017a6e65b2ce4f93bddcddf736892c5d Mon Sep 17 00:00:00 2001 From: Agetian Date: Sat, 28 Jan 2017 14:13:11 +0000 Subject: [PATCH] - 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? --- .../java/forge/ai/ability/CountersPutAi.java | 23 ++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java index 9e3d298ef43..ea7945b963e 100644 --- a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java @@ -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; @@ -290,6 +291,10 @@ public class CountersPutAi extends SpellAbilityAi { } } } + + if (sa.hasParam("Monstrosity")) { + return true; + } PhaseHandler ph = ai.getGame().getPhaseHandler(); @@ -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) {