Tier rolling cleanup

This commit is contained in:
Indyuce 2022-05-20 17:42:48 +02:00
parent 116247fd70
commit 13c0469594
4 changed files with 41 additions and 14 deletions

View File

@ -14,6 +14,7 @@ import org.bukkit.block.Chest;
import org.bukkit.configuration.ConfigurationSection; import org.bukkit.configuration.ConfigurationSection;
import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.scheduler.BukkitRunnable;
import org.bukkit.util.Vector; import org.bukkit.util.Vector;
import org.jetbrains.annotations.NotNull;
import java.util.*; import java.util.*;
import java.util.logging.Level; import java.util.logging.Level;
@ -117,25 +118,39 @@ public class LootChestRegion {
MMOCore.plugin.lootChests.register(lootChest); MMOCore.plugin.lootChests.register(lootChest);
} }
/**
* @param player Player rolling the tier
* @return A randomly picked tiers taking into account tier spawn rates
* and the player Chance attribute
*/
@NotNull
public ChestTier rollTier(PlayerData player) { public ChestTier rollTier(PlayerData player) {
double chance = player.getStats().getStat(StatType.CHANCE); double chance = player.getStats().getStat(StatType.CHANCE) * MMOCore.plugin.configManager.lootChestsChanceWeight;
//chance=0 ->the tier.chance remains the same
//chance ->+inf -> the tier.chance becomes the same for everyone, uniform law
//chance=8-> tierChance=sqrt(tierChance)
double sum = 0; double sum = 0;
for (ChestTier tier : tiers) { for (ChestTier tier : tiers)
sum += Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3)); sum += getTierCoefficient(tier.getChance(), chance);
} Validate.isTrue(sum > 0, "No chest tier was found");
double s=0; double cummulated = 0;
for (ChestTier tier : tiers) { for (ChestTier tier : tiers) {
s+=Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3))/sum; cummulated += getTierCoefficient(tier.getChance(), chance);
if (random.nextDouble() < s) if (random.nextDouble() < cummulated / sum)
return tier; return tier;
} }
return tiers.stream().findAny().orElse(null); throw new RuntimeException("Could not roll chest tier");
}
private static final double CHANCE_COEF = 7 / 100;
/**
* - Chance = 0 | tier coefficient is left unchanged.
* - Chance -> +oo | all tier coefficients are the same (1)
* - Chance = 50 | coefficients become their square roots
*/
private double getTierCoefficient(double initialTierChance, double chance) {
return Math.pow(initialTierChance, 1 / Math.pow(1 + CHANCE_COEF * chance, 1 / 3));
} }
public Location getRandomLocation(Location center) { public Location getRandomLocation(Location center) {

View File

@ -15,8 +15,6 @@ public class PermissionCondition extends Condition {
@Override @Override
public boolean isMet(ConditionInstance entity) { public boolean isMet(ConditionInstance entity) {
if (entity.getEntity() instanceof Player) return entity.getEntity() instanceof Player && entity.getEntity().hasPermission(perm);
return entity.getEntity().hasPermission(perm);
return false;
} }
} }

View File

@ -27,6 +27,7 @@ public class ConfigManager {
public String partyChatPrefix, noSkillBoundPlaceholder; public String partyChatPrefix, noSkillBoundPlaceholder;
public ChatColor staminaFull, staminaHalf, staminaEmpty; public ChatColor staminaFull, staminaHalf, staminaEmpty;
public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown;
public double lootChestsChanceWeight;
private final FileConfiguration messages; private final FileConfiguration messages;
private final boolean chatInput; private final boolean chatInput;
@ -97,6 +98,7 @@ public class ConfigManager {
lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L; lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L;
globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50;
noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message();
lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests");
staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN);
staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN);

View File

@ -58,6 +58,18 @@ protect-custom-mine: false
# - parties_and_friends # - parties_and_friends
party-plugin: mmocore party-plugin: mmocore
# MythicLib introduces a CHANCE stat that is used in
# several different systems in MMOCore. By changing these
# weights you can define how much the Chance stat impacts
# the different features implemented by MMOCore
#
# e.g setting some weight to 2 will DOUBLE the effect of
# the chance stat in one particular system. The weights are
# all set to 1 by default, this option is really server specific
chance-stat-weight:
loot-chests: 1
# Whether blocks generated with a "cobblegenerator" should # Whether blocks generated with a "cobblegenerator" should
# provide the player with experience points or not # provide the player with experience points or not
should-cobblestone-generators-give-exp: false should-cobblestone-generators-give-exp: false