diff --git a/forge-ai/src/main/java/forge/ai/AiController.java b/forge-ai/src/main/java/forge/ai/AiController.java index 4eb070a1179..01f497aadbc 100644 --- a/forge-ai/src/main/java/forge/ai/AiController.java +++ b/forge-ai/src/main/java/forge/ai/AiController.java @@ -730,7 +730,21 @@ public class AiController { if (sa.getCardState() != null && !sa.getHostCard().isInPlay() && sa.getCardState().getStateName() == CardStateName.Modal) { sa.getHostCard().setState(CardStateName.Modal, false); } + AiPlayDecision canPlay = canPlaySa(sa); // this is the "heaviest" check, which also sets up targets, defines X, etc. + + // Account for possible Ward after the spell is fully targeted + if (sa.usesTargeting()) { + for (Card tgt : sa.getTargets().getTargetCards()) { + if (tgt.hasKeyword(Keyword.WARD)) { + int amount = tgt.getKeywordMagnitude(Keyword.WARD); + if (amount > 0 && !ComputerUtilCost.canPayCost(sa, player)) { + return AiPlayDecision.CantAfford; + } + } + } + } + if (sa.getCardState() != null && !sa.getHostCard().isInPlay() && sa.getCardState().getStateName() == CardStateName.Modal) { sa.getHostCard().setState(CardStateName.Original, false); } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java index 6568034d767..cb37f9c4f10 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java @@ -589,6 +589,15 @@ public class ComputerUtilCost { } } + // Ward - will be accounted for when rechecking a targeted ability + if (sa.usesTargeting()) { + for (Card tgt : sa.getTargets().getTargetCards()) { + if (tgt.hasKeyword(Keyword.WARD)) { + extraManaNeeded += tgt.getKeywordMagnitude(Keyword.WARD); + } + } + } + // TODO: Alternate costs which involve both paying mana and tapping a card, e.g. Zahid, Djinn of the Lamp // Current AI decides on each part separately, thus making it possible for the AI to cheat by // tapping a mana source for mana and for the tap cost at the same time. Until this is improved, AI