mirror of
https://gitlab.com/phoenix-dvpmt/mmocore.git
synced 2024-11-24 00:15:16 +01:00
Fixed chest tier chance rolling
This commit is contained in:
parent
9a315e9431
commit
93377b6027
@ -10,8 +10,7 @@ public class ChestTier {
|
||||
private final TierEffect effect;
|
||||
private final ScalingFormula capacity;
|
||||
private final DropTable table;
|
||||
|
||||
public final double chance;
|
||||
private final double chance;
|
||||
|
||||
public ChestTier(ConfigurationSection config) {
|
||||
effect = config.isConfigurationSection("effect") ? new TierEffect(config.getConfigurationSection("effect")) : null;
|
||||
@ -24,6 +23,10 @@ public class ChestTier {
|
||||
return capacity.calculate(player.getLevel());
|
||||
}
|
||||
|
||||
public double getChance() {
|
||||
return chance;
|
||||
}
|
||||
|
||||
public DropTable getDropTable() {
|
||||
return table;
|
||||
}
|
||||
|
@ -119,14 +119,19 @@ public class LootChestRegion {
|
||||
// TODO stat to increase chance to get higher tiers?
|
||||
public ChestTier rollTier() {
|
||||
|
||||
double s = 0;
|
||||
for (ChestTier tier : tiers) {
|
||||
if (random.nextDouble() < tier.chance / (1 - s))
|
||||
return tier;
|
||||
s += tier.chance;
|
||||
}
|
||||
// Calculate sum of all chances and then normalize
|
||||
double norm = 0;
|
||||
for (ChestTier tier : tiers)
|
||||
norm += tier.getChance();
|
||||
|
||||
return tiers.stream().findAny().orElse(null);
|
||||
Validate.isTrue(norm > 0, "No tier was found");
|
||||
|
||||
double sum = 0;
|
||||
for (ChestTier tier : tiers)
|
||||
if (random.nextDouble() < (sum += tier.getChance()) / norm)
|
||||
return tier;
|
||||
|
||||
throw new RuntimeException("Could not roll random chest tier");
|
||||
}
|
||||
|
||||
public Location getRandomLocation(Location center) {
|
||||
|
Loading…
Reference in New Issue
Block a user