Created #repeatturn

This commit is contained in:
raeleus 2024-10-27 15:32:21 -07:00
parent 0830ead687
commit 7fd92590f3
3 changed files with 62 additions and 51 deletions

View file

@ -314,6 +314,59 @@ function deleteCharacter(name) {
state.characters.splice(index, 1)
}
function executeTurn(activeCharacter) {
var activeCharacterName = toTitleCase(activeCharacter.name)
var possessiveName = getPossessiveName(activeCharacter.name)
if (possessiveName == "Your") possessiveName = "your"
if (activeCharacter.className != null) {
state.show = "none"
return `\n[It is ${possessiveName} turn]\n`
} else {
var characters = state.characters.filter(x => x.health > 0)
var target = characters[getRandomInteger(0, characters.length - 1)]
var areWord = target.name == "You" ? "are" : "is"
var targetNameAdjustedCase = target.name == "You" ? "you" : toTitleCase(target.name)
var attack = calculateRoll(`1d20${activeCharacter.hitModifier > 0 ? "+" + activeCharacter.hitModifier : activeCharacter.hitModifier < 0 ? activeCharacter.hitModifier : ""}`)
var hit = attack >= target.ac
var text = `\n[It is ${possessiveName} turn]\n`
if (getRandomBoolean() || activeCharacter.spells.length == 0) {
if (hit) {
state.blockCharacter = target
state.blockPreviousHealth = target.health
var damage = isNaN(activeCharacter.damage) ? calculateRoll(activeCharacter.damage) : activeCharacter.damage
target.health = Math.max(target.health - damage, 0)
text += `\n[Character AC: ${target.ac} Attack roll: ${attack}]\n`
text += `${activeCharacterName} attacks ${targetNameAdjustedCase} for ${damage} damage!\n`
if (target.health == 0) text += ` ${toTitleCase(target.name)} ${areWord} unconscious! \n`
else text += ` ${toTitleCase(target.name)} ${areWord} at ${target.health} health.\n`
} else text += `${activeCharacterName} attacks ${targetNameAdjustedCase} but misses!\n`
} else {
var spell = activeCharacter.spells[getRandomInteger(0, activeCharacter.spells.length - 1)]
var diceMatches = spell.match(/(?<=^.*)\d*d\d+((\+|-)\d+)?$/gi)
if (diceMatches == null) text += `${activeCharacterName} casts spell ${spell}!`
else {
if (hit) {
var damage = calculateRoll(diceMatches[0])
var spell = spell.substring(0, spell.length - diceMatches[0].length)
target.health = Math.max(target.health - damage, 0)
text += `\n[Character AC: ${target.ac} Attack roll: ${attack}]\n`
text += `${activeCharacterName} casts spell ${spell} at ${targetNameAdjustedCase} for ${damage} damage!`
if (target.health == 0) text += ` ${toTitleCase(target.name)} ${areWord} unconscious!\n`
else text += ` ${toTitleCase(target.name)} ${areWord} at ${target.health} health.\n`
} else text += `${activeCharacterName} casts spell ${spell} at ${targetNameAdjustedCase} but misses!\n`
}
}
return text
}
}
function createEncounter(listName) {
var encounter = {
text: "",