diff --git a/module/documents/Actor/GenericActor.mjs b/module/documents/Actor/GenericActor.mjs index 8229dbd..7debd74 100644 --- a/module/documents/Actor/GenericActor.mjs +++ b/module/documents/Actor/GenericActor.mjs @@ -1,3 +1,5 @@ +import { DotDungeonItem } from "../Item/GenericItem.mjs"; + export class DotDungeonActor extends Actor { async createEmbeddedItem(defaults, opts = {}) { let items = await this.createEmbeddedDocuments(`Item`, defaults); @@ -14,4 +16,26 @@ export class DotDungeonActor extends Actor { }; }; }; + + /** @param {DotDungeonItem} item */ + async preItemEmbed(item) { + console.log(`preEmbed`, item._source._id); + let type = item.type[0].toUpperCase() + item.type.slice(1); + if (this[`pre${type}Embed`]) { + return await this[`pre${type}Embed`](item); + }; + let embedded = this.itemTypes[item.type].find(i => i._source._id === item._source._id); + if (embedded) { + await embedded.update({"system.quantity": embedded.system.quantity + 1}); + ui.notifications.info( + game.i18n.format( + `dotdungeon.notification.info.increased-item-quantity`, + { name: inventoryItem.name } + ), + { console: false } + ); + return false; + }; + return true; + }; }; diff --git a/module/documents/Actor/Player.mjs b/module/documents/Actor/Player.mjs index d20d660..404283f 100644 --- a/module/documents/Actor/Player.mjs +++ b/module/documents/Actor/Player.mjs @@ -45,20 +45,20 @@ export class Player extends DotDungeonActor { * TODO: Find item based of the source's ID, not name * @param {DotDungeonItem} item */ - async preUntypedEmbed(item) { - let inventoryItem = this.itemTypes.untyped.find(i => i.name === item.name); - if (inventoryItem) { - inventoryItem.update({"system.quantity": inventoryItem.system.quantity + 1}); - ui.notifications.info( - game.i18n.format( - `dotdungeon.notification.info.increased-item-quantity`, - { name: inventoryItem.name } - ), - { console: false } - ); - return false; - }; - }; + // async preUntypedEmbed(item) { + // let inventoryItem = this.itemTypes.untyped.find(i => i.name === item.name); + // if (inventoryItem) { + // inventoryItem.update({"system.quantity": inventoryItem.system.quantity + 1}); + // ui.notifications.info( + // game.i18n.format( + // `dotdungeon.notification.info.increased-item-quantity`, + // { name: inventoryItem.name } + // ), + // { console: false } + // ); + // return false; + // }; + // }; getRollData() { const data = { diff --git a/module/documents/Item/GenericItem.mjs b/module/documents/Item/GenericItem.mjs index 50d1fee..b52ddcd 100644 --- a/module/documents/Item/GenericItem.mjs +++ b/module/documents/Item/GenericItem.mjs @@ -1,4 +1,10 @@ export class DotDungeonItem extends Item { + async _preCreate() { + if (this.isEmbedded) { + return await this.actor?.preItemEmbed(this); + }; + }; + get usedCapacity() { let capacity = 0; if (this.system.uses_inventory_slot && this.system.quantity > 0) {