diff --git a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java index 8499e2921de..460835e73e5 100644 --- a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java @@ -311,13 +311,20 @@ public class CountersPutAi extends SpellAbilityAi { return false; } - if (sa.hasParam("Adapt") && source.getCounters(CounterType.P1P1) > 0) { - return false; - } - // TODO handle proper calculation of X values based on Cost int amount = AbilityUtils.calculateAmount(source, amountStr, sa); + if (sa.hasParam("Adapt")) { + Game game = ai.getGame(); + Combat combat = game.getCombat(); + + if (source.getCounters(CounterType.P1P1) > 0) { + return false; + } else if (combat != null && ph.is(PhaseType.COMBAT_DECLARE_BLOCKERS)) { + return doCombatAdaptLogic(source, amount, combat); + } + } + if ("Fight".equals(logic)) { int nPump = 0; if (type.equals("P1P1")) { @@ -1049,4 +1056,40 @@ public class CountersPutAi extends SpellAbilityAi { return false; } + private boolean doCombatAdaptLogic(Card source, int amount, Combat combat) { + // TODO: predict "can't have counters placed on it" type of effects here? + if (combat.isAttacking(source)) { + if (!combat.isBlocked(source)) { + return true; + } else { + for (Card blockedBy : combat.getBlockers(source)) { + if (blockedBy.getNetToughness() > source.getNetPower() + && blockedBy.getNetToughness() <= source.getNetPower() + amount) { + return true; + } + } + + int totBlkPower = Aggregates.sum(combat.getBlockers(source), CardPredicates.Accessors.fnGetNetPower); + if (source.getNetToughness() <= totBlkPower + && source.getNetToughness() + amount > totBlkPower) { + return true; + } + } + } else if (combat.isBlocking(source)) { + for (Card blocked : combat.getAttackersBlockedBy(source)) { + if (blocked.getNetToughness() > source.getNetPower() + && blocked.getNetToughness() <= source.getNetPower() + amount) { + return true; + } + } + + int totAtkPower = Aggregates.sum(combat.getAttackersBlockedBy(source), CardPredicates.Accessors.fnGetNetPower); + if (source.getNetToughness() <= totAtkPower + && source.getNetToughness() + amount > totAtkPower) { + return true; + } + } + return false; + } + }