From b3cee885bf9bcfbb1f4dd52f0ad8d6c7565dfeb6 Mon Sep 17 00:00:00 2001 From: Branleaf <78628663+Branleaf@users.noreply.github.com> Date: Thu, 21 Oct 2021 03:36:06 +0100 Subject: [PATCH 1/2] Adding my Adventure Mode/Death Detection script Includes a readme, a zip file containing all four scripts as well as the four scripts seperately for easy viewing --- contributed/adventure mode/adventure mode.zip | Bin 0 -> 2192 bytes contributed/adventure mode/contextModifier.js | 20 ++++++++++++ contributed/adventure mode/inputModifier.js | 23 ++++++++++++++ contributed/adventure mode/outputModifier.js | 23 ++++++++++++++ contributed/adventure mode/readme.md | 14 ++++++++ contributed/adventure mode/shared.js | 30 ++++++++++++++++++ 6 files changed, 110 insertions(+) create mode 100644 contributed/adventure mode/adventure mode.zip create mode 100644 contributed/adventure mode/contextModifier.js create mode 100644 contributed/adventure mode/inputModifier.js create mode 100644 contributed/adventure mode/outputModifier.js create mode 100644 contributed/adventure mode/readme.md create mode 100644 contributed/adventure mode/shared.js diff --git a/contributed/adventure mode/adventure mode.zip b/contributed/adventure mode/adventure mode.zip new file mode 100644 index 0000000000000000000000000000000000000000..3b175c96b9d5ca13d9c1a014a9d647dd03e7679f GIT binary patch literal 2192 zcmaKtc|6oxAIE?8>8ht;@EA*WqianlTh=j_W-yotQH&@?#%PdS`xavz+gw{|liee? zizp$Kt%jh$?N%pp69veyk6(L&N;8wdB0wt&-s3ioedYa5C8xm;1$%# zVRw9c(SQR0Bsc*;kiF{_h$CP_3CKWiKOa9VUhPV-lYJ|yLjyd`5-O?B$jM?jUR(zB z`R@pOKx|fZ*KBPZ*Qa!w?Wg;DN=$3A2&-VZq$&^|UzFy~+ zH{Yel`e@J<*$-3?wTl>7O#fVpHYU#?r$4;M;X+KxFi^L;{0h%AW=!Nk)`PbOTodL) z1$n#f(r6-g&}|r}887D755?EW-C#0&(|Okdha1@DvOA!)9G>yYgRONqTWc^|Yd_qz zkONAiO>nUq;Fcv}Wt2R!r&YjkeQ^55hoN^zobmqNHE&9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D(8u4 z163}sMq9gM(pL@*&O%?CHYbgVPB3fB&95`>p+G(tG3o`UQXa z&lv|G3OuhVb(85D<#-OmCH$Cyl+n+k?D=QL!Mxwk@Mj0l&*{IP0F;#M5ehNzsJ|l| z46*%$O?DOiSETJnTrViwLr`x1J>py=4SUe KwgO-FR{sY7POsts literal 0 HcmV?d00001 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 From d25b0a4e7e90d375e7696bbc2e370d064afa72be Mon Sep 17 00:00:00 2001 From: Branleaf <78628663+Branleaf@users.noreply.github.com> Date: Thu, 21 Oct 2021 03:42:43 +0100 Subject: [PATCH 2/2] Added MIT license --- contributed/adventure mode/readme.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/contributed/adventure mode/readme.md b/contributed/adventure mode/readme.md index 833e738..c9cf52a 100644 --- a/contributed/adventure mode/readme.md +++ b/contributed/adventure mode/readme.md @@ -11,4 +11,13 @@ I copied over the regex from the original AI Dungeon Colab's death detection cod 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 +You don't need to extract it- the modifier tabs should be filled in with the right scripts from the zip folder automatically. + +## MIT License +Copyright 2021 + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.