Items now copy over their features to Character

This commit is contained in:
WBHarry 2025-07-05 18:54:57 +02:00
parent 261867a4cc
commit 3d735e6a09
13 changed files with 167 additions and 103 deletions

View file

@ -74,4 +74,32 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
);
this.updateSource({ actions: [action] });
}
_onCreate(data) {
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
this.actor.createEmbeddedDocuments(
'Item',
this.features.map(feature => ({
...feature,
system: {
...feature.system,
type: this.parent.type,
originId: data._id,
identifier: feature.identifier
}
}))
);
}
async _preDelete() {
if (!this.actor || this.actor.type !== 'character') return;
const items = this.actor.items.filter(item => item.system.originId === this.parent.id);
if (items.length > 0)
await this.actor.deleteEmbeddedDocuments(
'Item',
items.map(x => x.id)
);
}
}