diff --git a/Input.js b/Input.js index 763a6ed..f8fecd1 100644 --- a/Input.js +++ b/Input.js @@ -205,6 +205,7 @@ const modifier = (text) => { if (text == null) text = processCommandSynonyms(command, commandName, removeEnemySynonyms, doRemoveEnemy) 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, helpSynonyms, doHelp) if (text == null) { var character = getCharacter() @@ -581,6 +582,7 @@ function init() { if (state.defaultDifficulty == null) state.defaultDifficulty = 10 if (state.day == null) state.day = 0 if (state.enemies == null) state.enemies = [] + if (state.initiativeOrder == null) state.initiativeOrder = [] state.show = null state.prefix = null state.critical = null @@ -1705,6 +1707,19 @@ function doAddEnemy(command) { return `[Enemy ${enemy.name} has been created]` } +function doInitiative(command) { + for (character of state.characters) { + var stat = character.stats.find(element => element.name.toLowerCase() == "dexterity") + if (stat == null) character.initiative = calculateRoll("d20") + else character.initiative = calculateRoll("d20") + getModifier(stat.value) + } + + createInitiativeOrder() + + state.show = "initiative" + return "\nBattle has commenced!\n" +} + function doTake(command) { var arg0 = getArgument(command, 0) if (arg0 == null) { @@ -2349,6 +2364,7 @@ function doReset(command) { state.locations = [] state.location = null state.enemies = null + state.initiativeOrder = [] state.x = null state.y = null state.defaultDifficulty = null diff --git a/Library.js b/Library.js index f873186..556a777 100644 --- a/Library.js +++ b/Library.js @@ -881,6 +881,22 @@ function createEnemy(name, health, ac, damage, initiative, ...spells) { return enemy } +function createInitiativeOrder() { + state.initiativeOrder = [] + + for (var character of state.characters) { + state.initiativeOrder.push(character) + } + + for (var enemy of state.enemies) { + state.initiativeOrder.push(enemy) + } + + state.initiativeOrder.sort(function(a, b) { + return b.initiative - a.initiative; + }); +} + const levelSplits = [0, 300, 900, 2700, 6500, 14000, 23000, 34000, 48000, 64000, 85000, 100000, 120000, 140000, 165000, 195000, 225000, 265000, 305000, 355000] function getLevel(experience) { diff --git a/Output.js b/Output.js index 59dbfbc..1367b91 100644 --- a/Output.js +++ b/Output.js @@ -231,6 +231,26 @@ const modifier = (text) => { text += "******************\n\n" break + case "initiative": + text += "*** INITIATIVE ORDER ***\n" + + if (state.initiativeOrder.length == 0) { + text += "There is no one in the battle. This makes no sense!" + } else { + var index = 0 + for (var character of state.initiativeOrder) { + text += `${++index}. ${character.name} (Initiative: ${character.initiative})\n` + } + } + + text += "******************\n\n" + + if (state.initiativeOrder.length > 0) { + var possesiveName = getPossessiveName(state.initiativeOrder[0].name) + if (possesiveName == "Your") possesiveName = "your" + text += `It is ${possessiveName} turn` + } + break case "reset": text += "[All settings have been reset]\n" break