From 935008201a367d64621859fa258b06bd6dc7f430 Mon Sep 17 00:00:00 2001 From: Chris Schmalz Date: Sun, 31 Aug 2025 11:26:35 -0700 Subject: [PATCH] Fixed swarm, fixed clickable dice hiding, all sheets update on change --- module/actor/actor-sheet.js | 3 +- module/actor/actor.js | 12 +++-- module/actor/creature-sheet.js | 72 +++++++++++++--------------- module/actor/ship-sheet-sbt.js | 3 +- module/actor/ship-sheet.js | 3 +- module/settings/creature-settings.js | 13 +++-- templates/actor/creature-sheet.html | 4 +- 7 files changed, 57 insertions(+), 53 deletions(-) diff --git a/module/actor/actor-sheet.js b/module/actor/actor-sheet.js index 73124f8..00d2963 100644 --- a/module/actor/actor-sheet.js +++ b/module/actor/actor-sheet.js @@ -12,7 +12,8 @@ export class MothershipActorSheet extends foundry.appv1.sheets.ActorSheet { template: "systems/mosh/templates/actor/actor-sheet.html", width: 820, height: 820, - tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }] + tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }], + submitOnChange: true } return foundry.utils.mergeObject(super.defaultOptions, options); } diff --git a/module/actor/actor.js b/module/actor/actor.js index 3edd98f..34495e5 100644 --- a/module/actor/actor.js +++ b/module/actor/actor.js @@ -96,6 +96,10 @@ export class MothershipActor extends Actor { } //set values system.bleeding.value = Number(bleedingValue ?? 0); + //keep combat updates for swarm types + if (system.swarm && system.swarm.enabled){ + system.stats.combat.value = system.swarm.combat.value * ( system.hits.max - system.hits.value ); + } } // Prepare Ship type specific data @@ -482,7 +486,6 @@ export class MothershipActor extends Actor { enrichedRollResult.dice.forEach(function (roll) { //add header for this roll diceBlock = diceBlock + ` -
`; @@ -545,7 +548,6 @@ export class MothershipActor extends Actor {
-
`; }); //set final roll variables in to template @@ -554,7 +556,9 @@ export class MothershipActor extends Actor {
${diceFormula}

${enrichedRollResult.total}

@@ -1447,7 +1451,7 @@ export class MothershipActor extends Actor { }; //create message const template = 'systems/mosh/templates/chat/rollCheck.html'; - const content = await foundry.applications.handlebars.renderTemplate(template, templateData); + const content = await foundry.applications.handlebars.renderTemplate(template, messageData); chatData.content = content; await ChatMessage.create(chatData); //log what was done diff --git a/module/actor/creature-sheet.js b/module/actor/creature-sheet.js index 3edcd4d..43b80b4 100644 --- a/module/actor/creature-sheet.js +++ b/module/actor/creature-sheet.js @@ -13,7 +13,8 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { template: "systems/mosh/templates/actor/creature-sheet.html", width: 820, height: 770, - tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }] + tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }], + submitOnChange: true }; return foundry.utils.mergeObject(super.defaultOptions, options); @@ -121,15 +122,6 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { return data.data; } - /** - * Get the remaining wounds of the creature - * @param {JQuery} html - * @returns {int} hits.max - hits.value - */ - getWoundsLeft(html){ - return html.find(`input[name="system.hits.max"]`).prop('value') - html.find(`input[name="system.hits.value"]`).prop('value'); - } - /** * Organize and classify Items for Character sheets. * @@ -142,6 +134,7 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { //console.log(sheetData); ///console.log("sheetdata Above"); // Initialize containers. + const abilities = []; const gear = []; const skills = []; const weapons = []; @@ -155,7 +148,9 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { let item = i.system; i.img = i.img || DEFAULT_TOKEN; - if (i.type === 'item') { + if (i.type === 'ability') { + abilities.push(i); + } else if (i.type === 'item') { gear.push(i); curWeight += item.weight * item.quantity; } else if (i.type === 'skill') { @@ -197,6 +192,7 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { } // Assign and return + actorData.abilities = abilities; actorData.gear = gear; actorData.skills = skills; actorData.armors = armors; @@ -363,20 +359,34 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { // Rollable Weapon html.find('.weapon-roll').click(ev => { - const li = ev.currentTarget.closest(".item"); - //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - var item; - item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null, 'low', 'combat', null, null, item); + const li = ev.currentTarget.closest(".item"); + var item; + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + //use swarm combat and damage settings if enabled + if (this.actor.system.swarm && this.actor.system.swarm.enabled){ + //calculate new damage string + let new_dice_ammount = item.system.damage.match(/([0-9]+)d[0-9]+/i)[1]*(this.actor.system.hits.max-this.actor.system.hits.value); + let swarm_damage_roll_string = item.system.damage.replace(/([0-9]+)(d[0-9]+)/i,`${new_dice_ammount}$2`); + this.actor.rollCheck(null, 'low', 'combat', null, null, item, swarm_damage_roll_string); + } else { + this.actor.rollCheck(null, 'low', 'combat', null, null, item); + } }); // Rollable Damage html.find('.dmg-roll').click(ev => { - const li = ev.currentTarget.closest(".item"); - //const item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - var item; - item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); - this.actor.rollCheck(null, null, 'damage', null, null, item); + const li = ev.currentTarget.closest(".item"); + var item; + item = foundry.utils.duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); + //use swarm combat and damage settings if enabled + if (this.actor.system.swarm && this.actor.system.swarm.enabled){ + //calculate new damage string + let new_dice_ammount = item.system.damage.match(/([0-9]+)d[0-9]+/i)[1]*(this.actor.system.hits.max-this.actor.system.hits.value); + let swarm_damage_roll_string = item.system.damage.replace(/([0-9]+)(d[0-9]+)/i,`${new_dice_ammount}$2`); + this.actor.rollCheck(null, null, 'damage', null, null, item, swarm_damage_roll_string); + } else { + this.actor.rollCheck(null, null, 'damage', null, null, item); + } }); // Rollable Item/Anything with a description that we want to click on. @@ -502,25 +512,7 @@ export class MothershipCreatureSheet extends foundry.appv1.sheets.ActorSheet { }); } - // update swarm combat - html.find(`input[name="system.swarm.combat.value"]`).change(ev => { - let new_combat_value = $(ev.currentTarget).prop('value') * this.getWoundsLeft(html); - this.actor.update({"system.stats.combat.value":new_combat_value}); - }); - html.find(`input[name="system.hits.max"]`).change(ev => { - //Max wounds changed -> calculate new combat stat - if (this.actor.system.swarm && this.actor.system.swarm.enabled){ - let new_combat_value = html.find(`input[name="system.swarm.combat.value"]`).prop('value') * this.getWoundsLeft(html); - this.actor.update({"system.stats.combat.value":new_combat_value}); - } - }); - html.find(`input[name="system.hits.value"]`).change(ev => { - //Current wounds changed -> calculate new combat stat - if (this.actor.system.swarm && this.actor.system.swarm.enabled){ - let new_combat_value = html.find(`input[name="system.swarm.combat.value"]`).prop('value') * this.getWoundsLeft(html); - this.actor.update({"system.stats.combat.value":new_combat_value}); - } - }); + } diff --git a/module/actor/ship-sheet-sbt.js b/module/actor/ship-sheet-sbt.js index 501fbab..684ff00 100644 --- a/module/actor/ship-sheet-sbt.js +++ b/module/actor/ship-sheet-sbt.js @@ -22,7 +22,8 @@ export class MothershipShipSheetSBT extends foundry.appv1.sheets.ActorSheet { tabs: [{ navSelector: "#sheet-tabs", contentSelector: "#sheet-body", initial: "character" }, { navSelector: "#side-tabs", contentSelector: "#side-body", initial: "close" }], // { navSelector: "#side-tabs", contentSelector: "#side-body", initial: "crew" }], - scrollY: [".sheet-body", "scroll-lock"] + scrollY: [".sheet-body", "scroll-lock"], + submitOnChange: true } return foundry.utils.mergeObject(super.defaultOptions, options); diff --git a/module/actor/ship-sheet.js b/module/actor/ship-sheet.js index eaca841..2ffa1cf 100644 --- a/module/actor/ship-sheet.js +++ b/module/actor/ship-sheet.js @@ -11,7 +11,8 @@ export class MothershipShipSheet extends foundry.appv1.sheets.ActorSheet { template: "systems/mosh/templates/actor/ship-sheet.html", width: 700, height: 650, - tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }] + tabs: [{ navSelector: ".sheet-tabs", contentSelector: ".sheet-body", initial: "character" }], + submitOnChange: true }); } diff --git a/module/settings/creature-settings.js b/module/settings/creature-settings.js index 690cc6c..3ec5b49 100644 --- a/module/settings/creature-settings.js +++ b/module/settings/creature-settings.js @@ -95,17 +95,22 @@ export class DLCreatureSettings extends FormApplication { "system.swarm.enabled": ev.currentTarget.checked }); - let new_combat = 0; + let swarm_combat = 0; + let current_combat = 0; + if (ev.currentTarget.checked) { + //set backup of current combat + swarm_combat = this.object.system.stats.combat.value; //calculate new combat stat based on wounds, - new_combat = this.object.system.swarm.combat.value * ( this.object.system.hits.max - this.object.system.hits.value); + current_combat = this.object.system.stats.combat.value * ( this.object.system.hits.max - this.object.system.hits.value); } else{ //revert back combat if swarm is disabled - new_combat = this.object.system.swarm.combat.value; + current_combat = this.object.system.swarm.combat.value; } this.object.update({ - "system.stats.combat.value":new_combat + "system.stats.combat.value":current_combat, + "system.swarm.combat.value":swarm_combat }); }); } diff --git a/templates/actor/creature-sheet.html b/templates/actor/creature-sheet.html index e0cfcf7..550fd56 100644 --- a/templates/actor/creature-sheet.html +++ b/templates/actor/creature-sheet.html @@ -13,8 +13,8 @@ {{#if system.swarm.enabled}} {{ localize 'Mosh.Combat' }} {{ localize 'Mosh.SwarmWoundShort' }} - + {{else}} {{ localize 'Mosh.Combat' }}