Here's the to-hit part of it with power generally = 40 for physical/elemental melee and = 0 for status effects melee.
Code:
/* Calculate the "attack quality" */
chance = (power + (level * 3));
/* Power competes against armor */
return randint0(chance) >= (ac * 2 / 3);
% Damage reduction is something like AC / 400 against physical attacks, maxing out at 240 AC. However a lot of damage is non-physical.
It's not that simple to calculate out unfortunately.