lipefl / swade-tools

A Fondry VTT module with automations for Savage Worlds (SWADE)
15 stars 13 forks source link

1d1 strenth cause Maximum recursion depth for exploding dice roll exceeded #290

Closed EternalRider closed 5 months ago

EternalRider commented 6 months ago

image

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.

EternalRider commented 6 months ago

another thing: swpf has a ability : All-Around Vision it can -1 gangup bonus, it's easy to add.

lipefl commented 5 months ago

Added both in v1.15.0 Thanks!