diff --git a/contributed/adventure mode/adventure mode.zip b/contributed/adventure mode/adventure mode.zip new file mode 100644 index 0000000..3b175c9 Binary files /dev/null and b/contributed/adventure mode/adventure mode.zip differ diff --git a/contributed/adventure mode/contextModifier.js b/contributed/adventure mode/contextModifier.js new file mode 100644 index 0000000..e13e022 --- /dev/null +++ b/contributed/adventure mode/contextModifier.js @@ -0,0 +1,20 @@ +const modifier = (text) => { + console.log("Input: " + text) + /* + history text needs placing in a seperate var + to the actual history list, as history is read-only. + */ + let hist = concatenateHistoryText(history); + " " + text; + stop = playerDied(hist); + //copied from input modifier, prevent new generation with stop=true + if (stop) { + text = null; + state.message = "You have died and your adventure is at an end."; + } else { + delete state.message; + } + return { text, stop } +} + +// Don't modify this part +modifier(text) diff --git a/contributed/adventure mode/inputModifier.js b/contributed/adventure mode/inputModifier.js new file mode 100644 index 0000000..b4076fa --- /dev/null +++ b/contributed/adventure mode/inputModifier.js @@ -0,0 +1,23 @@ +const modifier = (text) => { + console.log("Input: " + text) + /* + history text needs placing in a seperate var + to the actual history list, as history is read-only. + */ + let hist = concatenateHistoryText(history); + let stop = playerDied(hist); + if (stop) { + /* + prevent the input from generating text with stop=true and + stops it from being added to context by setting it to null + */ + text = null; + //puts this message above the action buttons and textbox + state.message = "You have died and your adventure is at an end."; + } else { + delete state.message; + } + return { text, stop } +} + +modifier(text) diff --git a/contributed/adventure mode/outputModifier.js b/contributed/adventure mode/outputModifier.js new file mode 100644 index 0000000..c3d7c87 --- /dev/null +++ b/contributed/adventure mode/outputModifier.js @@ -0,0 +1,23 @@ +const modifier = (text) => { + /* + history text needs placing in a seperate var + to the actual history list, as history is read-only. + */ + let hist = concatenateHistoryText(history) + " " + text; + dead = playerDied(hist); + if (dead) { + /* + shows a death message above action icons and + adds the classic line to the end of output + */ + state.message = "- You have died! -"; + text += "\n- YOU DIED! GAME OVER! -"; + } else { + delete state.message; + } + // You must return an object with the text property defined. + return { text } +} + +// Don't modify this part +modifier(text) diff --git a/contributed/adventure mode/readme.md b/contributed/adventure mode/readme.md new file mode 100644 index 0000000..833e738 --- /dev/null +++ b/contributed/adventure mode/readme.md @@ -0,0 +1,14 @@ +# Death Detection + +Basically what it says in the title- as Adventure Mode is expecting to be removed soon, I wanted to use scripting to emulate it, along with re-adding the classic "- YOU DIED! GAME OVER! -" line that shows up after you die. Unfortunately, I cannot disable action buttons with this, but you can do that yourself fairly easily through the settings screen in-app. + +## What it does + +I copied over the regex from the original AI Dungeon Colab's death detection code, tweaked it to work in JavaScript (The original is written in Python) and set up some code to check the story history for instances of phrases like "You die" or "You have been slain". Should this happen, the output gets the aforementioned death message line added to the bottom and inputs and continues stop being accepted. Of course, you can always revert/undo/alter out of this. + +## How to use in a scenario + +1. Download the .zip file in this directory and navigate to the scripting page on the scenario you want to add this to. +2. Click the upload button in the top right (has an arrow pointing up from a rectangle that looks like a computer or hard drive) and choose the zip file. +3. Make sure that all four tabs on the scripting page have the right code, and you're done. +You don't need to extract it- the modifier tabs should be filled in with the right scripts from the zip folder automatically. \ No newline at end of file diff --git a/contributed/adventure mode/shared.js b/contributed/adventure mode/shared.js new file mode 100644 index 0000000..944ae8c --- /dev/null +++ b/contributed/adventure mode/shared.js @@ -0,0 +1,30 @@ +/* +lumps story history all into one big string for +the playerDied() function's regex to search. +*/ +function concatenateHistoryText(history) { + let histText = ""; + + for (l of history) { + if (l.type == "story" || l.type == "continue") { + histText += " " + l.text + } + } + console.log("History: " + histText); + return histText; +} + +/* + the regex was copied from the OG ai dungeon colab repo + and touched up to work in JS. not as effective as a + classifier, but it should still work fine! + */ +function playerDied(hist) { + + const dead_regex = new RegExp(/you('re| are) (dead|killed|slain|no more|nonexistent)|you (die|pass away|perish|suffocate|drown|bleed out)|you('ve| have) (died|perished|suffocated|drowned|been (killed|slain))|you (\w* )?(yourself )?to death|you (\w* )*(collapse|bleed out|chok(e|ed|ing)|drown|dissolve) (\w* )*and (die(|d)|pass away|cease to exist|(\w* )+killed)/g, "i"); + let isDead = false; + //check history for "you died" regex phrases. + let loweredHist = hist.toLowerCase(); + isDead = dead_regex.test(hist); + return isDead; +} \ No newline at end of file