From 07f9d4a9bc64338c9586ca9814dd1023c5a5ce7e Mon Sep 17 00:00:00 2001 From: WBHarry Date: Wed, 20 Aug 2025 19:09:46 +0200 Subject: [PATCH] . --- .../sheets/api/application-mixin.mjs | 1 - module/applications/sheets/api/base-item.mjs | 9 ++-- module/data/actor/character.mjs | 12 ++--- module/data/item/base.mjs | 50 ++++++------------- module/data/item/feature.mjs | 18 ------- 5 files changed, 24 insertions(+), 66 deletions(-) diff --git a/module/applications/sheets/api/application-mixin.mjs b/module/applications/sheets/api/application-mixin.mjs index ab1c9ab2..bdcee27a 100644 --- a/module/applications/sheets/api/application-mixin.mjs +++ b/module/applications/sheets/api/application-mixin.mjs @@ -591,7 +591,6 @@ export default function DHApplicationMixin(Base) { if (featureOnCharacter) { systemData = { originItemType: this.document.type, - originId: this.document.id, identifier: this.document.system.isMulticlass ? 'multiclass' : null }; } diff --git a/module/applications/sheets/api/base-item.mjs b/module/applications/sheets/api/base-item.mjs index 9d7df6ee..e722b72e 100644 --- a/module/applications/sheets/api/base-item.mjs +++ b/module/applications/sheets/api/base-item.mjs @@ -149,12 +149,12 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { const { type } = target.dataset; const cls = foundry.documents.Item.implementation; + const multiclass = this.document.system.isMulticlass ? 'multiclass' : null; let systemData = {}; if (this.document.parent?.type === 'character') { systemData = { originItemType: this.document.type, - originId: this.document.id, - identifier: this.document.system.isMulticlass ? 'multiclass' : null + identifier: multiclass ?? type }; } @@ -275,14 +275,15 @@ export default class DHBaseItemSheet extends DHApplicationMixin(ItemSheetV2) { if (this.document.parent?.type === 'character') { const itemData = item.toObject(); + const multiclass = this.document.system.isMulticlass ? 'multiclass' : null; item = await cls.create( { ...itemData, + _stats: { compendiumSource: this.document.uuid }, system: { ...itemData.system, originItemType: this.document.type, - originId: this.document.id, - identifier: this.document.system.isMulticlass ? 'multiclass' : null + identifier: multiclass ?? target.dataset.type } }, { parent: this.document.parent } diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index bb6a8c65..7dd7993c 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -444,16 +444,12 @@ export default class DhCharacter extends BaseDataActor { } else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) { if (this.class.subclass) { const subclassState = this.class.subclass.system.featureState; - const subclass = - item.system.identifier === 'multiclass' ? this.multiclass.subclass : this.class.subclass; - const featureType = subclass - ? (subclass.system.features.find(x => x.item?.uuid === item.uuid)?.type ?? null) - : null; if ( - featureType === CONFIG.DH.ITEM.featureSubTypes.foundation || - (featureType === CONFIG.DH.ITEM.featureSubTypes.specialization && subclassState >= 2) || - (featureType === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3) + item.system.identifier === CONFIG.DH.ITEM.featureSubTypes.foundation || + (item.system.identifier === CONFIG.DH.ITEM.featureSubTypes.specialization && + subclassState >= 2) || + (item.system.identifier === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3) ) { subclassFeatures.push(item); } diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index f0b22b44..f333537b 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -144,50 +144,30 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel { } if (this.actor && this.actor.type === 'character' && this.features) { - const featureUpdates = {}; + const features = []; for (let f of this.features) { const fBase = f.item ?? f; const feature = fBase.system ? fBase : await foundry.utils.fromUuid(fBase.uuid); - const createData = foundry.utils.mergeObject( - feature.toObject(), - { - system: { - originItemType: this.parent.type, - originId: data._id, - identifier: this.isMulticlass ? 'multiclass' : null - } - }, - { inplace: false } + const multiclass = this.isMulticlass ? 'multiclass' : null; + features.push( + foundry.utils.mergeObject( + feature.toObject(), + { + _stats: { compendiumSource: fBase.uuid }, + system: { + originItemType: this.parent.type, + identifier: multiclass ?? (f.item ? f.type : null) + } + }, + { inplace: false } + ) ); - const [doc] = await this.actor.createEmbeddedDocuments('Item', [createData]); - - if (!featureUpdates.features) - featureUpdates.features = this.features.map(x => (x.item ? { ...x, item: x.item.uuid } : x.uuid)); - - if (f.item) { - const existingFeature = featureUpdates.features.find(x => x.item === f.item.uuid); - existingFeature.item = doc.uuid; - } else { - const replaceIndex = featureUpdates.features.findIndex(x => x === f.uuid); - featureUpdates.features.splice(replaceIndex, 1, doc.uuid); - } } - await this.updateSource(featureUpdates); + await this.actor.createEmbeddedDocuments('Item', features); } } - 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) - ); - } - async _preUpdate(changed, options, userId) { const allowed = await super._preUpdate(changed, options, userId); if (allowed === false) return false; diff --git a/module/data/item/feature.mjs b/module/data/item/feature.mjs index 13c1d149..6e1aab41 100644 --- a/module/data/item/feature.mjs +++ b/module/data/item/feature.mjs @@ -1,5 +1,4 @@ import BaseDataItem from './base.mjs'; -import { ActionField, ActionsField } from '../fields/actionField.mjs'; export default class DHFeature extends BaseDataItem { /** @inheritDoc */ @@ -30,24 +29,7 @@ export default class DHFeature extends BaseDataItem { nullable: true, initial: null }), - originId: new fields.StringField({ nullable: true, initial: null }), identifier: new fields.StringField() }; } - - get spellcastingModifier() { - let traitValue = 0; - if (this.actor && this.originId && ['class', 'subclass'].includes(this.originItemType)) { - if (this.originItemType === 'subclass') { - traitValue = - this.actor.system.traits[this.actor.items.get(this.originId).system.spellcastingTrait]?.value ?? 0; - } else { - const { value: multiclass, subclass } = this.actor.system.multiclass; - const selectedSubclass = multiclass?.id === this.originId ? subclass : this.actor.system.class.subclass; - traitValue = this.actor.system.traits[selectedSubclass.system.spellcastingTrait]?.value ?? 0; - } - } - - return traitValue; - } }