function getDamageReduction(creature, damage, damType)
local damageReduction = 0
local armor = creature:getArmor()
local defence = creature:getDefense()
local resistance = creature:getResistance(damType)
if armor > 0 then damageReduction = math.ceil(armor * 0.475) end
if defence > 1 then
if creature:isMonster() then
damageReduction = damageReduction + math.floor(math.random(defence/2, defence))
else
local defenseSkill = creature:getEffectiveSkillLevel(SKILL_SHIELD)
-- defenseFactor is missing from calculations, because seem like I can't get it without source edit
damageReduction = damageReduction + math.ceil(defenseSkill * defence * 0.015 + defence * 0.1) -- * defenseFactor
end
end
if resistance > 0 then damageReduction = damageReduction + percentage(damage, resistance) end
return damageReduction
end