From 09b404cbdc28cb2cb8df619b9783835a743a5501 Mon Sep 17 00:00:00 2001 From: raeleus Date: Sat, 5 Oct 2024 23:52:16 -0700 Subject: [PATCH] Added character AC. --- Input.js | 37 +++++++++++++++++++++++++++++++++++-- Library.js | 5 ++++- Output.js | 1 + 3 files changed, 40 insertions(+), 3 deletions(-) diff --git a/Input.js b/Input.js index 7eb0677..7832e0a 100644 --- a/Input.js +++ b/Input.js @@ -198,6 +198,7 @@ const modifier = (text) => { if (text == null) text = processCommandSynonyms(command, commandName, showDaySynonyms, doShowDay) if (text == null) text = processCommandSynonyms(command, commandName, setDaySynonyms, doSetDay) if (text == null) text = processCommandSynonyms(command, commandName, versionSynonyms, doVersion) + if (text == null) text = processCommandSynonyms(command, commandName, setAcSynonyms, doSetAc) if (text == null) text = processCommandSynonyms(command, commandName, helpSynonyms, doHelp) if (text == null) { var character = getCharacter() @@ -561,7 +562,8 @@ function init() { meleeStat: null, rangedStat: null, experience: 0, - health: 10 + health: 10, + ac: 10 } } if (state.characters == null) state.characters = [] @@ -575,6 +577,10 @@ function init() { state.show = null state.prefix = null state.critical = null + + state.characters.forEach(x => { + if (x.ac == null) x.ac = 10 + }) } function doRoll(command) { @@ -615,6 +621,7 @@ function doCreate(command) { state.tempCharacter.spellStat = null state.tempCharacter.meleeStat = "Strength" state.tempCharacter.rangedStat = "Dexterity" + state.tempCharacter.ac = 10 state.show = "create" return " " @@ -826,6 +833,27 @@ function doSetSkill(command) { return `\n[${possessiveName} ${toTitleCase(arg0)} skill is now ${arg2 >= 0 ? "+" + arg2 : "-" + arg2} and based on ${toTitleCase(arg1)}.]\n` } +function doSetAc(command) { + var character = getCharacter() + var arg0 = getArgument(command, 0) + if (arg0 == null) { + state.show = "none" + return "\n[Error: Not enough parameters. See #help]\n" + } + + if (isNaN(arg0)) { + state.show = "none" + return "\n[Error: Not a number. See #help]\n" + } + + var possessiveName = getPossessiveName(character.name) + + character.ac = parseInt(arg0) + + state.show = "none" + return `\n[${possessiveName} armor class is set to ${character.ac}]\n` +} + function doSetExperience(command) { var character = getCharacter() var arg0 = getArgument(command, 0) @@ -834,9 +862,14 @@ function doSetExperience(command) { return "\n[Error: Not enough parameters. See #help]\n" } + if (isNaN(arg0)) { + state.show = "none" + return "\n[Error: Not a number. See #help]\n" + } + var possessiveName = getPossessiveName(character.name) - character.experience = arg0 + character.experience = parseInt(arg0) state.show = "none" return `\n[${possessiveName} experience is set to ${character.experience}]\n` diff --git a/Library.js b/Library.js index cb195d5..4d5f444 100644 --- a/Library.js +++ b/Library.js @@ -252,6 +252,7 @@ function createCharacter(name) { existingCharacter.skills = [] existingCharacter.experience = 0 existingCharacter.health = 10 + existingCharacter.ac = 10 return existingCharacter } @@ -267,7 +268,8 @@ function createCharacter(name) { rangedStat: null, skills: [], experience: 0, - health: 10 + health: 10, + ac: 10 } state.characters.push(character) return character @@ -286,6 +288,7 @@ function copyCharacter(fromCharacter, toCharacter) { toCharacter.skills = [...new Set(fromCharacter.skills)] toCharacter.experience = fromCharacter.experience toCharacter.health = fromCharacter.health + toCharacter.ac = fromCharacter.ac return toCharacter } } diff --git a/Output.js b/Output.js index a45b859..cedeb6f 100644 --- a/Output.js +++ b/Output.js @@ -40,6 +40,7 @@ const modifier = (text) => { text += `*** ${possessiveName.toUpperCase()} BIO ***\n` text += `Class: ${character.className}\n` text += `Health: ${character.health}/${getHealthMax()}\n` + text += `Armor Class: ${character.ac}\n` text += `Experience: ${character.experience}\n` text += `Level: ${getLevel(character.experience)}\n` var nextLevel = getNextLevelXp(character.experience)