mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-17 19:28:01 +00:00
Merge branch 'master' into 'master'
Improve logic for grantsUsefulExtraBlockOpts, fix an issue with AI spam-activating pump abilities when low on life. See merge request core-developers/forge!2964
This commit is contained in:
@@ -388,7 +388,7 @@ public class PumpAi extends PumpAiBase {
|
||||
}
|
||||
|
||||
return true;
|
||||
} else if (grantsUsefulExtraBlockOpts(ai, card)) {
|
||||
} else if (grantsUsefulExtraBlockOpts(ai, sa, card, keywords)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ import forge.ai.ComputerUtilCombat;
|
||||
import forge.ai.SpellAbilityAi;
|
||||
import forge.card.MagicColor;
|
||||
import forge.game.Game;
|
||||
import forge.game.ability.AbilityUtils;
|
||||
import forge.game.card.*;
|
||||
import forge.game.combat.Combat;
|
||||
import forge.game.combat.CombatUtil;
|
||||
@@ -37,22 +38,48 @@ public abstract class PumpAiBase extends SpellAbilityAi {
|
||||
}
|
||||
|
||||
|
||||
public boolean grantsUsefulExtraBlockOpts(final Player ai, final Card card) {
|
||||
public boolean grantsUsefulExtraBlockOpts(final Player ai, final SpellAbility sa, final Card card, List<String> keywords) {
|
||||
PhaseHandler ph = ai.getGame().getPhaseHandler();
|
||||
|
||||
Card pumped = ComputerUtilCard.getPumpedCreature(ai, sa, card, 0, 0, keywords);
|
||||
ai.getGame().getAction().checkStaticAbilities(false);
|
||||
|
||||
if (ph.isPlayerTurn(ai) || !ph.getPhase().equals(PhaseType.COMBAT_DECLARE_ATTACKERS)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int canBlockNum = 1 + card.canBlockAdditional();
|
||||
int canBlockNumPumped = canBlockNum; // PumpedCreature doesn't return a meaningful value of canBlockAdditional, so we'll use sa params below
|
||||
|
||||
if (sa.hasParam("CanBlockAny")) {
|
||||
canBlockNumPumped = Integer.MAX_VALUE;
|
||||
} else if (sa.hasParam("CanBlockAmount")) {
|
||||
canBlockNumPumped += AbilityUtils.calculateAmount(pumped, sa.getParam("CanBlockAmount"), sa);
|
||||
}
|
||||
|
||||
int possibleBlockNum = 0;
|
||||
int possibleBlockNumPumped = 0;
|
||||
|
||||
for (Card attacker : ai.getGame().getCombat().getAttackers()) {
|
||||
if (CombatUtil.canBlock(attacker, card)) {
|
||||
possibleBlockNum++;
|
||||
if (possibleBlockNum > canBlockNum) {
|
||||
possibleBlockNum = canBlockNum;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return possibleBlockNum > canBlockNum;
|
||||
for (Card attacker : ai.getGame().getCombat().getAttackers()) {
|
||||
if (CombatUtil.canBlock(attacker, pumped)) {
|
||||
possibleBlockNumPumped++;
|
||||
if (possibleBlockNumPumped > canBlockNumPumped) {
|
||||
possibleBlockNumPumped = canBlockNumPumped;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return possibleBlockNumPumped > possibleBlockNum;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user