From b5800afa65349bc8693deb51c6ca0afdafc1a0ee Mon Sep 17 00:00:00 2001 From: TRT <> Date: Fri, 8 Oct 2021 15:14:24 +0200 Subject: [PATCH] Add extra sanity check --- forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java | 7 +++++++ .../src/main/java/forge/ai/ability/DamagePreventAi.java | 2 ++ 2 files changed, 9 insertions(+) diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java index 20ec0060a27..826579d699f 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java @@ -263,8 +263,15 @@ public class ComputerUtilCombat { * @return a int. */ public static int sumDamageIfUnblocked(final Iterable attackers, final Player attacked) { + return sumDamageIfUnblocked(attackers, attacked, false); + } + public static int sumDamageIfUnblocked(final Iterable attackers, final Player attacked, boolean onlyPreventable) { int sum = 0; for (final Card attacker : attackers) { + if (onlyPreventable && !attacker.canDamagePrevented(true)) { + continue; + } + // TODO always applies full prevention shields for each, so this might wrongly lower the result sum += damageIfUnblocked(attacker, attacked, null, false); } return sum; diff --git a/forge-ai/src/main/java/forge/ai/ability/DamagePreventAi.java b/forge-ai/src/main/java/forge/ai/ability/DamagePreventAi.java index 60541c2d738..8ea6208ffed 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DamagePreventAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DamagePreventAi.java @@ -112,6 +112,8 @@ public class DamagePreventAi extends SpellAbilityAi { final TargetChoices tcs = sa.getTargets(); if (sa.canTarget(ai) && ComputerUtilCombat.wouldLoseLife(ai, combat) && (ComputerUtilCombat.lifeInDanger(ai, combat) || sa.isAbility() || sa.isTrigger()) + // check if any of the incoming dmg is even preventable: + && (ComputerUtilCombat.sumDamageIfUnblocked(combat.getAttackers(), ai, true) > ai.getPreventNextDamageTotalShields()) && game.getPhaseHandler().getPlayerTurn().isOpponentOf(ai)) { tcs.add(ai); chance = true;