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
This commit is contained in:
parent
a9e1c892e2
commit
b3cee885bf
6 changed files with 110 additions and 0 deletions
BIN
contributed/adventure mode/adventure mode.zip
Normal file
BIN
contributed/adventure mode/adventure mode.zip
Normal file
Binary file not shown.
20
contributed/adventure mode/contextModifier.js
Normal file
20
contributed/adventure mode/contextModifier.js
Normal 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)
|
23
contributed/adventure mode/inputModifier.js
Normal file
23
contributed/adventure mode/inputModifier.js
Normal 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)
|
23
contributed/adventure mode/outputModifier.js
Normal file
23
contributed/adventure mode/outputModifier.js
Normal 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)
|
14
contributed/adventure mode/readme.md
Normal file
14
contributed/adventure mode/readme.md
Normal file
|
@ -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.
|
30
contributed/adventure mode/shared.js
Normal file
30
contributed/adventure mode/shared.js
Normal 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;
|
||||
}
|
Reference in a new issue