From ca55ffeff816ac224921aa692db3e2715ba66e38 Mon Sep 17 00:00:00 2001 From: Melon-PieldeSapo Date: Sat, 23 Nov 2024 00:53:12 +0100 Subject: [PATCH] basic swarm setting --- module/actor/creature-sheet.js | 39 +++++++++++++++++++ module/settings/creature-settings.js | 15 +++++++ templates/actor/creature-sheet.html | 17 ++++++-- .../dialogs/creature-settings-dialog.html | 4 ++ 4 files changed, 72 insertions(+), 3 deletions(-) diff --git a/module/actor/creature-sheet.js b/module/actor/creature-sheet.js index de9018b..e777acb 100644 --- a/module/actor/creature-sheet.js +++ b/module/actor/creature-sheet.js @@ -91,6 +91,15 @@ export class MothershipCreatureSheet extends 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. * @@ -176,6 +185,11 @@ export class MothershipCreatureSheet extends ActorSheet { } else { item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); } + if (this.actor.system.swarm && this.actor.system.swarm.enabled){ + //replace the roll damage for swarm actors + let new_dice_ammount = item.system.damage.match(/([0-9]+)d[0-9]+/i)[1]*this.getWoundsLeft(html); + item.system.damage = item.system.damage.replace(/([0-9]+)(d[0-9]+)/i,`${new_dice_ammount}$2`); + } this.actor.rollCheck(null, 'low', 'combat', null, null, item); }); @@ -188,6 +202,11 @@ export class MothershipCreatureSheet extends ActorSheet { } else { item = duplicate(this.actor.getEmbeddedDocument("Item", li.dataset.itemId)); } + if (this.actor.system.swarm && this.actor.system.swarm.enabled){ + //replace the roll damage for swarm actors + let new_dice_ammount = item.system.damage.match(/([0-9]+)d[0-9]+/i)[1]*this.getWoundsLeft(html); + item.system.damage = item.system.damage.replace(/([0-9]+)(d[0-9]+)/i,`${new_dice_ammount}$2`); + } this.actor.rollCheck(null, null, 'damage', null, null, item); }); @@ -264,6 +283,26 @@ export class MothershipCreatureSheet extends 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/settings/creature-settings.js b/module/settings/creature-settings.js index e55868d..dbdb932 100644 --- a/module/settings/creature-settings.js +++ b/module/settings/creature-settings.js @@ -90,6 +90,15 @@ export class DLCreatureSettings extends FormApplication { "system.stats.sanity.enabled": ev.currentTarget.checked }); }); + html.find(`input[type=checkbox][id="system.swarm.enabled"]`).click(ev => { + if (ev.currentTarget.checked) { + const sanity = html.find(`input[type=checkbox][id="system.swarm.enabled"]`).prop('checked', true); + } + + this.object.update({ + "system.swarm.enabled": ev.currentTarget.checked + }); + }); } /** @@ -120,6 +129,12 @@ export class DLCreatureSettings extends FormApplication { "data.stats.armor.enabled": true }); } + // swarm + if (this.object.system.swarm.enabled) { + await this.object.update({ + "data.swarm.enabled": true + }); + } await this.object.updateEmbeddedEntity("OwnedItem", update); diff --git a/templates/actor/creature-sheet.html b/templates/actor/creature-sheet.html index 751b740..91aed88 100644 --- a/templates/actor/creature-sheet.html +++ b/templates/actor/creature-sheet.html @@ -9,10 +9,17 @@
- COMBAT W* + + {{else}} + COMBAT - + {{/if}}
{{/if}} @@ -169,7 +176,11 @@
  • Name
    -
    Damage
    + {{#if system.swarm.enabled}} +
    Damage w*
    + {{else}} +
    Damage
    + {{/if}}
    Ammo
    Shots
    Range
    diff --git a/templates/dialogs/creature-settings-dialog.html b/templates/dialogs/creature-settings-dialog.html index fc63b7e..b90ba5e 100644 --- a/templates/dialogs/creature-settings-dialog.html +++ b/templates/dialogs/creature-settings-dialog.html @@ -26,6 +26,10 @@ +
    + + +