make recursive selection less recursive

This commit is contained in:
jascotty2 2019-09-16 09:13:11 -05:00
parent 98525b9367
commit 4be7e3c50b

View File

@ -290,14 +290,15 @@ public class Kit {
if (amt != amtToGive || kitAnimation != KitAnimation.NONE)
Collections.shuffle(innerContents);
return generateRandomItem(innerContents, amtToGive, player);
return generateRandomItem(innerContents, amtToGive, player, -1);
}
private boolean generateRandomItem(List<KitItem> innerContents, int amtToGive, Player player) {
private boolean generateRandomItem(List<KitItem> innerContents, int amtToGive, Player player, int forceSelect) {
boolean chosenItem = false;
int canChoose = 0;
for (KitItem item : innerContents) {
if (amtToGive == 0) continue;
int ch = item.getChance() == 0 ? 100 : item.getChance();
int ch = canChoose++ == forceSelect || item.getChance() == 0 ? 100 : item.getChance();
double rand = Math.random() * 100;
if (rand - ch < 0 || ch == 100) {
chosenItem = true;
@ -352,7 +353,7 @@ public class Kit {
}
}
if (!chosenItem) generateRandomItem(innerContents, amtToGive, player);
if (!chosenItem) generateRandomItem(innerContents, amtToGive, player, (int) (Math.random() * canChoose));
player.updateInventory();
return true;