Fix division by zero error in PossibleTargetSelector.

This commit is contained in:
Myrd
2016-01-01 22:06:13 +00:00
parent 0b95d357d3
commit b189fd5ff9

View File

@@ -40,15 +40,17 @@ public class PossibleTargetSelector {
// Divide up counters, since AI is expected to do this. For now, // Divide up counters, since AI is expected to do this. For now,
// divided evenly with left-overs going to the first target. // divided evenly with left-overs going to the first target.
if (sa.hasParam("DividedAsYouChoose")) { if (sa.hasParam("DividedAsYouChoose")) {
final String amountStr = sa.getParam("CounterNum");
final int amount = AbilityUtils.calculateAmount(sa.getHostCard(), amountStr, sa);
final int targetCount = sa.getTargets().getTargetCards().size(); final int targetCount = sa.getTargets().getTargetCards().size();
final int amountPerCard = amount / sa.getTargets().getTargetCards().size(); if (targetCount > 0) {
int amountLeftOver = amount - (amountPerCard * targetCount); final String amountStr = sa.getParam("CounterNum");
final TargetRestrictions tgtRes = sa.getTargetRestrictions(); final int amount = AbilityUtils.calculateAmount(sa.getHostCard(), amountStr, sa);
for (GameObject target : sa.getTargets().getTargets()) { final int amountPerCard = amount / targetCount;
tgtRes.addDividedAllocation(target, amountPerCard + amountLeftOver); int amountLeftOver = amount - (amountPerCard * targetCount);
amountLeftOver = 0; final TargetRestrictions tgtRes = sa.getTargetRestrictions();
for (GameObject target : sa.getTargets().getTargets()) {
tgtRes.addDividedAllocation(target, amountPerCard + amountLeftOver);
amountLeftOver = 0;
}
} }
} }