diff --git a/Input.js b/Input.js index e1bf316..8a4df81 100644 --- a/Input.js +++ b/Input.js @@ -1013,6 +1013,7 @@ function doDamage(command) { function doRest(command) { var commandName = getCommandName(command) state.day++ + state.enemies = [] state.characters.forEach(function(character) { if (commandName.toLowerCase() == "shortrest") { var max = getHealthMax(character) @@ -2320,10 +2321,11 @@ function doCastSpell(command) { var character = getCharacter() const dontWord = character.name == "You" ? "don't" : "doesn't" const tryWord = character.name == "You" ? "try" : "tries" + var usingDefaultDifficulty = false var spellIndex = 2; - var advantage = searchArgument(command, arrayToOrPattern(advantageNames)) + var advantage = searchArgument(command, arrayToOrPattern(advantageNames), spellIndex - 1) if (advantage == null) { advantage = "normal" spellIndex-- @@ -2331,9 +2333,10 @@ function doCastSpell(command) { const difficultyPatternNames = [...new Set(difficultyNames)] difficultyPatternNames.push("\\d+") - var difficulty = searchArgument(command, arrayToOrPattern(difficultyPatternNames)) + var difficulty = searchArgument(command, arrayToOrPattern(difficultyPatternNames), spellIndex - 1) if (difficulty == null) { difficulty = state.defaultDifficulty + usingDefaultDifficulty = true spellIndex-- } var difficultyIndex = difficultyNames.indexOf(difficulty) @@ -2385,6 +2388,33 @@ function doCastSpell(command) { var roll2 = calculateRoll("d20") var roll = advantage == "advantage" ? Math.max(roll1, roll2) : advantage == "disadvantage" ? Math.min(roll1, roll2) : roll1 + //add enemy damage here + var enemyString + if (target != null && state.initiativeOrder.length > 0) { + var damage = roll == 20 ? calculateRoll("2d6") + calculateRoll("2d6") : calculateRoll("2d6") + + var damageMatches = target.match(/\d*d\d+((\+|-)d+)?/g) + if (damageMatches != null) damage = roll == 20 ? calculateRoll(damageMatches[0]) + calculateRoll(damageMatches[0]) : calculateRoll(damageMatches[0]) + else { + damageMatches = target.match(/\d+/g) + if (damageMatches != null) damage = roll == 20 ? parseInt(damageMatches[damageMatches.length - 1]) * 2 : parseInt(damageMatches[damageMatches.length - 1]) + } + + for (var enemy of state.enemies) { + if (target.toLowerCase().includes(enemy.name.toLowerCase())) { + if (usingDefaultDifficulty) difficulty = enemy.ac + if (roll + modifier >= difficulty) { + if (roll == 20) enemyString += ` Critical Damage: ${damage}` + else enemyString += ` Damage: ${damage}` + enemy.health = Math.max(0, enemy.health - damage) + if (enemy.health == 0) enemyString = ` ${toTitleCase(enemy.name)} has been defeated!` + else enemyString = ` ${toTitleCase(enemy.name)} has ${enemy.health} health remaining!` + } + break + } + } + } + state.show = "prefix" var dieText = advantage == "advantage" || advantage == "disadvantage" ? `${advantage}(${roll1},${roll2})` : roll1 var difficultyWord = target == null ? "Difficulty" : "Armor" @@ -2398,6 +2428,8 @@ function doCastSpell(command) { else if (roll + modifier >= difficulty) text += ` The spell ${target != null ? "hits the target" : "is successful"}!` else text += ` The spell ${target != null ? "misses" : "fails"}!` + if (enemyString != null) text += enemyString + if (roll + modifier >= difficulty || roll == 20) text += addXpToAll(Math.floor(state.autoXp * clamp(difficulty, 1, 20) / 20)) return `\n${text}\n` } diff --git a/Output.js b/Output.js index 03ba950..b786045 100644 --- a/Output.js +++ b/Output.js @@ -321,9 +321,9 @@ const modifier = (text) => { text += "\n#try (ability|skill) (advantage|disadvantage) (difficulty_class or automatic|effortless|easy|medium|hard|impossible) task" text += "\n Attempts to do the task based on the character's ability/skill against the specified difficulty. Quotes are not necessary." text += "\n#attack (ranged) (advantage|disadvantage) (ac or effortless|easy|medium|hard|impossible) target" - text += "\n Attacks the specified target with a melee (the default) or ranged attack. The roll is compared against the specified AC which will determine if the attack succeeds or misses. The parameters can be listed in any order, except the target must be listed last. Quotes are not necessary." + text += "\n Attacks the specified target with a melee (the default) or ranged attack. The roll is compared against the specified AC which will determine if the attack succeeds or misses. If the AC is not specified, the default AC or the AC of the opponent in combat will be used. The parameters can be listed in any order, except the target must be listed last. Quotes are not necessary." text += "\n#cast (advantage|disadvantage) (difficulty_class or effortless|easy|medium|hard|impossible) spell(target)" - text += "\n Character will cast the indicated spell if the spell is in their spellbook. It will be a targeted spell if a target is indicated. The roll is modified by the spell casting ability of the character. You may type a phrase without quotes for spell such as \"cast fire bolt at the giant chicken\". The parameters can be listed in any order, except the target must be listed last. Quotes are not necessary." + text += "\n Character will cast the indicated spell if the spell is in their spellbook. It will be a targeted spell if a target is indicated. The roll is modified by the spell casting ability of the character. You may type a phrase without quotes for spell such as \"cast fire bolt at the giant chicken\". If the difficulty is not specified, the default difficulty or the AC of the opponent in combat will be used. The parameters can be listed in any order, except the target must be listed last. Quotes are not necessary." text += "\n\n--Abilities--" text += "\n#setability ability value"