From 286ee72c9f067196d61d5b7b17a7cd01cfeed183 Mon Sep 17 00:00:00 2001 From: Vlyan Date: Sat, 22 May 2021 23:33:24 +0200 Subject: [PATCH] Working on 0.8.x - Advancement bonus management for onDrop and delete --- system/scripts/actors/base-sheet.js | 28 ++++++++++++++++++++++++---- system/scripts/items/title-sheet.js | 3 +++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/system/scripts/actors/base-sheet.js b/system/scripts/actors/base-sheet.js index d32c67c..70d6687 100644 --- a/system/scripts/actors/base-sheet.js +++ b/system/scripts/actors/base-sheet.js @@ -215,6 +215,15 @@ export class BaseSheetL5r5e extends ActorSheet { await this.actor.addBonus(item); break; + case "title": + // Add embed advancements bonus + for (let [embedId, embedItem] of item.data.data.items) { + if (embedItem.data.type === "advancement") { + await this.actor.addBonus(embedItem); + } + } + break; + case "technique": // School_ability and mastery_ability, allow only 1 per type if (CONFIG.l5r5e.techniques.get(item.data.data.technique_type)?.type === "school") { @@ -258,7 +267,7 @@ export class BaseSheetL5r5e extends ActorSheet { return; } - return this._onDropItemCreate(item.data.toObject(false)); + return this._onDropItemCreate(item.data.toJSON()); } /** @@ -487,9 +496,20 @@ export class BaseSheetL5r5e extends ActorSheet { } const callback = async () => { - // Specific advancements, remove 1 to selected ring/skill - if (tmpItem.type === "advancement") { - await this.actor.removeBonus(tmpItem); + switch (tmpItem.type) { + case "advancement": + // Remove advancements bonus (1 to selected ring/skill) + await this.actor.removeBonus(tmpItem); + break; + + case "title": + // Remove embed advancements bonus + for (let [embedId, embedItem] of tmpItem.data.data.items) { + if (embedItem.data.type === "advancement") { + await this.actor.removeBonus(embedItem); + } + } + break; } return this.actor.deleteEmbeddedDocuments("Item", [itemId]); }; diff --git a/system/scripts/items/title-sheet.js b/system/scripts/items/title-sheet.js index cea38d7..948849e 100644 --- a/system/scripts/items/title-sheet.js +++ b/system/scripts/items/title-sheet.js @@ -106,6 +106,9 @@ export class TitleSheetL5r5e extends ItemSheetL5r5e { async _addSubItem(event) { // Show Dialog const selectedType = await game.l5r5e.HelpersL5r5e.showSubItemDialog(["advancement", "technique"]); + if (!selectedType) { + return; + } // Create the new Item const itemId = await this.document.addEmbedItem(