checkETBeffects: be a bit less greedy when facing death

This commit is contained in:
tool4EvEr
2021-10-19 21:19:13 +02:00
parent dc3c117ba8
commit 25e35e3468
3 changed files with 8 additions and 4 deletions

View File

@@ -329,6 +329,10 @@ public class AiController {
// These checks only work if the Executing SpellAbility is an Ability_Sub. // These checks only work if the Executing SpellAbility is an Ability_Sub.
if (exSA instanceof AbilitySub && !doTrigger(exSA, false)) { if (exSA instanceof AbilitySub && !doTrigger(exSA, false)) {
// AI would not run this trigger if given the chance // AI would not run this trigger if given the chance
if (api == null && card.isCreature() && exSA.usesTargeting() && !exSA.getTargetRestrictions().hasCandidates(exSA) && ComputerUtil.aiLifeInDanger(activatingPlayer, true, 0)) {
// trigger will not run due to lack of targets and we desperately need a creature
continue;
}
return false; return false;
} }
} }

View File

@@ -3015,6 +3015,7 @@ public class ComputerUtil {
// call this to determine if it's safe to use a life payment spell // call this to determine if it's safe to use a life payment spell
// or trigger "emergency" strategies such as holding mana for Spike Weaver of Counterspell. // or trigger "emergency" strategies such as holding mana for Spike Weaver of Counterspell.
public static boolean aiLifeInDanger(Player ai, boolean serious, int payment) { public static boolean aiLifeInDanger(Player ai, boolean serious, int payment) {
// TODO should also consider them as teams
for (Player opponent: ai.getOpponents()) { for (Player opponent: ai.getOpponents()) {
// test whether the human can kill the ai next turn // test whether the human can kill the ai next turn
Combat combat = new Combat(opponent); Combat combat = new Combat(opponent);
@@ -3035,10 +3036,10 @@ public class ComputerUtil {
// examples : Black Vise, The Rack, known direct damage spells in enemy hand, etc // examples : Black Vise, The Rack, known direct damage spells in enemy hand, etc
// If added, might need a parameter to define whether we want to check all threats or combat threats. // If added, might need a parameter to define whether we want to check all threats or combat threats.
if ((serious) && (ComputerUtilCombat.lifeInSeriousDanger(ai, combat, payment))) { if (serious && ComputerUtilCombat.lifeInSeriousDanger(ai, combat, payment)) {
return true; return true;
} }
if ((!serious) && (ComputerUtilCombat.lifeInDanger(ai, combat, payment))) { if (!serious && ComputerUtilCombat.lifeInDanger(ai, combat, payment)) {
return true; return true;
} }
} }

View File

@@ -94,7 +94,6 @@ public class Cost implements Serializable {
return true; return true;
} }
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public <T extends CostPart> T getCostPartByType(Class<T> costType) { public <T extends CostPart> T getCostPartByType(Class<T> costType) {
for (CostPart p : getCostParts()) { for (CostPart p : getCostParts()) {