わたしのはこんな感じ

//物理ダメージ
damage = defense - creature.attack * (creature.att_cut * def_cut + creature.att_stab * def_stab + creature.att_strike * def_strike);
if (damage >= 0) { //物理ダメージが回復値なら0
damage = 0;
}
//魔法ダメージ
damage_m = - creature.attack_m * (creature.att_poison * def_poison +
creature.att_fire * def_fire + creature.att_wind * def_wind + creature.att_earth * def_earth +
creature.att_water * def_water + creature.att_light * def_light + creature.att_dark * def_dark +
creature.att_holy * def_holy + creature.att_death * def_death);

if (damage_m < 0) { //マイナスなら魔法防御計算(プラスなら防御0で回復値を加算)
damage_m += defense_m;
if (damage_m > 0) { //防御でプラスになったら0
damage_m = 0;
}
}
//ダメージ合計
damage += damage_m;
//random
damage *= (1 + 0.5 * Math.random());