The problem is because chance[] was an int8, making it's upper limit be 255. Since the pool you are pulling from has three items at 100 chance each, that meant it was trying to set the value to 300, but when you hit 256 it would change to 0. So setting it to 300 made a resultant value of 44.
It does not matter what the sum of the chances are. Only the relative values matter. And chance[index] is going to be the current item chance plus all prior item chances. It is required for the item select code to work properly. Just because the first item will show a 100 chance and the second item will show a 200 chance, it does not mean the second item has twice the chance of being foraged. It just means that when we generate the random number, any values less than or equal to 200 *might* be the second item, but since we check for the first item before the second and any value less than or equal to 100 will return the first, that means the actual range of values that would return the second item is 101-200.
|