mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
- More combat AI improvements (predicting pump abilities).
This commit is contained in:
@@ -1996,7 +1996,8 @@ public class CombatUtil {
|
||||
* a {@link forge.game.phase.Combat} object.
|
||||
* @return a int.
|
||||
*/
|
||||
public static int predictToughnessBonusOfAttacker(final Card attacker, final Card defender, final Combat combat) {
|
||||
public static int predictToughnessBonusOfAttacker(final Card attacker, final Card defender, final Combat combat
|
||||
, boolean withoutAbilities) {
|
||||
int toughness = 0;
|
||||
|
||||
//check Exalted only for the first attacker
|
||||
@@ -2121,6 +2122,25 @@ public class CombatUtil {
|
||||
toughness += CardFactoryUtil.xCount(source, bonus);
|
||||
}
|
||||
}
|
||||
if (withoutAbilities) {
|
||||
return toughness;
|
||||
}
|
||||
for (SpellAbility ability : attacker.getAllSpellAbilities()) {
|
||||
if (!(ability instanceof AbilityActivated) || ability.getPayCosts() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ability.getApi() != ApiType.Pump || !ability.hasParam("NumDef")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!ability.getPayCosts().getTap() && ComputerUtil.canPayCost(ability, attacker.getController())) {
|
||||
int tBonus = AbilityFactory.calculateAmount(ability.getSourceCard(), ability.getParam("NumDef"), ability);
|
||||
if (tBonus > 0) {
|
||||
toughness += tBonus;
|
||||
}
|
||||
}
|
||||
}
|
||||
return toughness;
|
||||
}
|
||||
|
||||
@@ -2291,7 +2311,7 @@ public class CombatUtil {
|
||||
defenderDamage = defender.getNetDefense()
|
||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||
attackerDamage = attacker.getNetDefense()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||
}
|
||||
|
||||
int possibleDefenderPrevention = 0;
|
||||
@@ -2308,7 +2328,7 @@ public class CombatUtil {
|
||||
final int defenderLife = defender.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||
final int attackerLife = attacker.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||
|
||||
if (defender.hasKeyword("Double Strike")) {
|
||||
if (defenderDamage > 0 && (defender.hasKeyword("Deathtouch")
|
||||
@@ -2439,7 +2459,7 @@ public class CombatUtil {
|
||||
defenderDamage = defender.getNetDefense()
|
||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||
attackerDamage = attacker.getNetDefense()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||
}
|
||||
|
||||
int possibleDefenderPrevention = 0;
|
||||
@@ -2464,7 +2484,7 @@ public class CombatUtil {
|
||||
final int defenderLife = defender.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfBlocker(attacker, defender, withoutAbilities);
|
||||
final int attackerLife = attacker.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, defender, combat, withoutAbilities);
|
||||
|
||||
if (attacker.hasKeyword("Double Strike")) {
|
||||
if (attackerDamage > 0 && (attacker.hasKeyword("Deathtouch")
|
||||
|
||||
@@ -131,7 +131,7 @@ public class ComputerUtilAttack {
|
||||
public final boolean isEffectiveAttacker(final Player ai, final Card attacker, final Combat combat) {
|
||||
|
||||
// if the attacker will die when attacking don't attack
|
||||
if ((attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat)) <= 0) {
|
||||
if ((attacker.getNetDefense() + CombatUtil.predictToughnessBonusOfAttacker(attacker, null, combat, true)) <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -426,7 +426,7 @@ public class ComputerUtilBlock {
|
||||
CardLists.sortAttack(firstStrikeBlockers);
|
||||
for (final Card blocker : firstStrikeBlockers) {
|
||||
final int damageNeeded = attacker.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||
// if the total damage of the blockgang was not enough
|
||||
// without but is enough with this blocker finish the
|
||||
// blockgang
|
||||
@@ -493,7 +493,7 @@ public class ComputerUtilBlock {
|
||||
.getEnoughDamageToKill(attacker.getNetCombatDamage(), attacker, true);
|
||||
final int addedValue = CardFactoryUtil.evaluateCreature(blocker);
|
||||
final int damageNeeded = attacker.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||
if ((damageNeeded > currentDamage || CombatUtil.needsBlockers(attacker) > blockGang.size())
|
||||
&& !(damageNeeded > currentDamage + additionalDamage)
|
||||
// The attacker will be killed
|
||||
@@ -666,7 +666,7 @@ public class ComputerUtilBlock {
|
||||
safeBlockers = ComputerUtilBlock.getSafeBlockers(attacker, blockers, combat);
|
||||
for (final Card blocker : safeBlockers) {
|
||||
final int damageNeeded = attacker.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||
// Add an additional blocker if the current blockers are not
|
||||
// enough and the new one would deal additional damage
|
||||
if ((damageNeeded > CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker)))
|
||||
@@ -690,7 +690,7 @@ public class ComputerUtilBlock {
|
||||
|
||||
for (final Card blocker : safeBlockers) {
|
||||
final int damageNeeded = attacker.getKillDamage()
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat);
|
||||
+ CombatUtil.predictToughnessBonusOfAttacker(attacker, blocker, combat, false);
|
||||
// Add an additional blocker if the current blockers are not
|
||||
// enough and the new one would deal the remaining damage
|
||||
final int currentDamage = CombatUtil.totalDamageOfBlockers(attacker, combat.getBlockers(attacker));
|
||||
|
||||
Reference in New Issue
Block a user