I am not 100% sure I implemented the combat formula correctly because I based it on certain observations, but 3 magic, for example, is essentially the same as having 2 attack and 1 strength or 1 attack and 2 strength, and I know for sure those stats don't make you level 4.
I don't know if this will make any sense to you, but here's what my code looks like for the calculations:
$style = [
"melee" => $att + $str,
"mage" => $mag,
"ranger" => $rng
];
$level = 0.25 * (1.3 * max($style) + $def + $hp + floor(0.5*$pray) + floor(0.5*$sum));
$level = floor($level);
The "max" function takes the highest value from the $style array and the "floor" function rounds the value down to an integer