我想在此代码中添加一个随机修饰符,该修饰符将根据基础值的 +-20% 范围增加或减少伤害。伤害会在结果的 80% 到结果的 120% 之间随机化。对于数字示例:
攻击者.力量(20) - 防御者.防御(10) = 结果
20 - 10 = 范围(8 到 12)
var Fight = function (attacker, defender) {
var result;
result = (attacker.Strength - defender.Defense);
defender.HP = defender.HP - result;
if(defender.HP >= 1) {
return defender.Name + " has taken " + result + " damage!";
} else {
return defender.Name + " has been slain";
}
};