At first look, it seems like it checks for all affixes and try to apply them one by one... but it seems like once it gets 1 affix done, it stops checking the others...
For example:
<affix1 50>
<affix2 50>
<affix3 100>
it checks for affix1 first, if it doesn't get picked it proceeds to affix2, if it doesn't get picked too it proceeds to affix3...
so It's not the same as a lottery ticket chance...
for your problem with the bonus, since it's quite small (5% of 20 is supposedly 1), but the game might be rounding it down to 0 for some reason... try it on higher values of base defense...
@Vlue: I think it's better to let it have multiple affixes... that way you stay true to the rarity being the actual percent of having the affix...
Else you might wanna just change it into an affix pool, where the user adds the possible affixes and their "weight"...
ex:
<affix1 1>
<affix2 2>
So this means to add affix1 once to the pool, and affix2 twice... then you just pick a random affix from that pool... this way we know when we set-up that affix1 has a real 1/3 chance to be picked while affix2 has 2/3 chance...
but doing so, we should also be able to add a "blank" affix so that if we can have the chance of not having an affix
But as you see, working with a pool is more complicated than just allowing multiple affixes to be applied which is just removing the break command from the methods like this one:
break if add_affix(item, $~[1].to_i, false) if rand(100) < $2.to_iso it will be
Code:
add_affix(item, $~[1].to_i, false) if rand(100) < $2.to_i