Currently, I'm developing a unique job system within a Discord bot that allows users to mine various types of ores. The probability of receiving specific ores is based on the user's mining skill level, which is stored in a database and can vary accordingly. For example, at Skill Level 1, the chances are as follows:
let coal_chance = 80
let copper_chance = 15
let iron_chance = 5
let gold_chance = 0
let diamond_chance = 0
let emerald_chance = 0
Conversely, at Skill Level 2, the distribution changes:
let coal_chance = 50
let copper_chance = 35
let iron_chance = 10
let gold_chance = 5
let diamond_chance = 0
let emerald_chance = 0
This pattern continues for higher skill levels. However, my current dilemma lies in creating a dynamic chance system based on these percentages.
I initially attempted to implement a solution using Math.Random()
alongside a series of if statements. Unfortunately, this approach proved inefficient since it required separate conditionals for each skill level. Furthermore, any adjustments made to the ore probabilities within the database would necessitate corresponding alterations to the codebase.