From 6e2ef76a5c8ff49f4c99d4fed00c2686d9f4476a Mon Sep 17 00:00:00 2001 From: Theryn Date: Mon, 11 Dec 2023 18:55:18 -0500 Subject: [PATCH 1/4] Initial pass at supporting NPC healing actions. --- src/dndbeyond/base/monster.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dndbeyond/base/monster.js b/src/dndbeyond/base/monster.js index ae7b480b..88e0dfd4 100644 --- a/src/dndbeyond/base/monster.js +++ b/src/dndbeyond/base/monster.js @@ -472,7 +472,9 @@ class Monster extends CharacterBase { hit = description.slice(hit_idx); // Using match with global modifier then map to regular match because RegExp.matchAll isn't available on every browser const damage_regexp = new RegExp(/([\w]* )(?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?(?: plus [^\)]+)?)\)?)? ([\w ]+?) damage/) + const healing_regexp = new RegExp(/regains (?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?)(?: plus [^\)]+)?\)?)? hit points/) const damage_matches = reMatchAll(damage_regexp, hit) || []; + const healing_matches = reMatchAll(healing_regexp, hit) || []; const damages = []; const damage_types = []; for (let dmg of damage_matches) { @@ -489,6 +491,13 @@ class Monster extends CharacterBase { damage_types.push(dmg[4]); } } + for (let dmg of healing_matches) { + const damage = dmg[2] || dmg[1]; + if (damage) { + damages.push(damage.replace("plus", "+")); + damage_types.push("Healing"); + } + } let save = null; const m = hit.match(/DC ([0-9]+) (.*?) saving throw/) let preDCDamages = damages.length; From 1f6619cb9ead061e4a1e449cf9055fa38cd4abb3 Mon Sep 17 00:00:00 2001 From: Theryn Date: Mon, 11 Dec 2023 18:55:18 -0500 Subject: [PATCH 2/4] Expanded regex to cover potential temporary HP case. --- src/dndbeyond/base/monster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dndbeyond/base/monster.js b/src/dndbeyond/base/monster.js index 88e0dfd4..c0ccc674 100644 --- a/src/dndbeyond/base/monster.js +++ b/src/dndbeyond/base/monster.js @@ -472,7 +472,7 @@ class Monster extends CharacterBase { hit = description.slice(hit_idx); // Using match with global modifier then map to regular match because RegExp.matchAll isn't available on every browser const damage_regexp = new RegExp(/([\w]* )(?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?(?: plus [^\)]+)?)\)?)? ([\w ]+?) damage/) - const healing_regexp = new RegExp(/regains (?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?)(?: plus [^\)]+)?\)?)? hit points/) + const healing_regexp = new RegExp(/gains (?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?)(?: plus [^\)]+)?\)?)? (?:temporary)?\s*hit points/) const damage_matches = reMatchAll(damage_regexp, hit) || []; const healing_matches = reMatchAll(healing_regexp, hit) || []; const damages = []; From 36bca26ea85f42f1d6e62d8053f5ec03b78bdd7f Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 12 Dec 2023 12:09:51 -0500 Subject: [PATCH 3/4] Setting the correct damage type for Temp HP gains. --- src/dndbeyond/base/monster.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/dndbeyond/base/monster.js b/src/dndbeyond/base/monster.js index c0ccc674..14e7f6d6 100644 --- a/src/dndbeyond/base/monster.js +++ b/src/dndbeyond/base/monster.js @@ -472,7 +472,7 @@ class Monster extends CharacterBase { hit = description.slice(hit_idx); // Using match with global modifier then map to regular match because RegExp.matchAll isn't available on every browser const damage_regexp = new RegExp(/([\w]* )(?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?(?: plus [^\)]+)?)\)?)? ([\w ]+?) damage/) - const healing_regexp = new RegExp(/gains (?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?)(?: plus [^\)]+)?\)?)? (?:temporary)?\s*hit points/) + const healing_regexp = new RegExp(/gains (?:([0-9]+)(?!d))?(?: *\(?([0-9]*d[0-9]+(?:\s*[-+]\s*[0-9]+)?)(?: plus [^\)]+)?\)?)? (temporary)?\s*hit points/) const damage_matches = reMatchAll(damage_regexp, hit) || []; const healing_matches = reMatchAll(healing_regexp, hit) || []; const damages = []; @@ -493,9 +493,10 @@ class Monster extends CharacterBase { } for (let dmg of healing_matches) { const damage = dmg[2] || dmg[1]; + const healingType = dmg[3] ? "Temp HP" : "Healing" if (damage) { damages.push(damage.replace("plus", "+")); - damage_types.push("Healing"); + damage_types.push(healingType); } } let save = null; From 957288d91645c4db52de8a929eedc5871d1dc17b Mon Sep 17 00:00:00 2001 From: = <=> Date: Tue, 12 Dec 2023 12:10:28 -0500 Subject: [PATCH 4/4] Formatting fix. --- src/dndbeyond/base/monster.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dndbeyond/base/monster.js b/src/dndbeyond/base/monster.js index 14e7f6d6..58b79329 100644 --- a/src/dndbeyond/base/monster.js +++ b/src/dndbeyond/base/monster.js @@ -493,7 +493,7 @@ class Monster extends CharacterBase { } for (let dmg of healing_matches) { const damage = dmg[2] || dmg[1]; - const healingType = dmg[3] ? "Temp HP" : "Healing" + const healingType = dmg[3] ? "Temp HP" : "Healing" if (damage) { damages.push(damage.replace("plus", "+")); damage_types.push(healingType);