From 7def3a9e6b805d86367c8550432cf82b398ec75e Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Sun, 2 Apr 2023 10:31:53 +0200 Subject: [PATCH] Tweak logic so it checks the right face for cost --- .../src/main/java/forge/ai/AiController.java | 30 ++++++++++++------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index edcbb5004b0..8136f0d5ac9 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -738,7 +738,6 @@ public class AiController { return false; } - // This is for playing spells regularly (no Cascade/Ripple etc.) private AiPlayDecision canPlayAndPayFor(final SpellAbility sa) { if (!sa.canPlay()) { return AiPlayDecision.CantPlaySa; @@ -746,6 +745,25 @@ public class AiController { final Card host = sa.getHostCard(); + // state needs to be switched here so API checks evaluate the right face + CardStateName currentState = sa.getCardState() != null && host.getCurrentStateName() != sa.getCardStateName() && !host.isInPlay() ? host.getCurrentStateName() : null; + if (currentState != null) { + host.setState(sa.getCardStateName(), false); + } + + AiPlayDecision decision = canPlayAndPayForFace(sa); + + if (currentState != null) { + host.setState(currentState, false); + } + + return decision; + } + + // This is for playing spells regularly (no Cascade/Ripple etc.) + private AiPlayDecision canPlayAndPayForFace(final SpellAbility sa) { + final Card host = sa.getHostCard(); + // Check a predefined condition if (sa.hasParam("AICheckSVar")) { final String svarToCheck = sa.getParam("AICheckSVar"); @@ -783,18 +801,8 @@ public class AiController { } } - // state needs to be switched here so API checks evaluate the right face - CardStateName currentState = sa.getCardState() != null && host.getCurrentStateName() != sa.getCardStateName() && !host.isInPlay() ? host.getCurrentStateName() : null; - if (currentState != null) { - host.setState(sa.getCardStateName(), false); - } - AiPlayDecision canPlay = canPlaySa(sa); // this is the "heaviest" check, which also sets up targets, defines X, etc. - if (currentState != null) { - host.setState(currentState, false); - } - if (canPlay != AiPlayDecision.WillPlay) { return canPlay; }