From e13e65a37c0d883ca79f81e6b0598be77ae73bf9 Mon Sep 17 00:00:00 2001 From: raeleus Date: Sat, 26 Oct 2024 22:52:31 -0700 Subject: [PATCH] Fixed defeated enemies not being removed from combat. Resolves #92 --- Input.js | 14 +++++++------- README.md | 1 + 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/Input.js b/Input.js index b1c8494..f037f97 100644 --- a/Input.js +++ b/Input.js @@ -1569,7 +1569,6 @@ function doHeal(command) { if (healingMatches != null) healing = calculateRoll(healingMatches[0]) else { healingMatches = arg0.match(/\d+/g) - log(healingMatches) if (healingMatches != null) healing = parseInt(healingMatches[0]) } @@ -1642,7 +1641,6 @@ function doDamage(command) { if (damageMatches != null) damage = calculateRoll(damageMatches[0]) else { damageMatches = arg0.match(/\d+/g) - log(damageMatches) if (damageMatches != null) damage = parseInt(damageMatches[0]) } @@ -1918,7 +1916,6 @@ function doAttack(command) { var indexMatches = targetText.match(/(?<=enemy\s*)\d+/gi) if (indexMatches != null) { foundEnemy = state.enemies[parseInt(indexMatches[0]) - 1] - log(`foundEnemy:${foundEnemy}`) targetText = targetText.replace(/enemy\s*d+/gi, foundEnemy.name) } } @@ -1940,8 +1937,10 @@ function doAttack(command) { if (score == 20) enemyString += `\nCritical Damage: ${damage}\n` else enemyString += `\nDamage: ${damage}\n` foundEnemy.health = Math.max(0, foundEnemy.health - damage) - if (foundEnemy.health == 0) enemyString += ` ${toTitleCase(foundEnemy.name)} has been defeated!` - else enemyString += ` ${toTitleCase(foundEnemy.name)} has ${foundEnemy.health} health remaining!` + if (foundEnemy.health == 0) { + enemyString += ` ${toTitleCase(foundEnemy.name)} has been defeated!` + + } else enemyString += ` ${toTitleCase(foundEnemy.name)} has ${foundEnemy.health} health remaining!` } } } @@ -2524,7 +2523,8 @@ function doTurn(command) { if (enemy.health > 0) continue defeatedEnemies++ - var index = state.initiativeOrder.indexOf(enemy) + var index = state.initiativeOrder.findIndex(x => x.name.toLowerCase() == enemy.name.toLowerCase()) + log(`index:${index}`) if (index >= 0) state.initiativeOrder.splice(index, 1) } @@ -2533,7 +2533,7 @@ function doTurn(command) { if (character.health > 0) continue defeatedCharacters++ - var index = state.initiativeOrder.indexOf(character) + var index = state.initiativeOrder.findIndex(x => x.name.toLowerCase() == character.name.toLowerCase()) if (index >= 0) state.initiativeOrder.splice(index, 1) } diff --git a/README.md b/README.md index 2101b66..3b49b91 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ v. 0.2.2 * Added Humanoid Enemy Presets * Added optional enemy parameter to #heal * Tweaked #heal and #damage to allow targeting characters specified as a parameter +* Fixed defeated enemies not being removed from combat * Minor bug fixes and improvements v. 0.2.1 Hotfix 1