mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-19 12:18:00 +00:00
- Added a more conservative version of AILogic PayEnergy for PutCounter AI that only pays energy if the creature is in combat (attacking/blocking) or if there's more energy available than the most expensive energy cost of a permanent SA on the battlefield requires plus whatever the PutCounter SA requires.
- Set this logic for Longtusk Cub and Bristling Hydra. - TODO: maybe somehow teach the AI to pay energy if it can save the creature from lethal damage from a spell?
This commit is contained in:
@@ -40,6 +40,8 @@ import forge.game.card.CardUtil;
|
||||
import forge.game.card.CounterType;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
import forge.game.cost.CostPart;
|
||||
import forge.game.cost.CostPayEnergy;
|
||||
import forge.game.keyword.Keyword;
|
||||
import forge.game.phase.PhaseHandler;
|
||||
import forge.game.phase.PhaseType;
|
||||
@@ -1587,4 +1589,28 @@ public class ComputerUtilCard {
|
||||
public static boolean isPresentOnBattlefield(final Game game, final String cardName) {
|
||||
return !CardLists.filter(game.getCardsIn(ZoneType.Battlefield), CardPredicates.nameEquals(cardName)).isEmpty();
|
||||
}
|
||||
|
||||
public static int getMaxSAEnergyCostOnBattlefield(final Player ai) {
|
||||
// returns the maximum energy cost of an ability that permanents on the battlefield under AI's control have
|
||||
CardCollectionView otb = ai.getCardsIn(ZoneType.Battlefield);
|
||||
int maxEnergyCost = 0;
|
||||
|
||||
for (Card c : otb) {
|
||||
for (SpellAbility sa : c.getSpellAbilities()) {
|
||||
if (sa.getPayCosts() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
CostPayEnergy energyCost = sa.getPayCosts().getCostEnergy();
|
||||
if (energyCost != null) {
|
||||
int amount = energyCost.convertAmount();
|
||||
if (amount > maxEnergyCost) {
|
||||
maxEnergyCost = amount;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return maxEnergyCost;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +217,18 @@ public class CountersPutAi extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
if ("PayEnergy".equals(sa.getParam("AILogic"))) {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
if ("PayEnergyConservatively".equals(sa.getParam("AILogic"))) {
|
||||
if (ai.getGame().getCombat() != null && sa.getHostCard() != null) {
|
||||
if (ai.getGame().getCombat().isAttacking(sa.getHostCard()) || ai.getGame().getCombat().isBlocking(sa.getHostCard())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (ai.getCounters(CounterType.ENERGY) > ComputerUtilCard.getMaxSAEnergyCostOnBattlefield(ai) + sa.getPayCosts().getCostEnergy().convertAmount()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (sa.getConditions() != null && !sa.getConditions().areMet(sa) && sa.getSubAbility() == null) {
|
||||
|
||||
Reference in New Issue
Block a user