diff --git a/forge-ai/src/main/java/forge/ai/ability/LifeExchangeVariantAi.java b/forge-ai/src/main/java/forge/ai/ability/LifeExchangeVariantAi.java index 33737a66224..38686d589df 100644 --- a/forge-ai/src/main/java/forge/ai/ability/LifeExchangeVariantAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/LifeExchangeVariantAi.java @@ -3,6 +3,7 @@ package forge.ai.ability; import forge.ai.*; import forge.game.Game; import forge.game.card.Card; +import forge.game.keyword.Keyword; import forge.game.phase.PhaseType; import forge.game.player.Player; import forge.game.spellability.SpellAbility; @@ -88,6 +89,27 @@ public class LifeExchangeVariantAi extends SpellAbilityAi { int aiLife = ai.getLife(); + // Offensive use of Evra, try to kill the opponent or deal a lot of damage, and hopefully gain a lot of life too + if (game.getCombat() != null && game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS) + && game.getCombat().isAttacking(source) && source.getNetPower() > 0 + && source.getNetPower() < aiLife) { + Player def = game.getCombat().getDefenderPlayerByAttacker(source); + if (game.getCombat().isUnblocked(source) && def.canLoseLife() && aiLife >= def.getLife() && source.getNetPower() < def.getLife()) { + // Unblocked Evra which can deal lethal damage + return true; + } else if (ai.getController().isAI() && aiLife > source.getNetPower() && source.hasKeyword(Keyword.LIFELINK)) { + int dangerMin = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_THRESHOLD)); + int dangerMax = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_MAX_THRESHOLD)); + int dangerDiff = dangerMax - dangerMin; + int lifeInDanger = dangerDiff <= 0 ? dangerMin : MyRandom.getRandom().nextInt(dangerDiff) + dangerMin; + if (source.getNetPower() >= lifeInDanger && ComputerUtil.lifegainPositive(ai, source)) { + // Blocked or unblocked Evra which will get bigger *and* we're getting our life back through Lifelink + return true; + } + } + } + + // Defensive use of Evra, try to debuff Evra to try to gain some life if (source.getNetPower() > aiLife) { if (ComputerUtilCombat.lifeInSeriousDanger(ai, game.getCombat())) { return true; @@ -103,24 +125,6 @@ public class LifeExchangeVariantAi extends SpellAbilityAi { } } - if (game.getCombat() != null && game.getPhaseHandler().is(PhaseType.COMBAT_DECLARE_BLOCKERS) - && game.getCombat().isAttacking(source) && source.getNetPower() > 0 - && source.getNetPower() < ai.getLife()) { - Player def = game.getCombat().getDefenderPlayerByAttacker(source); - if (game.getCombat().isUnblocked(source) && def.canLoseLife() && ai.getLife() >= def.getLife() && source.getNetPower() < def.getLife()) { - // Unblocked Evra which can deal lethal damage - return true; - } else if (ai.getLife() > source.getNetPower()) { - int dangerMin = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_THRESHOLD)); - int dangerMax = (((PlayerControllerAi) ai.getController()).getAi().getIntProperty(AiProps.AI_IN_DANGER_MAX_THRESHOLD)); - int dangerDiff = dangerMax - dangerMin; - int lifeInDanger = dangerDiff == 0 ? dangerMin : MyRandom.getRandom().nextInt(dangerDiff) + dangerMin; - if (source.getNetPower() >= lifeInDanger) { - // Blocked or unblocked Evra which will get bigger *and* we're getting our life back through Lifelink - return true; - } - } - } } return false;