Merge pull request #23 from Branleaf/master

My Adventure Mode/Death Detection script
This commit is contained in:
William Unsworth 2021-10-20 21:02:19 -06:00 committed by GitHub
commit 87d1963fa8
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 119 additions and 0 deletions

Binary file not shown.

View file

@ -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)

View file

@ -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)

View file

@ -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)

View file

@ -0,0 +1,23 @@
# 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.
## 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.

View file

@ -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;
}