From ce3d47a7749640c45ae3f1cc51501cd1bbd626b5 Mon Sep 17 00:00:00 2001 From: Wes Baker Date: Mon, 13 Jul 2020 11:56:12 -0400 Subject: [PATCH] [Old-School Essentials by Necrotic Gnome] - 1.5.1 (#6945) * Fix a bug where the strength bonus was not added to attack rolls * Fix a bug where new characters would have AC of 0 * Refactor weapon attribute bonus/damage sheet worker * Fix armor calculation code to account for worn armor * Remove no longer needed sheet worker calculated attributes --- Old School Essentials - AAC/CHANGELOG.md | 8 ++ Old School Essentials - AAC/OSE-AAC.html | 107 ++++++++++++----------- 2 files changed, 66 insertions(+), 49 deletions(-) diff --git a/Old School Essentials - AAC/CHANGELOG.md b/Old School Essentials - AAC/CHANGELOG.md index ab788acfe8..b1929f3c6a 100644 --- a/Old School Essentials - AAC/CHANGELOG.md +++ b/Old School Essentials - AAC/CHANGELOG.md @@ -2,6 +2,14 @@ [GitHub Project Status board](https://github.com/wesbaker/roll20-character-sheets/projects/1) +## 1.5.1 + +### Fixed + +- Fix a bug where the strength bonus was not added to attack rolls +- Fix a bug where new characters would have AC of 0 +- Fix armor calculation code to account for worn armor + ## 1.5.0 ### Added diff --git a/Old School Essentials - AAC/OSE-AAC.html b/Old School Essentials - AAC/OSE-AAC.html index 3eb8d06f67..801f508d9b 100644 --- a/Old School Essentials - AAC/OSE-AAC.html +++ b/Old School Essentials - AAC/OSE-AAC.html @@ -4,8 +4,6 @@ - - @@ -497,7 +495,7 @@
- +
@@ -1059,13 +1057,21 @@ idArray.forEach(function(id) { const attributes = ["attackType", "weaponAttributeBonusDamage"] .map(name => `repeating_weapons_${id}_${name}`) - .push('BonusStr'); + .concat(['BonusSTR', 'BonusDEX']) ; getAttrs(attributes, function(values) { if (!values[`repeating_weapons_${id}_attackType`]) { if (values.BonusSTR !== 0 && values[`repeating_weapons_${id}_weaponAttributeBonusDamage`] === 0) { - setAttrs({ [`repeating_weapons_${id}_attackType`]: "Ranged" }) + setAttrs({ + [`repeating_weapons_${id}_attackType`]: "Ranged", + [`repeating_weapons_${id}_weaponAttributeBonus`]: values.BonusDEX, + [`repeating_weapons_${id}_weaponAttributeBonusDamage`]: '0' + }); } else { - setAttrs({ [`repeating_weapons_${id}_attackType`]: "Melee" }) + setAttrs({ + [`repeating_weapons_${id}_attackType`]: "Melee", + [`repeating_weapons_${id}_weaponAttributeBonus`]: values.BonusSTR, + [`repeating_weapons_${id}_weaponAttributeBonusDamage`]: values.BonusSTR + }); } } }); @@ -1220,31 +1226,29 @@ // Armor Calculation on('sheet:opened change:dex change:repeating_armor remove:repeating_armor', function () { - repeatingSum( - "ArmorTotal", - "armor", - ["armorValue", "armorWorn"], - { - callback: function () { - repeatingSum( - "ArmorWornTotal", - "armor", - ["armorWorn"], - { - callback: function () { - getAttrs(["ArmorTotal", "ArmorWornTotal", "BonusDEX", "aacAcUnarmored", "dacAcUnarmored"], function (values) { - const armorTotal = parseInt(values.ArmorTotal, 10); - setAttrs({ - aacAc: (values.ArmorWornTotal > 0) ? armorTotal + values.BonusDEX : values.aacAcUnarmored, - dacAc: (values.ArmorWornTotal > 0) ? armorTotal - values.BonusDEX : values.dacAcUnarmored - }); - }); - } - } - ) - } - } - ); + getSectionIDs("repeating_armor", function(idArray) { + let armorWorn = 0; + let armorTotal = 0; + + idArray.forEach(function(id) { + const attributes = ["armorValue", "armorWorn"] + .map(name => `repeating_armor_${id}_${name}`) + .concat(['BonusSTR', 'BonusDEX']); + getAttrs(attributes, function(values) { + if (values[`repeating_armor_${id}_armorWorn`]) { + armorWorn += 1; + armorTotal += parseFloat(values[`repeating_armor_${id}_armorValue`]); + } + }); + }); + + getAttrs(["BonusDEX"], function(values) { + setAttrs({ + aacAc: (armorWorn > 0) ? armorTotal + values.BonusDEX : values.aacAcUnarmored, + dacAc: (armorWorn > 0) ? armorTotal - values.BonusDEX : values.dacAcUnarmored, + }) + }) + }); }); // Recalculate encumbrance @@ -1296,24 +1300,29 @@ }); }); - // Set weaponAttributeBonus and weaponAttributeBonusDamage - on('change:repeating_weapons:attackType', function(event) { - const attackType = event.newValue; - getAttrs(["BonusSTR", "BonusDEX"], function(values) { - console.log(values) - if (attackType == "ranged") { - setAttrs({ - repeating_weapons_weaponAttributeBonus: values.BonusDEX, - repeating_weapons_weaponAttributeBonusDamage: 0 - }) - } else { - setAttrs({ - repeating_weapons_weaponAttributeBonus: values.BonusSTR, - repeating_weapons_weaponAttributeBonusDamage: values.BonusSTR - }) - } - }) - }) + // Update weaponAttributeBonus and weaponAttributeBonusDamage when STR or DEX changes + on('change:repeating_weapons:attackType change:str change:dex', function() { + getSectionIDs("repeating_weapons", function(idArray) { + idArray.forEach(function(id) { + const attributes = ["attackType"] + .map(name => `repeating_weapons_${id}_${name}`) + .concat(['BonusSTR', 'BonusDEX']) ; + getAttrs(attributes, function(values) { + if (values[`repeating_weapons_${id}_attackType`] === 'ranged') { + setAttrs({ + [`repeating_weapons_${id}_weaponAttributeBonus`]: values.BonusDEX, + [`repeating_weapons_${id}_weaponAttributeBonusDamage`]: '0' + }); + } else { + setAttrs({ + [`repeating_weapons_${id}_weaponAttributeBonus`]: values.BonusSTR, + [`repeating_weapons_${id}_weaponAttributeBonusDamage`]: values.BonusSTR + }); + } + }); + }); + }); + }); // Set saving throws, BAB, THAC0, HD, Next Level Experience on('change:level change:class change:monsterhitdice change:monsterhitdicemodifier', function() {