replace rarity calculation due to it breaking at more than two values

This commit is contained in:
Julian Krings authored and Julian Krings committed 2025-09-06 14:21:52 +02:00
1 parent 77842489e5
commit 81b8fb02ae
1 file changed
+26
@@ -69,6 +69,32 @@ public interface IRare {
return null;
}
if (possibilities.size() == 1) {
return possibilities.getFirst();
}
double total = 0;
for (T i : possibilities) {
total += 1d / i.getRarity();
}
double threshold = total * noiseValue;
double buffer = 0;
for (T i : possibilities) {
buffer += 1d / i.getRarity();
if (buffer >= threshold) {
return i;
}
}
return possibilities.getLast();
}
static <T extends IRare> T pickLegacy(List<T> possibilities, double noiseValue) {
if (possibilities.isEmpty()) {
return null;
}
if (possibilities.size() == 1) {
return possibilities.get(0);
}