From 6789c29c6b40bd4cf9f0e06b8e56c8d63675fb9f Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Sat, 9 Oct 2021 12:33:43 +0200 Subject: [PATCH] canPlayAndPayFor: check for RaiseCost --- .../src/main/java/forge/ai/AiController.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index da490d0f130..cf7cce65384 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -743,11 +743,15 @@ public class AiController { return AiPlayDecision.CantPlaySa; } + int oldCMC = 0; boolean xCost = sa.getPayCosts().hasXInAnyCostPart() || sa.getHostCard().hasStartOfKeyword("Strive"); - 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; + if (!xCost) { + if (!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; + } + oldCMC = CostAdjustment.adjust(sa.getPayCosts(), sa).getTotalMana().getCMC(); } // state needs to be switched here so API checks evaluate the right face @@ -763,6 +767,14 @@ public class AiController { return canPlay; } + // check if some target raised cost + if (!xCost) { + int finalCMC = CostAdjustment.adjust(sa.getPayCosts(), sa).getTotalMana().getCMC(); + if (finalCMC > oldCMC) { + xCost = true; + } + } + 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, this can only be checked late after canPlaySa has been run (or the AI will misplay)