Merge branch 'damageprevent' into 'master'

DamagePreventAi: Add extra sanity check

See merge request core-developers/forge!5523
This commit is contained in:
Michael Kamensky
2021-10-08 13:17:36 +00:00
2 changed files with 9 additions and 0 deletions

View File

@@ -263,8 +263,15 @@ public class ComputerUtilCombat {
* @return a int.
*/
public static int sumDamageIfUnblocked(final Iterable<Card> attackers, final Player attacked) {
return sumDamageIfUnblocked(attackers, attacked, false);
}
public static int sumDamageIfUnblocked(final Iterable<Card> 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;

View File

@@ -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;