Little modifications to the chance system. Potential fix of a bug about fishing drop tables.

This commit is contained in:
Ka0rX 2022-10-29 06:20:52 +02:00
parent 5cf1505a8d
commit 2adca395c0
4 changed files with 8 additions and 5 deletions

View File

@ -17,6 +17,7 @@ public class RandomWeightedRoll<T extends Weighted> {
private final T rolled; private final T rolled;
private static final Random RANDOM = new Random(); private static final Random RANDOM = new Random();
private static final double CHANCE_COEFFICIENT = 7. / 100;
public RandomWeightedRoll(PlayerData player, Collection<T> collection, double chanceWeight) { public RandomWeightedRoll(PlayerData player, Collection<T> collection, double chanceWeight) {
this.collection = collection; this.collection = collection;
@ -26,13 +27,13 @@ public class RandomWeightedRoll<T extends Weighted> {
for (T item : collection) { for (T item : collection) {
partialSum += computeRealWeight(item, chance); partialSum += computeRealWeight(item, chance);
if (partialSum > randomCoefficient * sum) { if (partialSum >= randomCoefficient * sum) {
rolled = item; rolled = item;
return; return;
} }
} }
throw new RuntimeException("Could not roll item"); throw new RuntimeException("Could not roll item, the chance is :"+chance);
} }
/** /**
@ -53,7 +54,6 @@ public class RandomWeightedRoll<T extends Weighted> {
return sum; return sum;
} }
private static final double CHANCE_COEFFICIENT = 7. / 100;
/** /**
* chance = 0 | tier chances are unchanged * chance = 0 | tier chances are unchanged

View File

@ -1,6 +1,7 @@
package net.Indyuce.mmocore.loot.droptable.dropitem; package net.Indyuce.mmocore.loot.droptable.dropitem;
import io.lumine.mythic.lib.api.MMOLineConfig; import io.lumine.mythic.lib.api.MMOLineConfig;
import net.Indyuce.mmocore.MMOCore;
import net.Indyuce.mmocore.api.player.PlayerData; import net.Indyuce.mmocore.api.player.PlayerData;
import net.Indyuce.mmocore.api.util.math.formula.RandomAmount; import net.Indyuce.mmocore.api.util.math.formula.RandomAmount;
import net.Indyuce.mmocore.loot.LootBuilder; import net.Indyuce.mmocore.loot.LootBuilder;
@ -46,7 +47,7 @@ public abstract class DropItem {
*/ */
public boolean rollChance(PlayerData player) { public boolean rollChance(PlayerData player) {
double value = random.nextDouble(); double value = random.nextDouble();
return value < Math.pow(chance, 1 / Math.pow(1 + CHANCE_COEFFICIENT * player.getStats().getStat("CHANCE"), 1.0 / 3.0)); return value < Math.pow(chance, 1 / Math.pow(1 + CHANCE_COEFFICIENT * MMOCore.plugin.configManager.dropItemsChanceWeight* player.getStats().getStat("CHANCE"), 1.0 / 3.0));
} }
public abstract void collect(LootBuilder builder); public abstract void collect(LootBuilder builder);

View File

@ -26,7 +26,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, fishingDropsChanceWeight, partyMaxExpSplitRange; public double lootChestsChanceWeight,dropItemsChanceWeight, fishingDropsChanceWeight, partyMaxExpSplitRange;
public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills, waypointWarpTime; public int maxPartyLevelDifference, maxBoundActiveSkills, maxBoundPassiveSkills, waypointWarpTime;
private final FileConfiguration messages; private final FileConfiguration messages;
@ -111,6 +111,7 @@ public class ConfigManager {
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"); lootChestsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.loot-chests");
dropItemsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.drop-items");
fishingDropsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.fishing-drops"); fishingDropsChanceWeight = MMOCore.plugin.getConfig().getDouble("chance-stat-weight.fishing-drops");
maxPartyLevelDifference = MMOCore.plugin.getConfig().getInt("party.max-level-difference"); maxPartyLevelDifference = MMOCore.plugin.getConfig().getInt("party.max-level-difference");
partyMaxExpSplitRange = MMOCore.plugin.getConfig().getDouble("party.max-exp-split-range"); partyMaxExpSplitRange = MMOCore.plugin.getConfig().getDouble("party.max-exp-split-range");

View File

@ -79,6 +79,7 @@ guild-plugin: mmocore
chance-stat-weight: chance-stat-weight:
loot-chests: 1 loot-chests: 1
fishing-drops: 1 fishing-drops: 1
drop-items: 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