47 lines
2.3 KiB
Java
47 lines
2.3 KiB
Java
package games.dmg.fantasystick.adventure;
|
|
|
|
import java.util.ArrayList;
|
|
import java.util.List;
|
|
import java.util.Objects;
|
|
import java.util.function.IntSupplier;
|
|
import java.util.function.IntUnaryOperator;
|
|
import org.bukkit.entity.EntityType;
|
|
|
|
/** Fixed weighted monster-camp roster generation with reviewed guarantees and caps. */
|
|
public final class CampRoster {
|
|
private CampRoster() { }
|
|
|
|
public static List<EntityType> roll(int count, java.util.random.RandomGenerator random) {
|
|
Objects.requireNonNull(random);
|
|
return roll(count, () -> random.nextInt(100), random::nextInt);
|
|
}
|
|
|
|
static List<EntityType> roll(int count, IntSupplier percent, IntUnaryOperator shuffleIndex) {
|
|
Objects.requireNonNull(percent); Objects.requireNonNull(shuffleIndex);
|
|
if (count < 4 || count > 64) throw new IllegalArgumentException("Camp enemy count must be 4 through 64");
|
|
int guaranteed = (count + 1) / 2;
|
|
int pillagerCap = count / 2;
|
|
int vindicatorCap = Math.max(1, count / 4);
|
|
int pillagers = 0, vindicators = 0, witches = 0;
|
|
var result = new ArrayList<EntityType>(count);
|
|
for (int index = 0; index < guaranteed; index++) result.add(EntityType.HUSK);
|
|
while (result.size() < count) {
|
|
int roll = percent.getAsInt();
|
|
if (roll < 0 || roll >= 100) throw new IllegalArgumentException("Camp roll must be 0 through 99");
|
|
EntityType selected;
|
|
if (roll < 40) selected = EntityType.HUSK;
|
|
else if (roll < 75 && pillagers < pillagerCap) { selected = EntityType.PILLAGER; pillagers++; }
|
|
else if (roll < 95 && roll >= 75 && vindicators < vindicatorCap) { selected = EntityType.VINDICATOR; vindicators++; }
|
|
else if (roll >= 95 && witches < 1) { selected = EntityType.WITCH; witches++; }
|
|
else selected = EntityType.HUSK;
|
|
result.add(selected);
|
|
}
|
|
for (int index = result.size() - 1; index > 0; index--) {
|
|
int other = shuffleIndex.applyAsInt(index + 1);
|
|
if (other < 0 || other > index) throw new IllegalArgumentException("Invalid shuffle index");
|
|
var value = result.get(index); result.set(index, result.get(other)); result.set(other, value);
|
|
}
|
|
return List.copyOf(result);
|
|
}
|
|
}
|