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 { export class DotDungeonActor extends Actor {
async createEmbeddedItem(defaults, opts = {}) { async createEmbeddedItem(defaults, opts = {}) {
let items = await this.createEmbeddedDocuments(`Item`, defaults); 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;
};
}; };

View file

@ -45,20 +45,20 @@ export class Player extends DotDungeonActor {
* TODO: Find item based of the source's ID, not name * TODO: Find item based of the source's ID, not name
* @param {DotDungeonItem} item * @param {DotDungeonItem} item
*/ */
async preUntypedEmbed(item) { // async preUntypedEmbed(item) {
let inventoryItem = this.itemTypes.untyped.find(i => i.name === item.name); // let inventoryItem = this.itemTypes.untyped.find(i => i.name === item.name);
if (inventoryItem) { // if (inventoryItem) {
inventoryItem.update({"system.quantity": inventoryItem.system.quantity + 1}); // inventoryItem.update({"system.quantity": inventoryItem.system.quantity + 1});
ui.notifications.info( // ui.notifications.info(
game.i18n.format( // game.i18n.format(
`dotdungeon.notification.info.increased-item-quantity`, // `dotdungeon.notification.info.increased-item-quantity`,
{ name: inventoryItem.name } // { name: inventoryItem.name }
), // ),
{ console: false } // { console: false }
); // );
return false; // return false;
}; // };
}; // };
getRollData() { getRollData() {
const data = { const data = {

View file

@ -1,4 +1,10 @@
export class DotDungeonItem extends Item { export class DotDungeonItem extends Item {
async _preCreate() {
if (this.isEmbedded) {
return await this.actor?.preItemEmbed(this);
};
};
get usedCapacity() { get usedCapacity() {
let capacity = 0; let capacity = 0;
if (this.system.uses_inventory_slot && this.system.quantity > 0) { if (this.system.uses_inventory_slot && this.system.quantity > 0) {