From 0a81e46725c99c398bfd5ff279b0882914acc44d Mon Sep 17 00:00:00 2001 From: U~man Date: Thu, 9 Jul 2020 18:29:19 +0200 Subject: [PATCH] ENH: Attack counter --- src/module/actor/actor-sheet.js | 32 +++-------- src/module/actor/entity.js | 1 - src/module/actor/monster-sheet.js | 54 ++++++++++++------- src/module/dice.js | 1 - src/module/item/entity.js | 8 +-- src/template.json | 6 ++- .../partials/monster-attributes-tab.html | 6 +++ 7 files changed, 55 insertions(+), 53 deletions(-) diff --git a/src/module/actor/actor-sheet.js b/src/module/actor/actor-sheet.js index acc27d2..dd6e61f 100644 --- a/src/module/actor/actor-sheet.js +++ b/src/module/actor/actor-sheet.js @@ -107,29 +107,6 @@ export class OseActorSheet extends ActorSheet { actorObject.rollSave(save, { event: event }); }); - //Toggle Spells - html.find(".item-cast").click(async (ev) => { - const li = $(ev.currentTarget).parents(".item"); - const item = this.actor.getOwnedItem(li.data("itemId")); - await this.actor.updateOwnedItem({ - _id: li.data("itemId"), - data: { - cast: !item.data.data.cast, - }, - }); - }); - //Toggle Equipment - html.find(".item-memorize").click(async (ev) => { - const li = $(ev.currentTarget).parents(".item"); - const item = this.actor.getOwnedItem(li.data("itemId")); - await this.actor.updateOwnedItem({ - _id: li.data("itemId"), - data: { - memorized: !item.data.data.memorized, - }, - }); - }); - html.find(".item .item-controls .item-show").click(async (ev) => { const li = $(ev.currentTarget).parents(".item"); const item = this.actor.getOwnedItem(li.data("itemId")); @@ -140,9 +117,12 @@ export class OseActorSheet extends ActorSheet { const li = $(ev.currentTarget).parents(".item"); const item = this.actor.getOwnedItem(li.data("itemId")); if (item.type == "weapon") { - item.rollWeapon(); + item.rollWeapon({event: ev}); + if (this.actor.data.type === 'monster') { + item.update({data: {counter: {value: item.data.data.counter.value - 1}}}) + } } else { - item.rollFormula(); + item.rollFormula({event: ev}); } }); @@ -157,7 +137,7 @@ export class OseActorSheet extends ActorSheet { let attack = element.parentElement.parentElement.dataset.attack; actorObject.rollAttack( { label: this.actor.name, type: attack }, - { event: event } + ev ); }); diff --git a/src/module/actor/entity.js b/src/module/actor/entity.js index d842d74..d71fe4b 100644 --- a/src/module/actor/entity.js +++ b/src/module/actor/entity.js @@ -246,7 +246,6 @@ export class OseActor extends Actor { rollAttack(attData, options = {}) { const data = this.data.data; - const rollParts = ["1d20"]; const dmgParts = []; diff --git a/src/module/actor/monster-sheet.js b/src/module/actor/monster-sheet.js index 8f7c827..c5796ac 100644 --- a/src/module/actor/monster-sheet.js +++ b/src/module/actor/monster-sheet.js @@ -38,31 +38,29 @@ export class OseActorSheetMonster extends OseActorSheet { */ getData() { const data = super.getData(); - + // Settings - data.config.morale = game.settings.get('ose', 'morale'); + data.config.morale = game.settings.get("ose", "morale"); return data; } /* -------------------------------------------- */ - async _chooseItemType( - choices = ['weapon', 'armor', 'shield', 'gear'], - ) { - let templateData = { upper: '', lower: '', types: choices }, + async _chooseItemType(choices = ["weapon", "armor", "shield", "gear"]) { + let templateData = { upper: "", lower: "", types: choices }, dlg = await renderTemplate( - 'templates/sidebar/entity-create.html', - templateData, + "templates/sidebar/entity-create.html", + templateData ); //Create Dialog window return new Promise((resolve) => { new Dialog({ - title: '', + title: "", content: dlg, buttons: { ok: { - label: game.i18n.localize('OSE.Ok'), + label: game.i18n.localize("OSE.Ok"), icon: '', callback: (html) => { resolve({ @@ -73,14 +71,28 @@ export class OseActorSheetMonster extends OseActorSheet { }, cancel: { icon: '', - label: game.i18n.localize('OSE.Cancel'), + label: game.i18n.localize("OSE.Cancel"), }, }, - default: 'ok', + default: "ok", }).render(true); }); } + async _onCountChange(event) { + event.preventDefault(); + const itemId = event.currentTarget.closest(".item").dataset.itemId; + const item = this.actor.getOwnedItem(itemId); + if (event.target.dataset.field == "value") { + return item.update({ + "data.counter.value": parseInt(event.target.value), + }); + } else if (event.target.dataset.field == "max") { + return item.update({ + "data.counter.max": parseInt(event.target.value), + }); + } + } /** * Activate event listeners using the prepared sheet HTML * @param html {HTML} The prepared HTML object ready to be rendered into the DOM @@ -109,22 +121,19 @@ export class OseActorSheetMonster extends OseActorSheet { const type = header.dataset.type; // item creation helper func - let createItem = function ( - type, - name = `New ${type.capitalize()}`, - ) { + let createItem = function (type, name = `New ${type.capitalize()}`) { const itemData = { name: name ? name : `New ${type.capitalize()}`, type: type, data: duplicate(header.dataset), }; - delete itemData.data['type']; + delete itemData.data["type"]; return itemData; }; - + // Getting back to main logic - if (type == 'choice') { - const choices = header.dataset.choices.split(','); + if (type == "choice") { + const choices = header.dataset.choices.split(","); this._chooseItemType(choices).then((dialogInput) => { const itemData = createItem(dialogInput.type, dialogInput.name); this.actor.createOwnedItem(itemData, {}); @@ -140,6 +149,11 @@ export class OseActorSheetMonster extends OseActorSheet { actorObject.rollMorale({ event: event }); }); + html + .find(".counter input") + .click((ev) => ev.target.select()) + .change(this._onCountChange.bind(this)); + html.find(".hp-roll").click((ev) => { let actorObject = this.actor; actorObject.rollHP({ event: event }); diff --git a/src/module/dice.js b/src/module/dice.js index ccdf77a..3567d39 100644 --- a/src/module/dice.js +++ b/src/module/dice.js @@ -240,7 +240,6 @@ export class OseDice { flavor: flavor, speaker: speaker }; - if (skipDialog) { return data.rollData.type === "Attack" ? OseDice.sendAttackRoll(rollData) diff --git a/src/module/item/entity.js b/src/module/item/entity.js index b3834c3..0cd04d0 100644 --- a/src/module/item/entity.js +++ b/src/module/item/entity.js @@ -45,7 +45,7 @@ export class OseItem extends Item { return data; } - rollWeapon(skipDialog) { + rollWeapon(options = {}) { let isNPC = this.actor.data.type != "character"; const data = this.data.data; let type = "raw"; @@ -66,7 +66,7 @@ export class OseItem extends Item { dmg: this.data.data.damage, bonus: data.bonus, }, - { event: { ctrlKey: skipDialog } } + options ); }, }, @@ -80,7 +80,7 @@ export class OseItem extends Item { label: this.name, dmg: this.data.data.damage, }, - { event: { ctrlKey: skipDialog } } + options ); }, }, @@ -95,7 +95,7 @@ export class OseItem extends Item { } this.actor.rollAttack( { type: type, label: this.name, dmg: data.damage, bonus: data.bonus }, - { event: { ctrlKey: skipDialog } } + options ); return true; diff --git a/src/template.json b/src/template.json index 105084b..94d748b 100644 --- a/src/template.json +++ b/src/template.json @@ -170,7 +170,11 @@ "melee": true, "cost": 0, "equipped": false, - "weight": 0 + "weight": 0, + "counter": { + "value": 0, + "max": 0 + } }, "armor": { "description": "", diff --git a/src/templates/actors/partials/monster-attributes-tab.html b/src/templates/actors/partials/monster-attributes-tab.html index d07fc3a..5d2ae23 100644 --- a/src/templates/actors/partials/monster-attributes-tab.html +++ b/src/templates/actors/partials/monster-attributes-tab.html @@ -113,6 +113,12 @@ {{item.name~}} + {{#if (eq item.type 'weapon')}} +
+ + / +
+ {{/if}}
{{#if ../../owner}}