From 486265cbebd59fe744947b641320d5f440837c89 Mon Sep 17 00:00:00 2001 From: Agetian Date: Tue, 4 Dec 2018 07:17:18 +0300 Subject: [PATCH] - Fixed a bug which caused the AI not to play X-dependent targeting spells like Repeal anymore. --- .../src/main/java/forge/ai/AiController.java | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index e864ce31dcd..51126c4c884 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -670,7 +670,12 @@ public class AiController { // This is for playing spells regularly (no Cascade/Ripple etc.) private AiPlayDecision canPlayAndPayFor(final SpellAbility sa) { - if (!ComputerUtilCost.canPayCost(sa, player)) { + boolean XCost = sa.getHostCard() != null && sa.getHostCard().getManaCost() != null + && sa.getHostCard().getManaCost().countX() > 0; + + if (!XCost && !ComputerUtilCost.canPayCost(sa, player)) { + // for most costs, it's OK to check if they can be paid early in order to avoid running a heavy API check + // when the AI won't even be able to play the spell in the first place (even if it could afford it) return AiPlayDecision.CantAfford; } @@ -678,7 +683,20 @@ public class AiController { return AiPlayDecision.CantPlaySa; } - return canPlaySa(sa); + AiPlayDecision canPlay = canPlaySa(sa); // this is the "heaviest" check, which also sets up targets, defines X, etc. + if (canPlay != AiPlayDecision.WillPlay) { + return canPlay; + } + + if (XCost && !ComputerUtilCost.canPayCost(sa, player)) { + // for dependent costs with X, e.g. Repeal, which require a valid target to be specified before a decision can be made + // on whether the cost can be paid + return AiPlayDecision.CantAfford; + } + + // if we got here, looks like we can play the final cost and we could properly set up and target the API and + // are willing to play the SA + return AiPlayDecision.WillPlay; } public AiPlayDecision canPlaySa(SpellAbility sa) {