mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-17 23:49:02 +01:00
Fixed so that features get their actions and effects
This commit is contained in:
parent
2608c4a5ae
commit
5df1d908a9
2 changed files with 48 additions and 25 deletions
|
|
@ -397,6 +397,7 @@ export default class DhCharacter extends BaseDataActor {
|
||||||
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.class.id) {
|
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.class.id) {
|
||||||
classFeatures.push(item);
|
classFeatures.push(item);
|
||||||
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) {
|
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.subclass.id) {
|
||||||
|
if (this.class.subclass) {
|
||||||
const subclassState = this.class.subclass.system.featureState;
|
const subclassState = this.class.subclass.system.featureState;
|
||||||
const subType = item.system.subType;
|
const subType = item.system.subType;
|
||||||
if (
|
if (
|
||||||
|
|
@ -406,6 +407,7 @@ export default class DhCharacter extends BaseDataActor {
|
||||||
) {
|
) {
|
||||||
subclassFeatures.push(item);
|
subclassFeatures.push(item);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.companion.id) {
|
} else if (item.system.originItemType === CONFIG.DH.ITEM.featureTypes.companion.id) {
|
||||||
companionFeatures.push(item);
|
companionFeatures.push(item);
|
||||||
} else if (item.type === 'feature' && !item.system.type) {
|
} else if (item.type === 'feature' && !item.system.type) {
|
||||||
|
|
|
||||||
|
|
@ -122,26 +122,47 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
||||||
|
|
||||||
this.updateSource({ actions: [action] });
|
this.updateSource({ actions: [action] });
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
_onCreate(data, _, userId) {
|
if (this.actor && this.actor.type === 'character' && this.features) {
|
||||||
if (userId !== game.user.id) return;
|
/* 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.
|
||||||
if (!this.actor || this.actor.type !== 'character' || !this.features) return;
|
*/
|
||||||
|
for (let listFeature of this.features) {
|
||||||
this.actor.createEmbeddedDocuments(
|
const feature = listFeature.item ?? listFeature;
|
||||||
'Item',
|
const docs = await this.actor.createEmbeddedDocuments('Item', [
|
||||||
this.features.map(feature => ({
|
{
|
||||||
...(feature.item ?? feature),
|
...feature,
|
||||||
|
effects: feature.effects.map(x => x.toObject()),
|
||||||
system: {
|
system: {
|
||||||
...(feature.item?.system ?? feature.system),
|
...feature.system,
|
||||||
originItemType: this.parent.type,
|
originItemType: this.parent.type,
|
||||||
originId: data._id,
|
originId: data._id,
|
||||||
identifier: feature.identifier,
|
identifier: feature.identifier,
|
||||||
subType: feature.item ? feature.type : undefined
|
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(docs[0])
|
||||||
|
},
|
||||||
|
{
|
||||||
|
parent: docs[0]
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
acc[action.id] = action.toObject();
|
||||||
|
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
|
||||||
|
await docs[0].updateSource({ 'system.actions': actions });
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async _preDelete() {
|
async _preDelete() {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue