From aca1b29969d76c66fd5d831772aad1c4941a0035 Mon Sep 17 00:00:00 2001 From: raeleus Date: Thu, 17 Oct 2024 19:58:19 -0700 Subject: [PATCH] Fixed being unable to use #damage to target enemies in combat. Thanks coryking! --- Input.js | 17 ++++++++--------- README.md | 1 + 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Input.js b/Input.js index 3ee26f7..0c6982d 100644 --- a/Input.js +++ b/Input.js @@ -1437,18 +1437,14 @@ function doDamage(command) { state.show = "none" return `\n[${character.name} ${haveWord} been damaged for ${damage} hp with ${character.health} remaining].${character.health == 0 ? " You are unconscious" : ""}\n` } else { - if (arg1 == null) { - state.show = "none" - return "\n[Error: Not enough parameters. See #help]\n" - } - var damage - var damageMatches = arg1.match(/\d*d\d+((\+|-)d+)?/gi) + var damageMatches = arg0.match(/\d*d\d+((\+|-)d+)?/gi) if (damageMatches != null) damage = calculateRoll(damageMatches[0]) else { - damageMatches = arg1.match(/\d+/g) - if (damageMatches != null) damage = parseInt(damageMatches[damageMatches.length - 1]) + damageMatches = arg0.match(/\d+/g) + log(damageMatches) + if (damageMatches != null) damage = parseInt(damageMatches[0]) } if (damage == null) { @@ -1457,11 +1453,14 @@ function doDamage(command) { } for (var enemy of state.enemies) { - if (enemy.name.toLowerCase() == arg0.toLowerCase()) { + 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` } } + + state.show = "none" + return `\n[Error: Could not find an enemy matching the name ${enemy.name}. Type #enemies to see a list]` } } diff --git a/README.md b/README.md index b3f3f9e..240e3b6 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ Watch the [tutorial video](https://youtu.be/E5TYU7rDaBQ). v. 0.2.1 * Call `#xp` with the parameter `party` to add xp to the entire group * List places of interest at your current coordinates to `#location` +* Fixed being unable to use #damage to target enemies in combat. Thanks coryking! * Minor bug fixes and improvements v. 0.2.0