Closed EternalRider closed 5 months ago
1d1 always is 1, but 1 will explode in 1d1x same problem at 1d0x.
fix:
/** * 爆炸所有骰子:这个函数的作用是将武器伤害字符串中的所有骰子部分后面加上爆炸符号"x"。 * 例如,对于输入"3d6+2d8=12",将返回"3d6x+2d8x=12"。 * @param {string} weaponDamage - 表示武器伤害的字符串,可以包含数字、字母"d"以及加减运算符等。 * @returns {string} 修改后的武器伤害字符串,其中所有骰子部分后面都加上了"x"符号。 */ export function explodeAllDice(weaponDamage) { // 定义用于匹配骰子部分的正则表达式(格式为"d数字",其中数字为1到2位) let regexDiceExplode = /d(?!0|1$)[0-9]{1,2}/g; // 移除字符串中已有的"x"和"="符号 weaponDamage = weaponDamage.replace(/x|=/g, ''); // 在匹配到的骰子部分后面加上"x"符号 weaponDamage = weaponDamage.replace(regexDiceExplode, "$&x"); // 为1d1和1d0的骰子部分移除"x"符号 let noExplode = /(d[0-1])(x)/g; weaponDamage = weaponDamage.replace(noExplode, "$1"); return weaponDamage; }
add let noExplode = /(d[0-1])(x)/g; and replace again.
let noExplode = /(d[0-1])(x)/g;
another thing: swpf has a ability : All-Around Vision it can -1 gangup bonus, it's easy to add.
Added both in v1.15.0 Thanks!
1d1 always is 1, but 1 will explode in 1d1x same problem at 1d0x.
fix:
add
let noExplode = /(d[0-1])(x)/g;
and replace again.