From 30dda88adbf84f7cb8b6a9dded259b4b1468c64f Mon Sep 17 00:00:00 2001 From: tool4EvEr Date: Fri, 29 Apr 2022 18:10:12 +0200 Subject: [PATCH] Clean up --- .../java/forge/ai/AiAttackController.java | 20 ++++++--------- .../java/forge/ai/ComputerUtilCombat.java | 25 ++++++++----------- .../main/java/forge/ai/ComputerUtilCost.java | 2 +- 3 files changed, 20 insertions(+), 27 deletions(-) diff --git a/forge-ai/src/main/java/forge/ai/AiAttackController.java b/forge-ai/src/main/java/forge/ai/AiAttackController.java index 7a08a093c0c..2efa9a2456f 100644 --- a/forge-ai/src/main/java/forge/ai/AiAttackController.java +++ b/forge-ai/src/main/java/forge/ai/AiAttackController.java @@ -572,8 +572,7 @@ public class AiAttackController { if (numExtraBlocks > 0) { // TODO should be limited to how much getBlockCost the opp can pay while (numExtraBlocks-- > 0 && !remainingAttackers.isEmpty()) { - blockedAttackers.add(remainingAttackers.get(0)); - remainingAttackers.remove(0); + blockedAttackers.add(remainingAttackers.remove(0)); maxBlockersAfterCrew--; } } @@ -581,8 +580,7 @@ public class AiAttackController { if (remainingAttackers.isEmpty()) { break; } - blockedAttackers.add(remainingAttackers.get(0)); - remainingAttackers.remove(0); + blockedAttackers.add(remainingAttackers.remove(0)); maxBlockersAfterCrew--; } unblockedAttackers.addAll(remainingAttackers); @@ -605,8 +603,8 @@ public class AiAttackController { final CardCollection unblockableCantPayFor = new CardCollection(); final CardCollection unblockableWithoutCost = new CardCollection(); // TODO also check poison - for (Card attacker : CardLists.getKeyword(unblockedAttackers, Keyword.TRAMPLE)) { - Cost tax = CombatUtil.getAttackCost(attacker.getGame(), attacker, defendingOpponent); + for (Card attacker : unblockedAttackers) { + Cost tax = CombatUtil.getAttackCost(ai.getGame(), attacker, defendingOpponent); if (tax == null) { unblockableWithoutCost.add(attacker); } else { @@ -620,19 +618,17 @@ public class AiAttackController { } } int dmgUnblockableAfterPaying = ComputerUtilCombat.sumDamageIfUnblocked(unblockableWithPaying, defendingOpponent); + unblockedAttackers = unblockableWithoutCost; if (dmgUnblockableAfterPaying > trampleDamage) { - unblockedAttackers.removeAll(unblockableCantPayFor); - unblockedAttackers.removeAll(unblockableWithPaying); + myFreeMana -= unblockableAttackTax; totalCombatDamage = dmgUnblockableAfterPaying; // recalculate the trampler damage with the reduced mana available now - myFreeMana -= unblockableAttackTax; trampleDamage = getDamageFromBlockingTramplers(blockedAttackers, remainingBlockers, myFreeMana).getLeft(); } else { - unblockedAttackers = unblockableWithoutCost; myFreeMana -= tramplerTaxPaid; // find out if we can still pay for some left for (Card attacker : unblockableWithPaying) { - Cost tax = CombatUtil.getAttackCost(attacker.getGame(), attacker, defendingOpponent); + Cost tax = CombatUtil.getAttackCost(ai.getGame(), attacker, defendingOpponent); int taxCMC = tax.getCostMana().getMana().getCMC(); if (myFreeMana < unblockableAttackTax + taxCMC) { continue; @@ -664,7 +660,7 @@ public class AiAttackController { CardCollection remainingBlockers = new CardCollection(blockers); for (Card attacker : CardLists.getKeyword(blockedAttackers, Keyword.TRAMPLE)) { // TODO might sort by quotient of dmg/cost for best combination - Cost tax = CombatUtil.getAttackCost(attacker.getGame(), attacker, defendingOpponent); + Cost tax = CombatUtil.getAttackCost(ai.getGame(), attacker, defendingOpponent); int taxCMC = tax != null ? tax.getCostMana().getMana().getCMC() : 0; if (myFreeMana < currentAttackTax + taxCMC) { continue; diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java index 73094a7d4e6..9c979e25615 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCombat.java @@ -1268,21 +1268,17 @@ public class ComputerUtilCombat { } List list = Lists.newArrayList(); - if (!sa.hasParam("ValidCards")) { - list = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), null); - } - if (sa.hasParam("Defined") && sa.getParam("Defined").startsWith("TriggeredAttacker")) { - list.add(attacker); - } if (sa.hasParam("ValidCards")) { if (attacker.isValid(sa.getParam("ValidCards").split(","), source.getController(), source, null) || attacker.isValid(sa.getParam("ValidCards").replace("attacking+", "").split(","), source.getController(), source, null)) { list.add(attacker); } + } else { + list = AbilityUtils.getDefinedCards(source, sa.getParam("Defined"), null); } - if (list.isEmpty()) { - continue; + if (sa.hasParam("Defined") && sa.getParam("Defined").startsWith("TriggeredAttacker")) { + list.add(attacker); } if (!list.contains(attacker)) { continue; @@ -1464,14 +1460,15 @@ public class ComputerUtilCombat { toughness -= predictDamageTo(attacker, damage, source, false); continue; } else if (ApiType.Pump.equals(sa.getApi())) { + if (!sa.hasParam("NumDef")) { + continue; + } if (sa.hasParam("Cost")) { if (!CostPayment.canPayAdditionalCosts(sa.getPayCosts(), sa)) { continue; } } - if (!sa.hasParam("NumDef")) { - continue; - } + final String defined = sa.getParam("Defined"); CardCollection list = AbilityUtils.getDefinedCards(source, defined, sa); if (defined != null && defined.startsWith("TriggeredAttacker")) { @@ -1497,6 +1494,9 @@ public class ComputerUtilCombat { toughness += AbilityUtils.calculateAmount(source, bonus, sa); } } else if (ApiType.PumpAll.equals(sa.getApi())) { + if (!sa.hasParam("NumDef")) { + continue; + } if (sa.hasParam("Cost")) { if (!CostPayment.canPayAdditionalCosts(sa.getPayCosts(), sa)) { continue; @@ -1506,9 +1506,6 @@ public class ComputerUtilCombat { if (!sa.hasParam("ValidCards")) { continue; } - if (!sa.hasParam("NumDef")) { - continue; - } if (!attacker.isValid(sa.getParam("ValidCards").replace("attacking+", "").split(","), source.getController(), source, sa)) { continue; } diff --git a/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java b/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java index ab113c4a48b..46f379218ce 100644 --- a/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java +++ b/forge-ai/src/main/java/forge/ai/ComputerUtilCost.java @@ -724,7 +724,7 @@ public class ComputerUtilCost { // ward or human misplay if (ApiType.Counter.equals(sa.getApi())) { - List spells = AbilityUtils.getDefinedSpellAbilities(source, sa.hasParam("Defined") ? sa.getParam("Defined") : "Targeted", sa); + List spells = AbilityUtils.getDefinedSpellAbilities(source, sa.getParamOrDefault("Defined", "Targeted"), sa); for (SpellAbility toBeCountered : spells) { if (!CardFactoryUtil.isCounterable(toBeCountered.getHostCard())) { return false;