Fixed being unable to use negative modifiers for #roll

This commit is contained in:
raeleus 2024-10-06 10:22:49 -07:00
parent ca76856c90
commit ff64d9006b
2 changed files with 4 additions and 3 deletions

View file

@ -605,6 +605,7 @@ function doRoll(command) {
if (roll == 20) text += " Critical Success!"
else if (roll == 1) text += " Critical Failure!"
else if (addition > 0) text += ` + ${addition} = ${roll + addition}`
else if (addition < 0) text += ` - ${Math.abs(addition)} = ${roll + addition}`
text += "]\n"
return text

View file

@ -200,16 +200,16 @@ function getSides(rolltext) {
}
function getAddition(rolltext) {
var matches = rolltext.match(/(?<=(\+|-)\s*)\d+/)
var matches = rolltext.match(/(\+|-)\s*\d+/)
if (matches != null) {
return parseInt(matches[0])
return parseInt(matches[0].replaceAll(/\s*/g, ""))
}
return 0
}
function formatRoll(text) {
var matches = text.match(/(?<=.*)\d*d\d+(?=.*)(\s*\+\s*\d+)?/)
var matches = text.match(/(?<=.*)\d*d\d+(?=.*)(\s*(\+|-)\s*\d+)?/)
if (matches != null) {
return matches[0].replaceAll(/\s*\+\s*/g, "+").replaceAll(/\s*-\s*/g, "-")
}