This is for items with the "charged" mod, I have yet to look at the 3 hitskill mods.
First, if "max" is 0, then it does:
slvl = (X + (ilvl - reqlvl) / 4) + 1Then it checks if the slvl is at least 1, and 20 or less and modifies it according to that (so it will be a value from 1 to 20).
X = 3 if ilvl - reqlvl < 0, else 0
reqlvl is the reqlvl from skills.txt
If "max" is a negative value, it does:
slvl = (ilvl - uselvl) / neg(99 - uselvl / max)Now it only checks if it is at least 1, no upper cap.
99 - uselevel is always at least 1. It also makes sure that neg(99...) is at least 1 before the division.
uselvl is the highest of reqlvl from skills.txt and level from affix.txt.
After it calculates slvl, it gets number of charges:
num_charges = (neg(min) * slvl) / 8 + neg(min)min is just the value from min column in affix.txt. num_charges is then capped at 255. It then calculates the charges left when spawned:
spawn_charges = 1 + (num_charges / 8) + rnd[num_charges - (num_charges / 8)]