From bfd87c5f90dcb7b21923624e0c92acddb497010e Mon Sep 17 00:00:00 2001 From: raeleus Date: Sun, 22 Sep 2024 17:04:58 -0700 Subject: [PATCH] Allow flipping around check and try with the ability/skill first. --- Input.js | 24 ++++++++++++++++++++++++ Library.js | 4 +++- 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/Input.js b/Input.js index eb14d70..0dcea82 100644 --- a/Input.js +++ b/Input.js @@ -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"] diff --git a/Library.js b/Library.js index f7fcdbc..afb4f8d 100644 --- a/Library.js +++ b/Library.js @@ -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, '"') } } }