diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index 0b129db1..ccf3cd1f 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -124,43 +124,17 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { } if (this.actor && this.actor.type === 'character' && this.features) { - /* Actions won't get created during createEmbeddedDocuments because they need the parent to be the newly created feature. - If this can be fixed somehow, we can just create all at the same time instead of one by one. - */ - for (let listFeature of this.features) { - const feature = listFeature.item ?? listFeature; - const [doc] = await this.actor.createEmbeddedDocuments('Item', [ - { - ...feature, - effects: feature.effects.map(x => x.toObject()), - system: { - ...feature.system, - originItemType: this.parent.type, - originId: data._id, - identifier: feature.identifier, - subType: feature.item ? feature.type : undefined - } + for (let f of this.features) { + const feature = f.item ?? f; + const createData = foundry.utils.mergeObject(feature.toObject(), { + system: { + originItemType: this.parent.type, + originId: data._id, + identifier: feature.identifier, + subType: feature.item ? feature.type : undefined } - ]); - - const actions = feature.system.actions.reduce((acc, oldAction) => { - const cls = game.system.api.models.actions.actionsTypes[oldAction.type]; - const action = new cls( - { - ...oldAction.toObject(), - ...cls.getSourceConfig(doc) - }, - { - parent: doc - } - ); - - acc[action.id] = action.toObject(); - - return acc; - }, {}); - - await doc.updateSource({ 'system.actions': actions }); + }, { inplace: false }); + await this.actor.createEmbeddedDocuments('Item', [createData]); } } }