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.

This commit is contained in:
Seravy
2018-02-14 19:20:57 +01:00
parent 668eaa1a7c
commit 465066c04c
2 changed files with 30 additions and 20 deletions

View File

@@ -18,6 +18,31 @@ import forge.game.zone.ZoneType;
import forge.util.MyRandom; import forge.util.MyRandom;
public abstract class DamageAiBase extends SpellAbilityAi { 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) { protected boolean shouldTgtP(final Player comp, final SpellAbility sa, final int d, final boolean noPrevention) {
int restDamage = d; int restDamage = d;
final Game game = comp.getGame(); final Game game = comp.getGame();
@@ -53,24 +78,8 @@ public abstract class DamageAiBase extends SpellAbilityAi {
return true; return true;
} }
// Logic for cards that damage owner, like Fireslinger if (avoidTargetP(comp, sa)) {
// Do not target a player if they aren't below 75% of our health. return false;
// 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 (!noPrevention) { if (!noPrevention) {

View File

@@ -573,10 +573,11 @@ public class DamageDealAi extends DamageAiBase {
// TODO: Improve Damage, we shouldn't just target the player just // TODO: Improve Damage, we shouldn't just target the player just
// because we can // because we can
else if (sa.canTarget(enemy)) { 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)) || (SpellAbilityAi.isSorcerySpeed(sa) && phase.is(PhaseType.MAIN2))
|| sa.getPayCosts() == null || immediately || sa.getPayCosts() == null || immediately
|| this.shouldTgtP(ai, sa, dmg, noPrevention)) { || this.shouldTgtP(ai, sa, dmg, noPrevention)) &&
(!avoidTargetP(ai, sa))) {
tcs.add(enemy); tcs.add(enemy);
if (divided) { if (divided) {
tgt.addDividedAllocation(enemy, dmg); tgt.addDividedAllocation(enemy, dmg);