Well, I have something that works, I have learned a lot from this...
const calcWeaponDamage = function (prefix) {
const sourceAttrs = [
"DMG-mod", "DMG2-mod", "DMG_ranged-mod", "DMG_ranged2-mod",
'PwrAtkDam',
"APP-mod", "STR-mod", "DEX-mod", "CON-mod", "INT-mod", "WIS-mod", "CHA-mod",
prefix+"_enhance", prefix+"_attack-type", prefix+"_damage", prefix+"_damage-ability", prefix+"_damage_ability_mult", prefix+"_damage-ability-max", prefix+"_masterwork",
];
getAttrs(sourceAttrs, function (v) {
var atkType = v[prefix+"_attack-type"]; // Compare
var damAbil = v[prefix+"_damage-ability"]; // Compare
var attackType = " ", buff_DMG_mod = 0, damageAbil = " ", damAbilMod = 0; // Unset variables, yet.
if (atkType === "0") {attackType="None", buff_DMG_mod=0;}
if (atkType === "@{attk-melee}") {attackType="Melee", buff_DMG_mod=parseFloat(v["DMG-mod"],10) || 0;}
if (atkType === "@{attk-melee2}") {attackType="Melee2", buff_DMG_mod=parseFloat(v["DMG2-mod"],10) || 0;}
if (atkType === "@{attk-ranged}") {attackType="Ranged", buff_DMG_mod=parseFloat(v["DMG_ranged-mod"],10) || 0;}
//if (atkType === "@{attk-ranged2}"){attackType="Ranged2", buff_DMG_mod=parseFloat(v["DMG_ranged2-mod"],10) || 0;} NOT USED, Yet.
if (atkType === "@{attk-CMB}") {attackType="CMB";}
if (atkType === "@{attk-CMB2}") {attackType="CMB2";}
console.log("Attack Type: " +attackType+ " || Bonus Damage:" +buff_DMG_mod+ "."); // DOES NOT SHOW the propper damage??
if (damAbil === "0") {attackType="None";damAbilMod=0}
if (damAbil === "@{APP-mod}") {damageAbil="APP Mod";damAbilMod=parseInt(v["APP-mod"]);} // Appearance Score, kinda like comelyness from AD&D, Houserule.
if (damAbil === "@{STR-mod}") {damageAbil="STR Mod";damAbilMod=parseInt(v["STR-mod"]);}
if (damAbil === "@{DEX-mod}") {damageAbil="DEX Mod";damAbilMod=parseInt(v["DEX-mod"]);}
if (damAbil === "@{CON-mod}") {damageAbil="CON Mod";damAbilMod=parseInt(v["CON-mod"]);}
if (damAbil === "@{INT-mod}") {damageAbil="INT Mod";damAbilMod=parseInt(v["INT-mod"]);}
if (damAbil === "@{WIS-mod}") {damageAbil="WIS Mod";damAbilMod=parseInt(v["WIS-mod"]);}
if (damAbil === "@{CHA-mod}") {damageAbil="CHA Mod";damAbilMod=parseInt(v["CHA-mod"]);}
console.log("Damage Ability: " +damageAbil+ "+" +damAbilMod+ "."); // Does not show the proper ability modifier?? Same problem as above console log?
var wepEnh = parseInt(v[prefix+"_enhance"],10) || 0;
var wepDmgMisc = parseInt(v[prefix+"_damage"],10) || 0;
var abilDam = Math.max(damAbilMod * parseFloat(v[prefix+"_damage_ability_mult"]), parseInt(v[prefix+"_damage-ability-max"])); // I've never really understood abilty max... but okay..
var PwrAtk = parseInt(v["PwrAtkDam"])||0 * Math.max(parseFloat(v[prefix+"_damage_ability_mult"]),2); // Set Power Attack Based Abil Multiplier, with a maximum of x2
var Damage = wepEnh + wepDmgMisc + abilDam + PwrAtk + buff_DMG_mod;
console.log("Damage Calculation: "+Damage+"= Enh:"+wepEnh+"+Mod"+wepDmgMisc+"+Abil"+abilDam+"+PwrAtk"+PwrAtk+"+Buffs"+buff_DMG_mod);
/* From SWUtil.js || Parses an text or input field with @{xxx} or [[ xx ]] arithmatic into readable fields for SheetWorkers */
/* I have quickly learned to love SWUtils, I just wish there was more examples of how they work... */
evaluateAndSetNumber("repeating_weapon_attack","repeating_weapon_attack-mod");
evaluateAndSetNumber("repeating_weapon_crit_confirm","repeating_weapon_crit_conf_mod");
evaluateAndSetNumber("repeating_weapon_damage","repeating_weapon_damage-mod");
setAttrs({
[prefix+"_wepEnh"]: Math.max(parseInt(v["repeating_weapon_enhance"]),parseInt(v["repeating_weapon_masterwork"])),
[prefix+"_total-damage"]: Damage,
});
});
};
on('change:DMG-mod', function () {
getSectionIDs('repeating_weapon', function (ids) {
ids.forEach(id => calcWeaponDamage('repeating_weapon_'+id));
});
});
on('change:repeating_weapon', function () {
calcWeaponDamage('repeating_weapon');
});
the const calcWeaponDamage = function (prefix) {....} in particular is different, I can see how that would be quite versatile and useful for separating different types of attributes that you wish to include.
I'm not sure what the bottom two onChange() functions are actually doing, at least not specifically, the first appears to be looping through each repeating section row, but looping and doing what? That I cant see.. And the second, maybe is setting the acceptable prefix?
There are a few errors that are being throwing when this functions, specifically when the Buffs repeating section buffs are being enabled/disabled, I get a NaN in the console log that vanishes instantly, but it affects nothing, and doesn't seem to be causing issues with rolls or anything.
And a more serious error that I have noticed just as I am writing this, that if I try and delete a row, it wont let me unless I click minimize/maximize all rows and thereby lock everything from moving around. Its hard to explain without alot of screenshots. It also seems to be releated to the NaN error.
firebase.2.4.0.js:45 FIREBASE WARNING: Exception was thrown by user callback. Error: Firebase.update failed: First argument contains NaN in property 'stg-campaign-41092-XKZkxz5JZEsxvCFXxCI4Fg.char-attribs.char.-KQqjW1XrGfKWm2SWlPo.-KzprFQm2UXpt_1V6Odf.current'
at hg (https://app.roll20dev.net/assets/firebase.2.4.0.js:123:203)
at https://app.roll20dev.net/assets/firebase.2.4.0.j...
at Fb (https://app.roll20dev.net/assets/firebase.2.4.0.js:28:656)
at jg (https://app.roll20dev.net/assets/firebase.2.4.0.js:126:134)
at X.update (https://app.roll20dev.net/assets/firebase.2.4.0.js:258:369)
at https://app.roll20dev.net/assets/firebase.2.4.0.j...
at c (https://app.roll20dev.net/assets/firebase.2.4.0.js:240:58)
at https://app.roll20dev.net/assets/firebase.2.4.0.j...
at gc (https://app.roll20dev.net/assets/firebase.2.4.0.js:52:165)
at cc (https://app.roll20dev.net/assets/firebase.2.4.0.js:30:216)
S @ firebase.2.4.0.js:45
(anonymous) @ firebase.2.4.0.js:52
setTimeout (async)
gc @ firebase.2.4.0.js:52
cc @ firebase.2.4.0.js:30
bc @ firebase.2.4.0.js:29
Qi @ firebase.2.4.0.js:224
h.Ib @ firebase.2.4.0.js:238
h.Og @ firebase.2.4.0.js:240
Backbone.sync @ app.js?1509374274:3
save @ base.js?1507671575:1
syncedSave @ app.js?1509374274:40
(anonymous) @ app.js?1509374274:47
k.each.k.forEach @ base.js?1507671575:1
h.(anonymous function) @ base.js?1507671575:1
(anonymous) @ app.js?1509374274:47
firebase.2.4.0.js:123 Uncaught Error: Firebase.update failed: First argument contains NaN in property 'stg-campaign-41092-XKZkxz5JZEsxvCFXxCI4Fg.char-attribs.char.-KQqjW1XrGfKWm2SWlPo.-KzprFQm2UXpt_1V6Odf.current'
at hg (firebase.2.4.0.js:123)
at firebase.2.4.0.js:126
at Fb (firebase.2.4.0.js:28)
at jg (firebase.2.4.0.js:126)
at X.update (firebase.2.4.0.js:258)
at app.js?1509374274:3
at c (firebase.2.4.0.js:240)
at firebase.2.4.0.js:201
at gc (firebase.2.4.0.js:52)
at cc (firebase.2.4.0.js:30)
Anyways, I intend to keep fiddling, but I wanted to thank you for all your assistance.