Added #flee

This commit is contained in:
raeleus 2024-10-07 06:22:54 -07:00
parent 619365344f
commit f855683de8
2 changed files with 36 additions and 2 deletions

View file

@ -206,6 +206,7 @@ const modifier = (text) => {
if (text == null) text = processCommandSynonyms(command, commandName, clearEnemiesSynonyms, doClearEnemies)
if (text == null) text = processCommandSynonyms(command, commandName, addEnemySynonyms, doAddEnemy)
if (text == null) text = processCommandSynonyms(command, commandName, initiativeSynonyms, doInitiative)
if (text == null) text = processCommandSynonyms(command, commandName, fleeSynonyms, doFlee)
if (text == null) text = processCommandSynonyms(command, commandName, helpSynonyms, doHelp)
if (text == null) {
var character = getCharacter()
@ -1732,6 +1733,39 @@ function doInitiative(command) {
return battleHasStarted ? " " : "\nBattle has commenced!\n"
}
function doFlee(command) {
if (state.initiativeOrder.length == 0) {
state.show = "none"
return "\n[Error: Not in combat. Call #initiative first]\n"
}
var difficulty = getArgument(command, 0)
if (difficulty != null) {
const difficultyNames = ["impossible", "extreme", "hard", "medium", "easy", "effortless", "automatic"]
const difficultyScores = [30, 25, 20, 15, 10, 5, 0]
const difficultyPatternNames = [...new Set(difficultyNames)]
difficultyPatternNames.push("\\d+")
var difficultyIndex = difficultyNames.indexOf(difficulty)
if (difficultyIndex >= 0 && difficultyIndex < difficultyNames.length) {
difficulty = difficultyScores[difficultyIndex]
}
} else {
difficulty = state.defaultDifficulty
}
var roll = calculateRoll("d20")
var text = ""
if (difficulty != 0) text += `\n[DC: ${difficulty} Roll: ${roll}]\n`
if (roll >= difficulty) {
state.initiativeOrder = []
text += `\nThe party successfuly flees from battle!\n`
} else text += `\nThe party tries to flee from battle, but fails!\n`
return text
}
function doTake(command) {
var arg0 = getArgument(command, 0)
if (arg0 == null) {

View file

@ -393,8 +393,8 @@ const modifier = (text) => {
text += "\n Assigns initiative to all characters. This begins combat."
text += "\n#turn"
text += "\n Updates the turn to the next character in combat. If it is an enemy, the enemy will attack. If it's a player character, the system will allow the player to take their turn. If there are no enemies left or all the player characters are dead, combat ends."
text += "\n#flee (dc or automatic|effortless|easy|)"
text += "\n Shows the list of current enemies."
text += "\n#flee (difficulty_class or automatic|effortless|easy|medium|hard|impossible)"
text += "\n Attempt to flee from combat. If the difficulty is not specified, the automatic difficulty will be used instead."
text += "\n\n--Locations--"
text += "\n#createlocation [(x) (y) or (here|far) or (distance)] location_name"