Loot Rarity System
Mornin'
I've been trying to make a system for my game which involves generating random values in a specific way.
But first, a little bit of context. In my game, you can get loot which is found after killing an enemy. Loot can have different rarities (common, uncommon, rare, etc...) with 10 total rarities. I wanted to make it so that the chance of getting a certain rarity is determined by an external number, such as a "Luck Stat". The higher this number is, the higher the chance of getting higher rarities.
With the lowest luck, you would have 100% chance of getting a common item, but as you progress the chance would be split amongst the different rarities.
Does anyone know if there is some way I could implement this? Or will I have to find a workaround?
humm, if the progression of luck is linear, lets try do it
public float[] ratioOfRarity; //array with the rarity percentage of each item class
public float maximiumLuck;
/// <summary>
/// return the index of the rarity class choosed
/// </summary>
/// <param name="LuckStat">Luck stat need to be between 0 and the sum of each rarity percentage.</param>
int Roulette(float LuckStat){
float randr = Random.Range (0f, LuckStat);
int ret = 0;
float Sum = ratioOfRarity[0];//the default case
while (Sum < randr){
ret++;
Sum += ratioOfRarity[ret];
}
return ret;
}
Answer by tormentoarmagedoom · Jan 24, 2019 at 04:46 PM
Good day.
Then you need to make a Random.Range function.
with something like
Random.Range(0,LuckStat);
So, as more luck stat, more higher the number you can get.
Then, simple. If result...
0 to 20 common
20 to 40 uncommon
40 to 60 rare
etc...
Good luck!
Bye!