diff --git a/Input.js b/Input.js index 15e8bab..d370879 100644 --- a/Input.js +++ b/Input.js @@ -1532,21 +1532,62 @@ function doHeal(command) { state.show = "none" return "\n[Error: Not enough parameters. See #help]\n" } - arg0 = parseInt(arg0) - var haveWord = character.name == "You" ? "have" : "has" - var areWord = character.name == "You" ? "are" : "is" + var arg1 = getArgumentRemainder(command, 1) + + if (arg1 == null) { + if (character == null) { + state.show = "none" + return "\n[Error: Character must be specified. See #help]\n" + } + + var healing + + var healingMatches = arg0.match(/\d*d\d+((\+|-)d+)?/gi) + if (healingMatches != null) healing = calculateRoll(healingMatches[0]) + else { + healingMatches = arg0.match(/\d+/g) + if (healingMatches != null) healing = parseInt(healingMatches[healingMatches.length - 1]) + } + + if (healing == null) { + state.show = "none" + return "\n[Error: Expected a number. See #help]\n" + } + + var haveWord = character.name == "You" ? "have" : "has" + + character.health += healing + character.health = clamp(character.health, 0, getHealthMax()) - if (character.health >= getHealthMax()) { state.show = "none" - return `\n[${character.name} ${areWord} at maximum health]\n` + return `\n[${character.name} ${haveWord} been healed for ${healing} hp to a total of ${character.health}]\n` + } else { + var healing + + var healingMatches = arg0.match(/\d*d\d+((\+|-)d+)?/gi) + if (healingMatches != null) healing = calculateRoll(healingMatches[0]) + else { + healingMatches = arg0.match(/\d+/g) + log(healingMatches) + if (healingMatches != null) healing = parseInt(healingMatches[0]) + } + + if (healing == null) { + state.show = "none" + return "\n[Error: Expected a number. See #help]\n" + } + + for (var enemy of state.enemies) { + if (enemy.name.toLowerCase() == arg1.toLowerCase()) { + enemy.health = Math.max(0, enemy.health + healing) + return `\n[${toTitleCase(enemy.name)} has been healed for ${healing} hp to a total of ${enemy.health}]\n` + } + } + + state.show = "none" + return `\n[Error: Could not find an enemy matching the name ${enemy.name}. Type #enemies to see a list]` } - - character.health = character.health + arg0 - character.health = clamp(character.health, 0, getHealthMax()) - - state.show = "none" - return `\n[${character.name} ${haveWord} been healed by ${arg0} hp to ${character.health} health]\n` } function doDamage(command) { @@ -1585,7 +1626,7 @@ function doDamage(command) { character.health = clamp(character.health, 0, getHealthMax()) state.show = "none" - return `\n[${character.name} ${haveWord} been damaged for ${damage} hp with ${character.health} remaining].${character.health == 0 ? " You are unconscious" : ""}\n` + return `\n[${character.name} ${haveWord} been damaged for ${damage} hp with ${character.health} remaining] ${character.health == 0 ? " You are unconscious" : ""}\n` } else { var damage @@ -1605,7 +1646,7 @@ function doDamage(command) { for (var enemy of state.enemies) { if (enemy.name.toLowerCase() == arg1.toLowerCase()) { enemy.health = Math.max(0, enemy.health - damage) - return `\n[${toTitleCase(enemy.name)} has been damaged for ${damage} hp with ${enemy.health} remaining].${enemy.health == 0 ? " " + toTitleCase(enemy.name) + " has been defeated!" : ""}\n` + return `\n[${toTitleCase(enemy.name)} has been damaged for ${damage} hp with ${enemy.health} remaining] ${enemy.health == 0 ? " " + toTitleCase(enemy.name) + " has been defeated!" : ""}\n` } } diff --git a/Output.js b/Output.js index 5fda02d..9922fdf 100644 --- a/Output.js +++ b/Output.js @@ -352,10 +352,10 @@ const modifier = (text) => { text += "\n Sets the summary of the character for player reference. Quotes are not necessary." text += "\n#sethealth value" text += "\n Sets the character's health to specified value. It's capped at the character's max health." - text += "\n#heal value" - text += "\n Increases the character's health by the specified value. It's capped at the character's max health." + text += "\n#heal value or dice_roll (enemy)" + text += "\n Increases the enemy's health by the specified value or dice_roll. If an enemy isn't specified, the character calling the command is healed." text += "\n#damage value or dice_roll (enemy) " - text += "\n Decreases the enemy's health by the specified damage or dice_roll. If an enemy isn't specified, the character calling the command is damaged. Reaching 0 causes the character to become \"unconscious\"." + text += "\n Decreases the enemy's health by the specified value or dice_roll. If an enemy isn't specified, the character calling the command is damaged. Reaching 0 causes the character to become \"unconscious\"." text += "\n#setac value" text += "\n Sets the armor class of the character. The default is 10" text += "\n#setdamage value or dice_roll" diff --git a/README.md b/README.md index ff9e2a4..6921a5b 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Watch the [tutorial video](https://youtu.be/E5TYU7rDaBQ). v. 0.2.2 * Added Boss difficulty encounters * Added Humanoid Enemy Presets +* Added optional enemy parameter to #heal * Minor bug fixes and improvements v. 0.2.1 Hotfix 1