I'm testing here and it seems to be working fine
this AR calculation is too weird, every layer have its own % usage of item ARMOR value
Code:
layer_helm = 15%
layer_collar = 7%
layer_shirt, layer_chest, layer_tunic, layer_cape, layer_robe = 0%
layer_shirt, layer_chest, layer_tunic, layer_robe = 35%
layer_arms, layer_cape, layer_robe = 14%
layer_gloves = 7%
layer_pants, layer_half_apron, layer_robe, layer_skirt, layer_legs = 22%
layer_shoes, layer_legs = 0%
PS: note that many layers are repeated, and if you have an item equipped on these layers, sphere will stack both values if you have COMBAT_STACKARMOR enabled on sphere.ini it will stack both values, otherwise it will consider only the higher value
so if you have an chest + head armor items with ARMOR=20 both, the chest armor will add +7 AR on char (35% of 20 = 7) and the head layer will add +3 AR (15% of 20 = 3). Basically the calculation is so weird that you'll never know the real AR value that these items will increase when equip on char
but anyway, the magic bonus calculation is based on s_enchant spell on your sphere_spells.scp. This spell have an range value that probably will be 1,9 on your script. The item MOREY also have a range of 0,1000 which is the % (0% to 100%) that it will take from spell range
lets suppose that you have an random t_armor item with ARMOR=20. If you set attr_magic + MOREY, the bonus will be:
MOREY=0 -> 0% of range 1,9 -> +1 (final result = 20 + 1 = 21)
MOREY=500 -> 50.0% of range 1,9 -> +4.5 -> +4 (final result = 20 + 4 = 24)
MOREY=1000 -> 100.0% of range 1,9 -> +9 (final result = 20 + 9 = 29)
but don't forget that this is only the bonus calculation to get the item ARMOR value. After get this value, it will be decreased because the layer % distribution on char