From 465066c04cc77bf8216167c7821cd372c657e30f Mon Sep 17 00:00:00 2001 From: Seravy Date: Wed, 14 Feb 2018 19:20:57 +0100 Subject: [PATCH] Had to move this part to a new "AvoidTargetP" function - shouldtargetP is not absolute, the AI still targets the player if there is no better target move, but we want it to not use the ability instead. --- .../java/forge/ai/ability/DamageAiBase.java | 45 +++++++++++-------- .../java/forge/ai/ability/DamageDealAi.java | 5 ++- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/ability/DamageAiBase.java b/forge-ai/src/main/java/forge/ai/ability/DamageAiBase.java index 56e9d66f6d4..c20df1d3302 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DamageAiBase.java +++ b/forge-ai/src/main/java/forge/ai/ability/DamageAiBase.java @@ -18,6 +18,31 @@ import forge.game.zone.ZoneType; import forge.util.MyRandom; public abstract class DamageAiBase extends SpellAbilityAi { + protected boolean avoidTargetP(final Player comp, final SpellAbility sa) { + Player enemy = ComputerUtil.getOpponentFor(comp); + // Logic for cards that damage owner, like Fireslinger + // Do not target a player if they aren't below 75% of our health. + // Unless Lifelink will cancel the damage to us + Card hostcard = sa.getHostCard(); + boolean lifelink = hostcard.hasKeyword("Lifelink"); + for (Card ench : hostcard.getEnchantedBy(false)) { + // Treat cards enchanted by older cards with "when enchanted creature deals damage, gain life" as if they had lifelink. + if (ench.hasSVar("LikeLifeLink")) { + if ("True".equals(ench.getSVar("LikeLifeLink"))) { + lifelink = true; + } + } + } + if ("SelfDamage".equals(sa.getParam("AILogic"))) { + if (comp.getLife() * 0.75 < enemy.getLife()) { + if (!lifelink) { + return true; + } + } + } + return false; + } + protected boolean shouldTgtP(final Player comp, final SpellAbility sa, final int d, final boolean noPrevention) { int restDamage = d; final Game game = comp.getGame(); @@ -53,24 +78,8 @@ public abstract class DamageAiBase extends SpellAbilityAi { return true; } - // Logic for cards that damage owner, like Fireslinger - // Do not target a player if they aren't below 75% of our health. - // Unless Lifelink will cancel the damage to us - boolean lifelink = hostcard.hasKeyword("Lifelink"); - for (Card ench : hostcard.getEnchantedBy(false)) { - // Treat cards enchanted by older cards with "when enchanted creature deals damage, gain life" as if they had lifelink. - if (ench.hasSVar("LikeLifeLink")) { - if ("True".equals(ench.getSVar("LikeLifeLink"))) { - lifelink = true; - } - } - } - if ("SelfDamage".equals(sa.getParam("AILogic"))) { - if (comp.getLife() * 0.75 < enemy.getLife()) { - if (!lifelink) { - return false; - } - } + if (avoidTargetP(comp, sa)) { + return false; } if (!noPrevention) { diff --git a/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java b/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java index dac507f5182..1a34d2c573b 100644 --- a/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/DamageDealAi.java @@ -573,10 +573,11 @@ public class DamageDealAi extends DamageAiBase { // TODO: Improve Damage, we shouldn't just target the player just // because we can else if (sa.canTarget(enemy)) { - if ((phase.is(PhaseType.END_OF_TURN) && phase.getNextTurn().equals(ai)) + if (((phase.is(PhaseType.END_OF_TURN) && phase.getNextTurn().equals(ai)) || (SpellAbilityAi.isSorcerySpeed(sa) && phase.is(PhaseType.MAIN2)) || sa.getPayCosts() == null || immediately - || this.shouldTgtP(ai, sa, dmg, noPrevention)) { + || this.shouldTgtP(ai, sa, dmg, noPrevention)) && + (!avoidTargetP(ai, sa))) { tcs.add(enemy); if (divided) { tgt.addDividedAllocation(enemy, dmg);