Allow flipping around check and try with the ability/skill first.

This commit is contained in:
raeleus 2024-09-22 17:04:58 -07:00
parent 9e7a69087b
commit bfd87c5f90
2 changed files with 27 additions and 1 deletions

View file

@ -141,6 +141,18 @@ const modifier = (text) => {
if (text == null) text = processCommandSynonyms(command, commandName, setAutoXpSynonyms, doSetAutoXp)
if (text == null) text = processCommandSynonyms(command, commandName, showAutoXpSynonyms, doShowAutoXp)
if (text == null) text = processCommandSynonyms(command, commandName, helpSynonyms, doHelp)
if (text == null) {
var character = getCharacter()
var statNames = []
character.stats.forEach(x => {
statNames.push(x.name.toLowerCase())
})
character.skills.forEach(x => {
statNames.push(x.name.toLowerCase())
})
text = processCommandSynonyms(command, commandName, statNames, doTest)
}
return { text }
}
@ -840,6 +852,18 @@ function doRest(command) {
return `\n[All characters have rested and feel rejuvinated]\n`
}
function doTest(command) {
var ability = getCommandName(command)
var arg0 = getArgument(command, 0)
if (arg0 == null) return;
var remainder = getArgumentRemainder(command, 1)
command = `${arg0} ${ability} ${remainder}`
text = processCommandSynonyms(command, arg0, checkSynonyms, doCheck)
if (text == null) text = processCommandSynonyms(command, arg0, trySynonyms, doTry)
return text
}
function doCheck(command) {
const advantageNames = ["normal", "advantage", "disadvantage"]
const difficultyNames = ["impossible", "extreme", "hard", "medium", "easy", "effortless"]

View file

@ -70,7 +70,9 @@ function getArgumentRemainder(command, index) {
const pattern = new RegExp(argumentPattern)
while ((match = pattern.exec(command)) != null) {
if (counter++ == index + 1) {
return command.substring(match.index).replace(/^"/, "").replace(/"$/, "").replaceAll(/\\"/g, '"')
var result = command.substring(match.index)
if (/^".*"$/g.test(result)) result = result.replace(/^"/, "").replace(/"$/, "")
return result.replaceAll(/\\"/g, '"')
}
}
}