Implement gacha banners (not newbie)

This commit is contained in:
Melledy
2025-11-01 04:17:44 -07:00
parent e9f991355a
commit 37b74c9b35
20 changed files with 697 additions and 40 deletions

View File

@@ -0,0 +1,35 @@
package emu.nebula.util;
import java.util.NavigableMap;
import java.util.TreeMap;
import java.util.concurrent.ThreadLocalRandom;
public class WeightedList<E> {
private final NavigableMap<Double, E> map = new TreeMap<>();
private double total = 0;
public WeightedList() {
}
public WeightedList<E> add(double weight, E result) {
if (weight <= 0) return this;
total += weight;
map.put(total, result);
return this;
}
public E next() {
double value = ThreadLocalRandom.current().nextDouble() * total;
return map.higherEntry(value).getValue();
}
public int size() {
return map.size();
}
public void clear() {
this.map.clear();
this.total = 0;
}
}