mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-18 11:48:02 +00:00
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:
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user