mirror of
https://github.com/Card-Forge/forge.git
synced 2025-11-16 10:48:00 +00:00
- 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:
@@ -436,6 +436,7 @@ public class CountersPutAi extends SpellAbilityAi {
|
|||||||
final String amountStr = sa.getParam("CounterNum");
|
final String amountStr = sa.getParam("CounterNum");
|
||||||
final boolean divided = sa.hasParam("DividedAsYouChoose");
|
final boolean divided = sa.hasParam("DividedAsYouChoose");
|
||||||
final int amount = AbilityUtils.calculateAmount(sa.getHostCard(), amountStr, sa);
|
final int amount = AbilityUtils.calculateAmount(sa.getHostCard(), amountStr, sa);
|
||||||
|
int left = amount;
|
||||||
|
|
||||||
if (abTgt == null) {
|
if (abTgt == null) {
|
||||||
// No target. So must be defined
|
// 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.getTargetableCards(player.getCardsIn(ZoneType.Battlefield), sa);
|
||||||
list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source);
|
list = CardLists.getValidCards(list, abTgt.getValidTgts(), source.getController(), source);
|
||||||
|
|
||||||
|
int totalTargets = list.size();
|
||||||
|
|
||||||
while (sa.getTargets().getNumTargeted() < abTgt.getMaxTargets(sa.getHostCard(), sa)) {
|
while (sa.getTargets().getNumTargeted() < abTgt.getMaxTargets(sa.getHostCard(), sa)) {
|
||||||
if (mandatory) {
|
if (mandatory) {
|
||||||
// When things are mandatory, gotta handle a little differently
|
// When things are mandatory, gotta handle a little differently
|
||||||
@@ -507,7 +510,13 @@ public class CountersPutAi extends SpellAbilityAi {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (choice != null && divided) {
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user