diff --git a/module/actor/creature-sheet.js b/module/actor/creature-sheet.js index 55d56c2..4ca5085 100644 --- a/module/actor/creature-sheet.js +++ b/module/actor/creature-sheet.js @@ -90,6 +90,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. * @@ -175,6 +184,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); }); @@ -187,6 +201,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); }); @@ -263,6 +282,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 4e2a3e8..bd15de8 100644 --- a/templates/actor/creature-sheet.html +++ b/templates/actor/creature-sheet.html @@ -9,8 +9,9 @@
+ {{ localize 'Mosh.Combat' }} + data-label="Combat">{{ localize 'Mosh.Combat' }}{{#if system.swarm.enabled}} {{ localize 'Mosh.SwarmWoundShort' }}
@@ -168,11 +169,14 @@
  1. +
    {{ localize 'Mosh.Name' }}
    +
    {{ localize 'Mosh.Damage' }}{{#if system.swarm.enabled}} {{ localize 'Mosh.SwarmWoundShort' }}{{/if}}
    {{ localize 'Mosh.Damage' }}
    {{ localize 'Mosh.Ammo' }}
    {{ localize 'Mosh.Shots' }}
    {{ localize 'Mosh.Range' }}
    +
    {{ localize 'Mosh.Add' }} diff --git a/templates/dialogs/creature-settings-dialog.html b/templates/dialogs/creature-settings-dialog.html index 094f8b5..1a7ab7d 100644 --- a/templates/dialogs/creature-settings-dialog.html +++ b/templates/dialogs/creature-settings-dialog.html @@ -26,6 +26,10 @@
    +
    + + +