From b32d45f1f46a11abaaafad19d36a4d886da9c9bd Mon Sep 17 00:00:00 2001 From: Agetian Date: Fri, 15 Apr 2016 12:23:37 +0000 Subject: [PATCH] - Attempting to fix an issue where the AI distributed twice the allowed number of counters for any card that said "Distribute N counters among any number of creatures you control" (Armament Corps, Blessings of Nature etc.). The math is a bit dodgy here, please review and update if necessary and possible. --- .../src/main/java/forge/ai/ability/CountersPutAi.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) 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 39a7ac3c9cf..433a1527a28 100644 --- a/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java +++ b/forge-ai/src/main/java/forge/ai/ability/CountersPutAi.java @@ -436,6 +436,7 @@ public class CountersPutAi extends SpellAbilityAi { final String amountStr = sa.getParam("CounterNum"); final boolean divided = sa.hasParam("DividedAsYouChoose"); final int amount = AbilityUtils.calculateAmount(sa.getHostCard(), amountStr, sa); + int left = amount; if (abTgt == null) { // No target. So must be defined @@ -455,6 +456,8 @@ public class CountersPutAi extends SpellAbilityAi { list = CardLists.getTargetableCards(player.getCardsIn(ZoneType.Battlefield), sa); list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source); + int totalTargets = list.size(); + while (sa.getTargets().getNumTargeted() < abTgt.getMaxTargets(sa.getHostCard(), sa)) { if (mandatory) { // When things are mandatory, gotta handle a little differently @@ -507,7 +510,13 @@ public class CountersPutAi extends SpellAbilityAi { } } if (choice != null && divided) { - abTgt.addDividedAllocation(choice, amount); + int alloc = Math.max(amount / totalTargets, 1); + if (sa.getTargets().getNumTargeted() == Math.min(totalTargets, abTgt.getMaxTargets(sa.getHostCard(), sa)) - 1) { + abTgt.addDividedAllocation(choice, left); + } else { + abTgt.addDividedAllocation(choice, alloc); + left -= alloc; + } } }