Hi guys,
i have a system with weapon upgrades in the game where the equipped weapon gets upgraded if you pick up the same weapon again.
I want to make the possibility of spawning the same weapon from the pickup a bit higher, so, for example, if i have a sword equipped and there's a loot box, which can contain one item of 10 random items (10% chance for every weapon) and i ramp up the weight for sword by 20%, there will be 30% possibility to spawn a sword and 7,77% possibility of spawning something else.
I have a bit inefficient system, so i'd like some ideas how to improve it. Currently, i get the name of the equipped weapon and do 20 string switches. When i get a match, i raise the matched weapon's weight a bit. The thing is, i also need to lower the other weapons' weights and then reset everything after the spawn, which is tedious.
Also, i don't quite get the concept of weighted index, if one item weight is 0.6, and other is 0.8, which is 1.4 altogether, what is the actual chance of those being selected? Should i have a 0.05 weight for every item if i want 5% chance of spawning it? And what when i put a new item, do i have to recalculate the weight for all items again?