- 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.

This commit is contained in:
Agetian
2016-04-15 12:23:37 +00:00
parent 6190580390
commit b32d45f1f4

View File

@@ -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;
}
}
}