Begin making the pre-embed quantity change logic based on source IDs and not name
This commit is contained in:
parent
6a355e63c0
commit
bad95f8c18
3 changed files with 44 additions and 14 deletions
|
|
@ -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;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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 = {
|
||||
|
|
|
|||
|
|
@ -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) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue