I have an item dropping system but i want to be able to give the player more luck
const blocks = [
{
name: "Iron",
ratio: 1 / 2,
},
{
name: "Gold nugget",
ratio: 1 / 4,
},
{
name: "Green Amulet",
ratio: 1 / 10,
},
{
name: "Red Gem",
ratio: 1 / 20,
},
{
name: "Diamond",
ratio: 1 / 100,
}
]
const totalRatio = blocks.reduce((sum, item) => sum + item.ratio, 0);
function rollItem(luckIncreasePercentage = 0) {
const luckboost = (1000 * Math.random());
let roll = Math.random();
let cumulativeChance = 0;
for (let i = 0; i < blocks.length; i++) {
cumulativeChance += blocks[i].ratio / totalRatio;
if (roll <= cumulativeChance) {
return blocks[i];
}
}
}
I want to be able to add a luckboost percent for example 10% more lucky of some sort
i already did something that would do more Math.randoms and take the highest one but i am not satisfied with the solution because if you have a crazy amount of luck it starts to lag out