From d28d125404751ba73750549bbf92d19682ba1e6c Mon Sep 17 00:00:00 2001 From: Darth-John <77751557+Darth-John@users.noreply.github.com> Date: Mon, 14 Mar 2022 10:29:23 -0700 Subject: [PATCH 01/10] Refactored createSkill() Moving to writeValues() to likely resolve cache out of sync issues. POCed on createSkill() function. --- BESM4eExtras/BESM4eExtras.html | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/BESM4eExtras/BESM4eExtras.html b/BESM4eExtras/BESM4eExtras.html index 621ea0c80b..9b896a761c 100644 --- a/BESM4eExtras/BESM4eExtras.html +++ b/BESM4eExtras/BESM4eExtras.html @@ -13858,6 +13858,12 @@ clog(debug, timer, "specializations =", specializations); clog(debug, timer, "statallaspect =", statallaspect); clog(debug, timer, "statmajor =", statmajor); + const skill_attributes = ['group','name','skillspecilizations','majorstats','minorstats','stat','skillrollvalue']; + const skill_attributes_values = [group, name, specializations, type.major, type.minor, getSkillStatsDisplay(stats), roll]; + _.each(skill_attributes, (a,i) => { + writeValues(debug, timer, value, `repeating_skill_${skillID}_${a}`, skill_attributes_values[i], setObj); + }); + /* setObj[`repeating_skill_${skillID}_group`] = group; setObj[`repeating_skill_${skillID}_name`] = name; setObj[`repeating_skill_${skillID}_costperlevel`] = cost; @@ -13866,8 +13872,8 @@ setObj[`repeating_skill_${skillID}_minorstats`] = type.minor; setObj[`repeating_skill_${skillID}_stat`] = getSkillStatsDisplay(stats); setObj[`repeating_skill_${skillID}_skillrollvalue`] = roll; - setObj.skillmanagement = 0; - const id = skillID.toLowerCase(); + + value[`repeating_skill_${id}_group`] = group; value[`repeating_skill_${id}_name`] = name; value[`repeating_skill_${id}_costperlevel`] = cost; @@ -13876,7 +13882,10 @@ value[`repeating_skill_${id}_minorstats`] = type.minor; value[`repeating_skill_${id}_stat`] = getSkillStatsDisplay(stats); value[`repeating_skill_${id}_skillrollvalue`] = roll; - value.skillIDs = value.skillIDs.push(id); + */ + //const id = skillID.toLowerCase(); + value.skillIDs = value.skillIDs.push(skillID.toLowerCase()); + setObj.skillmanagement = 0; } function buildSkillTemplateValuesArray(skilltemplateIDs){ From d57a099410ec9ef375baa55853547f6b2f2b1ee0 Mon Sep 17 00:00:00 2001 From: Darth-John <77751557+Darth-John@users.noreply.github.com> Date: Mon, 14 Mar 2022 13:14:57 -0700 Subject: [PATCH 02/10] Ammo/Capacity Fix Setting Ammo limiter to rank 3 will now give reloads of 1 instead of 2. Fixed ammo/capacity persistency with new caching system. --- BESM4eExtras/BESM4eExtras.html | 52 ++++++++++++++++++++-------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/BESM4eExtras/BESM4eExtras.html b/BESM4eExtras/BESM4eExtras.html index 9b896a761c..0363b5534b 100644 --- a/BESM4eExtras/BESM4eExtras.html +++ b/BESM4eExtras/BESM4eExtras.html @@ -12602,27 +12602,22 @@ } function getAmmoMax(debug, timer, rank) { - const result = rank == 4 ? 0 : 6 / rank; + const result = + rank == 4 ? 0 : + rank == 3 ? 1 : + 6 / rank; clog(debug, timer, 'result =', result, 'getAmmoMax()'); return result; } function setWeaponReload(debug, timer, attrdb, value, setObj) { const rowID = value.active_weapon; - //const weapon = _.find(attrdb.weapon, w => { - // if (w.source == rowID) return true; - //}); - //const customization = _.find(weapon.customizations, c => { - // if (c.name == 'ammo') return true; - //}); - //const ammo = getAmmoMax(debug, timer, customization.rank); const capacity = parseInt(value[`repeating_attr_${rowID}_capacity`]); let ammostate = parseInt(value.weapon_ammo_reloads); - let capacitystate = parseInt(value.weapon_ammo_capacity); - const reloadammo = ammo => ammo > 0 ? ammostate -= 1 : ammostate; - const reloadcapacity = ammo => ammo > 0 ? capacitystate = capacity : capacitystate; - setObj.weapon_ammo_reloads = reloadammo(ammostate); - setObj.weapon_ammo_capacity = reloadcapacity(ammostate); + const reloadcapacity = ammostate > 0 ? capacity : 0; + const reloadammo = ammostate > 0 ? ammostate -= 1 : 0; + writeValues(debug, timer, value, 'weapon_ammo_reloads', reloadammo, setObj); + writeValues(debug, timer, value, 'weapon_ammo_capacity', reloadcapacity, setObj); clog(debug, timer, 'reloads =', setObj.weapon_ammo_reloads, 'setWeaponReload()'); clog(debug, timer, 'capacity =', setObj.weapon_ammo_capacity); } @@ -12647,15 +12642,19 @@ const capacity = isNaN(parseInt(value[`repeating_attr_${rowID}_capacitystate`])) ? 0 : parseInt(value[`repeating_attr_${rowID}_capacitystate`]); - setObj.weapon_ammo_reloads = ammo; - setObj.weapon_ammo_capacity = capacity; + //setObj.weapon_ammo_reloads = ammo; + //setObj.weapon_ammo_capacity = capacity; + writeValues(debug, timer, value, 'weapon_ammo_reloads', ammo, setObj); + writeValues(debug, timer, value, 'weapon_ammo_capacity', capacity, setObj); clog(debug, timer, 'ammo =', ammo, 'setWeaponAmmo()'); clog(debug, timer, 'capacity =', capacity); } else {//weapon unarmed, save ammo state const ammostate = parseInt(value.weapon_ammo_reloads); const capacitystate = parseInt(value.weapon_ammo_capacity); - setObj[`repeating_attr_${rowID}_ammostate`] = ammostate; - setObj[`repeating_attr_${rowID}_capacitystate`] = capacitystate; + //setObj[`repeating_attr_${rowID}_ammostate`] = ammostate; + //setObj[`repeating_attr_${rowID}_capacitystate`] = capacitystate; + writeValues(debug, timer, value, `repeating_attr_${rowID}_ammostate`, ammostate, setObj); + writeValues(debug, timer, value, `repeating_attr_${rowID}_capacitystate`, capacitystate, setObj); clog(debug, timer, 'ammostate =', ammostate, 'setWeaponAmmo()'); clog(debug, timer, 'capacitystate =', capacitystate); } @@ -13514,20 +13513,26 @@ }); } + function recordAmmoState(debug, timer, value, setObj) { + writeValues(debug, timer, value, `repeating_attr_${value.active_weapon}_ammostate`, value.weapon_ammo_reloads, setObj); + writeValues(debug, timer, value, `repeating_attr_${value.active_weapon}_capacitystate`, value.weapon_ammo_capacity, setObj); + } + function disableActiveWeapon(debug, timer, value, rowID, setObj) { + const activeweapon = value.active_weapon; + recordAmmoState(debug, timer, value, setObj); setObj.weapon_range = 0; setObj.weapon_ammo_autofire = 0; setObj.weapon_ammo = 0; setObj.weapon_autofire = 0; const state = parseInt(setObj[`repeating_attr_${rowID}_activate`]) || parseInt(value[`repeating_attr_${rowID}_activate`]); - const activeweapon = value.active_weapon; + clog(debug, timer, 'state =', state, 'disableActiveWeapon()'); + clog(debug, timer, 'activeweapon =', activeweapon); if (!state) return; if (activeweapon == rowID) { setObj.active_weapon = ''; } - clog(debug, timer, 'state =', state, 'disableActiveWeapon()'); - clog(debug, timer, 'activeweapon =', activeweapon); } function setButtonState(debug, timer, value, source, rowID, sourceAttr, setObj) { @@ -13719,7 +13724,7 @@ } function recordSheetChanges(eventInfo, value, setObj) { - const sheet_change_array = ['show_debug_messages']; + const sheet_change_array = ['show_debug_messages','weapon_ammo_reloads','weapon_ammo_capacity']; const recordChange = sheet_change_array.indexOf(eventInfo.sourceAttribute) !== -1 ? true : false; if (recordChange) { @@ -13940,6 +13945,8 @@ function registerEvents() { const eventsToRegister = [ + "weapon_ammo_reloads", + "weapon_ammo_capacity", "static_options_selection_gamegenre", "show_debug_messages", "static_weapon_autofire_selection", @@ -14285,10 +14292,11 @@ //setPoolCostIfGroupIsFlux(debug, timer, attrIDs, value, rowID, setObj); setAttrGroupPoolSpentByActivation(debug, timer, isActive, attrIDs, value, rowID, setObj); //setPoolCostIfGroupIsVariation(debug, timer, isActive, attrIDs, value, rowID, setObj); + disableActiveWeapon(debug, timer, value, rowID, setObj); if (handstate) { setWeaponAmmo(debug, timer, attrdb, value, handsource, setObj); } - disableActiveWeapon(debug, timer, value, rowID, setObj); + setGroupDefectPointsOnActivation(debug, timer, attrIDs, attrdb, value, sectionName, rowID, setObj); break; case `lock`: From 475dbfde5502282e79f41de3d56b3152166e9a33 Mon Sep 17 00:00:00 2001 From: Darth-John <77751557+Darth-John@users.noreply.github.com> Date: Mon, 14 Mar 2022 13:57:18 -0700 Subject: [PATCH 03/10] Stat update fix Stat update is now reflected in skill rolls. --- BESM4eExtras/BESM4eExtras.html | 51 +++++++++++++++++++--------------- 1 file changed, 28 insertions(+), 23 deletions(-) diff --git a/BESM4eExtras/BESM4eExtras.html b/BESM4eExtras/BESM4eExtras.html index 0363b5534b..459425c605 100644 --- a/BESM4eExtras/BESM4eExtras.html +++ b/BESM4eExtras/BESM4eExtras.html @@ -8108,7 +8108,7 @@ return result; } - function setStatCost(debug, timer, eventInfo, setObj, sourceAttr) { + function setStatCost(debug, timer, eventInfo, value, setObj, sourceAttr) { const newValue = parseInt(eventInfo.newValue) || 0; const previousValue = parseInt(eventInfo.previousValue) || 0; const diffValue = newValue - previousValue; @@ -8121,7 +8121,8 @@ (((newValue - 12) * 8) + 48) - (previousValue * 4) : newValue <= 12 && previousValue > 12 ? (newValue * 4) - (((previousValue - 12) * 8) + 48) : 0; - setObj[`stat_cost_${sourceAttr}`] = statCost; + //setObj[`stat_cost_${sourceAttr}`] = statCost; + writeValues(debug, timer, value, `stat_cost_${sourceAttr}`, statCost, setObj); clog(debug, timer, 'statCost =', statCost, 'setStatCost()'); } @@ -8721,7 +8722,7 @@ //setObj[`stat_total_${stat}`] = result; writeValues(debug, timer, value, `stat_total_${stat}`, result, setObj); clog(debug, timer, 'result =', result, 'setAllAspectStats()'); - setStatCost(debug, timer, eventInfo, setObj, stat); + setStatCost(debug, timer, eventInfo, value, setObj, stat); setStatAspectLevels(debug, timer, attrdb, value, stat, result, setObj) } @@ -8741,7 +8742,8 @@ }) .value(); _.each(minorstats, (minorstat, i) => { - setObj[`stat_total_${minorstat}`] = result[i]; + //setObj[`stat_total_${minorstat}`] = result[i]; + writeValues(debug, timer, value, `stat_total_${minorstat}`, result[i], setObj); }); clog(debug, timer, 'result:', result, 'setStatAspectLevels()'); } @@ -8894,22 +8896,24 @@ derivedvalue == 'social' ? Math.round((bodyormind + soul) / 2) + bonus + temp : 0; - setObj[`stat_total_${derivedvalue}`] = result; + //setObj[`stat_total_${derivedvalue}`] = result; + writeValues(debug, timer, value, `stat_total_${derivedvalue}`, result, setObj); clog(debug, timer, derivedvalue, result, 'setDerivedValue()'); } - function setTotalShock(debug, timer, attrdb, setObj, sourceAttr) { + function setTotalShock(debug, timer, value, attrdb, setObj) { const health = parseInt(setObj.stat_total_health) || parseInt(value.stat_total_health) || 0; const hardboiled = getSumOfActiveSubAttrRanks(attrdb, 'combattechnique', 'hardboiled') || 0; const result = Math.round(health / 5) + hardboiled; - setObj.stat_total_shock = result; + //setObj.stat_total_shock = result; + writeValues(debug, timer, value, 'stat_total_shock', result, setObj); clog(debug, timer, 'result =', result, 'setTotalShock()'); } - function setTotalMovement(debug, timer, value, attrdb, setObj, sourceAttr) { + function setTotalMovement(debug, timer, value, attrdb, setObj) { const body = parseInt(setObj.stat_total_body) || parseInt(value.stat_total_body) || 0; @@ -12056,7 +12060,7 @@ break; case "specialmovement": setAttrdb(isActive, debug, timer, value, attrdb, attrIDs, rowID, sourceAttr, attribute, setObj); - setTotalMovement(debug, timer, value, attrdb, setObj, sourceAttr); + setTotalMovement(debug, timer, value, attrdb, setObj); setActiveAttribute(isActive, debug, timer, value, rowID, attrdb, setObj, attribute, level); break; case "socialmastery": @@ -12642,8 +12646,6 @@ const capacity = isNaN(parseInt(value[`repeating_attr_${rowID}_capacitystate`])) ? 0 : parseInt(value[`repeating_attr_${rowID}_capacitystate`]); - //setObj.weapon_ammo_reloads = ammo; - //setObj.weapon_ammo_capacity = capacity; writeValues(debug, timer, value, 'weapon_ammo_reloads', ammo, setObj); writeValues(debug, timer, value, 'weapon_ammo_capacity', capacity, setObj); clog(debug, timer, 'ammo =', ammo, 'setWeaponAmmo()'); @@ -12651,8 +12653,6 @@ } else {//weapon unarmed, save ammo state const ammostate = parseInt(value.weapon_ammo_reloads); const capacitystate = parseInt(value.weapon_ammo_capacity); - //setObj[`repeating_attr_${rowID}_ammostate`] = ammostate; - //setObj[`repeating_attr_${rowID}_capacitystate`] = capacitystate; writeValues(debug, timer, value, `repeating_attr_${rowID}_ammostate`, ammostate, setObj); writeValues(debug, timer, value, `repeating_attr_${rowID}_capacitystate`, capacitystate, setObj); clog(debug, timer, 'ammostate =', ammostate, 'setWeaponAmmo()'); @@ -13625,9 +13625,10 @@ let result = []; _.each(stats, (stat) => { const lowerstat = stat.toLowerCase(); - result[result.length] = (sourceAttr == lowerstat) ? - parseInt(setObj[`${skill}${lowerstat}state`]) || 0 : - parseInt(value[`${skill}${lowerstat}state`]) || 0; + result[result.length] = + isNaN(parseInt(setObj[`${skill}${lowerstat}state`])) ? + parseInt(value[`${skill}${lowerstat}state`]) || 0 : + parseInt(setObj[`${skill}${lowerstat}state`]) || 0; }); clog(debug, timer, 'stats:', stats, 'getStatStateArray()]'); clog(debug, timer, 'result =', result); @@ -13688,6 +13689,7 @@ function setSkillRoll(debug, timer, value, source, rowID, sourceAttr, level, setObj, type) { clog(debug, timer, 'level =', level, 'setSkillRoll(TEST)'); + clog(debug, timer, 'source =', source); const base = getStatRollBase(debug, timer, value, sourceAttr, setObj, type, source); const roll = getRollString(debug, timer, 'rolls', 'skillroll', 'Skill Roll', base + level); setObj[`repeating_skill_${rowID}_skillrollvalue`] = roll; @@ -13715,10 +13717,12 @@ clog(debug, timer, `value[${eventInfo.sourceAttribute}] =`, value[eventInfo.sourceAttribute]); } - function updateSkillRolls(debug, timer, value, source, skillIDs, sourceAttr, setObj) { + function updateSkillRolls(debug, timer, value, skillIDs, sourceAttr, setObj) { + clog(debug, timer, 'sourceAttr =', sourceAttr, 'updateSkillRolls(TEST)'); const type = getStatType(value); _.each(skillIDs, id => { - const level = parseInt(value[`repeating_skill_${id}_level`]) || 0; + const source = `repeating_skill_${id}`; + const level = parseInt(value[`${source}_level`]) || 0; setSkillRoll(debug, timer, value, source, id, sourceAttr, level, setObj, type); }) } @@ -13844,7 +13848,7 @@ const type = getStatType(value); _.each(statarray,stat=>{ //setObj[`repeating_skill_${skillID}_${stat}state`] = 1; - writeValues(debug, timer, value, `repeating_skill_${skillID}_${stat}state`, 1 ,setObj); + writeValues(debug, timer, value, `repeating_skill_${skillID}_${stat}state`, 1 , setObj); }); const stats = type.major==1 ? statmajor: statallaspect; const sum = _.chain(stats) @@ -14348,7 +14352,8 @@ case 'statselection': case 'option': const state = parseInt(value[`${source}_${sourceAttr}`]) > 0 ? 0: 1; - setObj[`${source}_${sourceAttr}`] = state; + //setObj[`${source}_${sourceAttr}`] = state; + writeValues(debug, timer, value, `${source}_${sourceAttr}`, state, setObj); break; default: setSkillStatButtonState(debug, timer, value, match, sourceAttr, setObj); @@ -14429,9 +14434,9 @@ setDerivedValue(debug, timer, attrdb, value, setObj, 'energy'); setDerivedValue(debug, timer, attrdb, value, setObj, 'sanity'); setDerivedValue(debug, timer, attrdb, value, setObj, 'social'); - setTotalShock(debug, timer, attrdb, setObj, sourceAttr); - setTotalMovement(debug, timer, value, attrdb, setObj, sourceAttr); - updateSkillRolls(debug, timer, value, source, skillIDs, sourceAttr, setObj); + setTotalShock(debug, timer, value, attrdb, setObj); + setTotalMovement(debug, timer, value, attrdb, setObj); + updateSkillRolls(debug, timer, value, skillIDs, sourceAttr, setObj); break; } break; From fc490e03d227e4673f9350b45452c32cd6206e40 Mon Sep 17 00:00:00 2001 From: Darth-John <77751557+Darth-John@users.noreply.github.com> Date: Mon, 14 Mar 2022 14:05:40 -0700 Subject: [PATCH 04/10] Fixed default dynamic roll string New characters will now be able to roll 2d6 from roll menu (previously had no default value set). --- BESM4eExtras/BESM4eExtras.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BESM4eExtras/BESM4eExtras.html b/BESM4eExtras/BESM4eExtras.html index 459425c605..9c22c8bc96 100644 --- a/BESM4eExtras/BESM4eExtras.html +++ b/BESM4eExtras/BESM4eExtras.html @@ -938,7 +938,7 @@