mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-13 17:27:46 +00:00
Merge branch 'damageprevent' into 'master'
DamagePreventAi: Add extra sanity check See merge request core-developers/forge!5523
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user