diff --git a/src/lang/en.json b/src/lang/en.json index 726f73d..d5c011e 100644 --- a/src/lang/en.json +++ b/src/lang/en.json @@ -169,6 +169,7 @@ "OSE.armor.heavy": "Heavy", "OSE.armor.shield": "Shield", + "OSE.spells.spend": "{speaker} is casting {name}!", "OSE.spells.Memorized": "Memorized", "OSE.spells.Cast": "Cast", "OSE.spells.Range": "Range", @@ -177,6 +178,7 @@ "OSE.spells.Duration": "Duration", "OSE.spells.Level": "Level", "OSE.spells.Save": "Save", + "OSE.spells.ResetSlots": "Reset Spell slots", "OSE.abilities.Requirements": "Requirements", diff --git a/src/module/actor/actor-sheet.js b/src/module/actor/actor-sheet.js index 4b5eeec..3a0db27 100644 --- a/src/module/actor/actor-sheet.js +++ b/src/module/actor/actor-sheet.js @@ -52,7 +52,7 @@ export class OseActorSheet extends ActorSheet { sortedSpells[lvl].push(spells[i]); } data.slots = { - used: slots + used: slots, }; // Assign and return data.owned = { @@ -94,6 +94,18 @@ export class OseActorSheet extends ActorSheet { } } + async _resetSpells(event) { + let spells = $(event.currentTarget).closest(".inventory.spells").find(".item"); + spells.each((_, el) => { + let itemId = el.dataset.itemId; + const item = this.actor.getOwnedItem(itemId); + item.update({ + _id: item.id, + "data.cast": item.data.data.memorized, + }); + }); + } + activateListeners(html) { // Item summaries html @@ -117,12 +129,16 @@ export class OseActorSheet extends ActorSheet { const li = $(ev.currentTarget).parents(".item"); const item = this.actor.getOwnedItem(li.data("itemId")); if (item.type == "weapon") { - if (this.actor.data.type === 'monster') { - item.update({data: {counter: {value: item.data.data.counter.value - 1}}}) + if (this.actor.data.type === "monster") { + item.update({ + data: { counter: { value: item.data.data.counter.value - 1 } }, + }); } - item.rollWeapon({event: ev}); + item.rollWeapon({ event: ev }); + } else if (item.type == "spell") { + item.spendSpell(); } else { - item.rollFormula({event: ev}); + item.rollFormula({ event: ev }); } }); @@ -135,10 +151,11 @@ export class OseActorSheet extends ActorSheet { let actorObject = this.actor; let element = event.currentTarget; let attack = element.parentElement.parentElement.dataset.attack; - actorObject.rollAttack( - { label: this.actor.name, type: attack }, - ev - ); + actorObject.rollAttack({ label: this.actor.name, type: attack }, ev); + }); + + html.find(".spells .item-reset").click((ev) => { + this._resetSpells(ev); }); html.find(".hit-dice .attribute-name a").click((ev) => { diff --git a/src/module/actor/monster-sheet.js b/src/module/actor/monster-sheet.js index d3f2a08..5220fe8 100644 --- a/src/module/actor/monster-sheet.js +++ b/src/module/actor/monster-sheet.js @@ -95,13 +95,23 @@ export class OseActorSheetMonster extends OseActorSheet { } async _resetCounters(event) { - $(event.currentTarget).closest('.abilities').find(".item").each(async (_, el) => { - let itemId = el.dataset.itemId; - const item = this.actor.getOwnedItem(itemId); - if (item.data.type == 'weapon') { - await item.update({"data.counter.value": parseInt(item.data.data.counter.max)}); - } - }) + $(event.currentTarget) + .closest(".abilities") + .find(".item") + .each(async (_, el) => { + let itemId = el.dataset.itemId; + const item = this.actor.getOwnedItem(itemId); + if (item.data.type == "weapon") { + await item.update({ + _id: item.id, + data: { + counter: { + value: parseInt(item.data.data.counter.max), + }, + }, + }); + } + }); } /** @@ -155,9 +165,9 @@ export class OseActorSheetMonster extends OseActorSheet { return this.actor.createOwnedItem(itemData, {}); }); - html.find('.item-reset').click(ev => { + html.find(".item-reset").click((ev) => { this._resetCounters(ev); - }) + }); html.find(".morale-check a").click((ev) => { let actorObject = this.actor; diff --git a/src/module/item/entity.js b/src/module/item/entity.js index 0cd04d0..324f666 100644 --- a/src/module/item/entity.js +++ b/src/module/item/entity.js @@ -131,6 +131,14 @@ export class OseItem extends Item { }); } + spendSpell() { + this.update({data: { + cast: this.data.data.cast - 1 + }}).then(() => { + this.roll({skipDialog: true}) + }) + } + /** * Roll the item to Chat, creating a chat card which contains follow up attack or damage roll options * @return {Promise} diff --git a/src/templates/actors/monster-sheet.html b/src/templates/actors/monster-sheet.html index 88abee4..0e286a3 100644 --- a/src/templates/actors/monster-sheet.html +++ b/src/templates/actors/monster-sheet.html @@ -30,8 +30,11 @@ {{/if}}