diff --git a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java index 6e265a3b..8e6afc9a 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java +++ b/src/main/java/net/Indyuce/mmocore/loot/chest/LootChestRegion.java @@ -14,6 +14,7 @@ import org.bukkit.block.Chest; import org.bukkit.configuration.ConfigurationSection; import org.bukkit.scheduler.BukkitRunnable; import org.bukkit.util.Vector; +import org.jetbrains.annotations.NotNull; import java.util.*; import java.util.logging.Level; @@ -117,25 +118,39 @@ public class LootChestRegion { 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) { - 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; - for (ChestTier tier : tiers) { - sum += Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3)); - } + for (ChestTier tier : tiers) + sum += getTierCoefficient(tier.getChance(), chance); + Validate.isTrue(sum > 0, "No chest tier was found"); - double s=0; + double cummulated = 0; for (ChestTier tier : tiers) { - s+=Math.pow(tier.chance, 1 / Math.pow((1 + chance),1/3))/sum; - if (random.nextDouble() < s) + cummulated += getTierCoefficient(tier.getChance(), chance); + if (random.nextDouble() < cummulated / sum) 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) { diff --git a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java index 0d009b44..43967da5 100644 --- a/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java +++ b/src/main/java/net/Indyuce/mmocore/loot/droptable/condition/PermissionCondition.java @@ -15,8 +15,6 @@ public class PermissionCondition extends Condition { @Override public boolean isMet(ConditionInstance entity) { - if (entity.getEntity() instanceof Player) - return entity.getEntity().hasPermission(perm); - return false; + return entity.getEntity() instanceof Player && entity.getEntity().hasPermission(perm); } } diff --git a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java index 96a41f87..bcc54190 100644 --- a/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java +++ b/src/main/java/net/Indyuce/mmocore/manager/ConfigManager.java @@ -27,6 +27,7 @@ public class ConfigManager { public String partyChatPrefix, noSkillBoundPlaceholder; public ChatColor staminaFull, staminaHalf, staminaEmpty; public long combatLogTimer, lootChestExpireTime, lootChestPlayerCooldown, globalSkillCooldown; + public double lootChestsChanceWeight; private final FileConfiguration messages; private final boolean chatInput; @@ -97,6 +98,7 @@ public class ConfigManager { lootChestPlayerCooldown = (long) MMOCore.plugin.getConfig().getDouble("player-cooldown") * 1000L; globalSkillCooldown = MMOCore.plugin.getConfig().getLong("global-skill-cooldown") * 50; noSkillBoundPlaceholder = getSimpleMessage("no-skill-placeholder").message(); + lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests"); staminaFull = getColorOrDefault("stamina-whole", ChatColor.GREEN); staminaHalf = getColorOrDefault("stamina-half", ChatColor.DARK_GREEN); diff --git a/src/main/resources/config.yml b/src/main/resources/config.yml index adce82fd..5611ba68 100644 --- a/src/main/resources/config.yml +++ b/src/main/resources/config.yml @@ -58,6 +58,18 @@ protect-custom-mine: false # - parties_and_friends 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 # provide the player with experience points or not should-cobblestone-generators-give-exp: false