Merge branch 'update_prevention_predition' into 'master'

Update AI damage prevention prediction code

See merge request core-developers/forge!4683
This commit is contained in:
Michael Kamensky
2021-05-10 03:26:41 +00:00
2 changed files with 29 additions and 4 deletions

View File

@@ -2293,7 +2293,8 @@ public class ComputerUtilCombat {
for (final Card ca : game.getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES)) {
for (final ReplacementEffect re : ca.getReplacementEffects()) {
Map<String, String> params = re.getMapParams();
if (!re.getMode().equals(ReplacementType.DamageDone) || !params.containsKey("PreventionEffect")) {
if (!re.getMode().equals(ReplacementType.DamageDone) ||
(!params.containsKey("PreventionEffect") && !params.containsKey("Prevent"))) {
continue;
}
// Immortal Coil prevents the damage but has a similar negative effect
@@ -2320,6 +2321,14 @@ public class ComputerUtilCombat {
}
}
if (params.containsKey("Prevent")) {
return 0;
} else if (re.getOverridingAbility() != null) {
SpellAbility repSA = re.getOverridingAbility();
if (repSA.getApi() == ApiType.ReplaceDamage) {
return Math.max(0, restDamage - AbilityUtils.calculateAmount(ca, repSA.getParam("Amount"), repSA));
}
}
return 0;
}
}
@@ -2491,7 +2500,14 @@ public class ComputerUtilCombat {
List<ReplacementEffect> list = game.getReplacementHandler().getReplacementList(
ReplacementType.DamageDone, repParams, ReplacementLayer.Other);
return !list.isEmpty();
for (final ReplacementEffect re : list) {
Map<String, String> params = re.getMapParams();
if (params.containsKey("Prevent") ||
(re.getOverridingAbility() != null && re.getOverridingAbility().getApi() != ApiType.ReplaceDamage)) {
return true;
}
}
return false;
}
public static boolean attackerHasThreateningAfflict(Card attacker, Player aiDefender) {

View File

@@ -5170,10 +5170,11 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
return damage;
}
for (final Card ca : getGame().getCardsIn(ZoneType.Battlefield)) {
for (final Card ca : getGame().getCardsIn(ZoneType.STATIC_ABILITIES_SOURCE_ZONES)) {
for (final ReplacementEffect re : ca.getReplacementEffects()) {
Map<String, String> params = re.getMapParams();
if (!re.getMode().equals(ReplacementType.DamageDone) || !params.containsKey("PreventionEffect")) {
if (!re.getMode().equals(ReplacementType.DamageDone) ||
(!params.containsKey("PreventionEffect") && !params.containsKey("Prevent"))) {
continue;
}
if (params.containsKey("ValidSource")
@@ -5195,6 +5196,14 @@ public class Card extends GameEntity implements Comparable<Card>, IHasSVars {
}
}
}
if (params.containsKey("Prevent")) {
return 0;
} else if (re.getOverridingAbility() != null) {
SpellAbility repSA = re.getOverridingAbility();
if (repSA.getApi() == ApiType.ReplaceDamage) {
return Math.max(0, damage - AbilityUtils.calculateAmount(ca, repSA.getParam("Amount"), repSA));
}
}
return 0;
}
}