diff --git a/dnd/dnd-statblock-print.html b/dnd/dnd-statblock-print.html index 2dc6c97..84db451 100644 --- a/dnd/dnd-statblock-print.html +++ b/dnd/dnd-statblock-print.html @@ -13,11 +13,12 @@ - - - - - + + + + + + diff --git a/dnd/dnd-statblock.html b/dnd/dnd-statblock.html index 1bcdaa1..f3bec8d 100644 --- a/dnd/dnd-statblock.html +++ b/dnd/dnd-statblock.html @@ -11,11 +11,13 @@ - - - - - + + + + + + + diff --git a/dnd/js/helper-functions.js b/dnd/js/helper-functions.js new file mode 100644 index 0000000..0220c48 --- /dev/null +++ b/dnd/js/helper-functions.js @@ -0,0 +1,10 @@ +const CalculateAverageCustomHP = (monHp, conMod) =>{ + let regExp = /^\d+d(?:4|6|8|10|12|20)$/ + if(!regExp.test(monHp)) { + return monHp + } + + let [numDice, dieType] = monHp.split('d') + let average = parseInt(numDice) * (parseInt(dieType) + 1) / 2 + (parseInt(numDice) * parseInt(conMod)) + return `${Math.floor(average)} (${monHp})${!!conMod && conMod > 0 ? ` + ${parseInt(numDice) * parseInt(conMod)}` : ''}` +} \ No newline at end of file diff --git a/dnd/js/statblock-script.js b/dnd/js/statblock-script.js index 194c365..9fff847 100644 --- a/dnd/js/statblock-script.js +++ b/dnd/js/statblock-script.js @@ -1675,9 +1675,9 @@ var StringFunctions = { // Get the string displayed for the monster's HP GetHP: function () { - if (mon.customHP) - return mon.hpText; let conBonus = MathFunctions.PointsToBonus(mon.conPoints); + if (mon.customHP) + return CalculateAverageCustomHP(mon.hpText, conBonus); hitDieSize = data.sizes[mon.size].hitDie, avgHP = Math.floor(mon.hitDice * ((hitDieSize + 1) / 2)) + (mon.hitDice * conBonus); if (conBonus > 0)