Begin making the pre-embed quantity change logic based on source IDs and not name

This commit is contained in:
Oliver-Akins 2024-03-21 21:24:26 -06:00
parent 6a355e63c0
commit bad95f8c18
3 changed files with 44 additions and 14 deletions

View file

@ -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;
};
};