mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-18 16:09:03 +01:00
Added LinkedItems for class. Added autoremoval of features and linkeditems when the related item is removed.
This commit is contained in:
parent
6336f2a60f
commit
df8b96e9bc
16 changed files with 202 additions and 118 deletions
|
|
@ -361,9 +361,9 @@ export default class DhCharacter extends BaseDataActor {
|
|||
const subclassState = this.class.subclass.system.featureState;
|
||||
const subType = item.system.subType;
|
||||
if (
|
||||
subType === CONFIG.DH.ITEM.featureSubTypes.foundation ||
|
||||
(subType === CONFIG.DH.ITEM.featureSubTypes.specialization && subclassState >= 2) ||
|
||||
(subType === CONFIG.DH.ITEM.featureSubTypes.mastery && subclassState >= 3)
|
||||
subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.foundation ||
|
||||
(subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.specialization && subclassState >= 2) ||
|
||||
(subType === CONFIG.DH.ITEM.itemLinkFeatureTypes.mastery && subclassState >= 3)
|
||||
) {
|
||||
subclassFeatures.push(item);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ export default class ItemLinksField extends foundry.data.fields.TypedObjectField
|
|||
constructor(options, context) {
|
||||
super(
|
||||
new foundry.data.fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.featureSubTypes,
|
||||
choices: CONFIG.DH.ITEM.itemLinkTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
|
|
|
|||
|
|
@ -20,12 +20,14 @@ export default class DHAncestry extends BaseDataItem {
|
|||
}
|
||||
|
||||
get primaryFeature() {
|
||||
return this.features.find(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.primary);
|
||||
return this.features.find(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.primary
|
||||
);
|
||||
}
|
||||
|
||||
get secondaryFeature() {
|
||||
return this.features.find(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.secondary
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.secondary
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,7 +10,8 @@ export default class DHArmor extends AttachableItem {
|
|||
label: 'TYPES.Item.armor',
|
||||
type: 'armor',
|
||||
hasDescription: true,
|
||||
isInventoryItem: true
|
||||
isInventoryItem: true,
|
||||
isItemLinkable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
hasResource: false,
|
||||
isQuantifiable: false,
|
||||
isInventoryItem: false,
|
||||
isItemLinkable: true
|
||||
isItemLinkable: false
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -143,13 +143,27 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
}
|
||||
|
||||
async _preDelete() {
|
||||
if (!this.actor || this.actor.type !== 'character') return;
|
||||
if (this.actor && this.actor.type === 'character') {
|
||||
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)
|
||||
);
|
||||
}
|
||||
|
||||
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)
|
||||
);
|
||||
if (this.metadata.isItemLinkable) {
|
||||
const linkEntries = Object.entries(this.itemLinks);
|
||||
for (let [uuid, type] of linkEntries) {
|
||||
const item = await foundry.utils.fromUuid(uuid);
|
||||
const path = CONFIG.DH.ITEM.itemLinkFeatureTypes[type] ? 'system.features' : 'system.linkedItems';
|
||||
await item.update({
|
||||
[path]: foundry.utils
|
||||
.getProperty(item, path)
|
||||
.filter(x => x.uuid !== this.parent.uuid)
|
||||
.map(x => x.uuid)
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,12 +28,8 @@ export default class DHClass extends BaseDataItem {
|
|||
}),
|
||||
evasion: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.GENERAL.evasion' }),
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||
linkedItems: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
|
||||
inventory: new fields.SchemaField({
|
||||
take: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
|
||||
choiceA: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
|
||||
choiceB: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false })
|
||||
}),
|
||||
characterGuide: new fields.SchemaField({
|
||||
suggestedTraits: new fields.SchemaField({
|
||||
agility: new fields.NumberField({ initial: 0, integer: true }),
|
||||
|
|
@ -42,21 +38,54 @@ export default class DHClass extends BaseDataItem {
|
|||
instinct: new fields.NumberField({ initial: 0, integer: true }),
|
||||
presence: new fields.NumberField({ initial: 0, integer: true }),
|
||||
knowledge: new fields.NumberField({ initial: 0, integer: true })
|
||||
}),
|
||||
suggestedPrimaryWeapon: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
suggestedSecondaryWeapon: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
suggestedArmor: new ForeignDocumentUUIDField({ type: 'Item' })
|
||||
})
|
||||
}),
|
||||
isMulticlass: new fields.BooleanField({ initial: false })
|
||||
};
|
||||
}
|
||||
|
||||
get hopeFeatures() {
|
||||
return this.features.filter(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.hope);
|
||||
return this.features.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.hope
|
||||
);
|
||||
}
|
||||
|
||||
get classFeatures() {
|
||||
return this.features.filter(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.class);
|
||||
return this.features.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.class
|
||||
);
|
||||
}
|
||||
|
||||
get suggestedPrimaryWeapon() {
|
||||
return this.linkedItems.find(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.primaryWeapon
|
||||
);
|
||||
}
|
||||
|
||||
get suggestedSecondaryWeapon() {
|
||||
return this.linkedItems.find(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.secondaryWeapon
|
||||
);
|
||||
}
|
||||
|
||||
get suggestedArmor() {
|
||||
return this.linkedItems.find(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.armor);
|
||||
}
|
||||
|
||||
get take() {
|
||||
return this.linkedItems.filter(x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.take);
|
||||
}
|
||||
|
||||
get choiceA() {
|
||||
return this.linkedItems.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.choiceA
|
||||
);
|
||||
}
|
||||
|
||||
get choiceB() {
|
||||
return this.linkedItems.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkTypes.choiceB
|
||||
);
|
||||
}
|
||||
|
||||
async _preCreate(data, options, user) {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ export default class DHConsumable extends BaseDataItem {
|
|||
type: 'consumable',
|
||||
hasDescription: true,
|
||||
isQuantifiable: true,
|
||||
isInventoryItem: true
|
||||
isInventoryItem: true,
|
||||
isItemLinkable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,7 +23,11 @@ export default class DHFeature extends BaseDataItem {
|
|||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
subType: new fields.StringField({ choices: CONFIG.DH.ITEM.featureSubTypes, nullable: true, initial: null }),
|
||||
subType: new fields.StringField({
|
||||
choices: CONFIG.DH.ITEM.itemLinkFeatureTypes,
|
||||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
originId: new fields.StringField({ nullable: true, initial: null }),
|
||||
identifier: new fields.StringField(),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
|
|
|
|||
|
|
@ -9,7 +9,8 @@ export default class DHMiscellaneous extends BaseDataItem {
|
|||
type: 'miscellaneous',
|
||||
hasDescription: true,
|
||||
isQuantifiable: true,
|
||||
isInventoryItem: true
|
||||
isInventoryItem: true,
|
||||
isItemLinkable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,8 @@ export default class DHSubclass extends BaseDataItem {
|
|||
return foundry.utils.mergeObject(super.metadata, {
|
||||
label: 'TYPES.Item.subclass',
|
||||
type: 'subclass',
|
||||
hasDescription: true
|
||||
hasDescription: true,
|
||||
isItemLinkable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
@ -30,19 +31,19 @@ export default class DHSubclass extends BaseDataItem {
|
|||
|
||||
get foundationFeatures() {
|
||||
return this.features.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.foundation
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.foundation
|
||||
);
|
||||
}
|
||||
|
||||
get specializationFeatures() {
|
||||
return this.features.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.specialization
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.specialization
|
||||
);
|
||||
}
|
||||
|
||||
get masteryFeatures() {
|
||||
return this.features.filter(
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.featureSubTypes.mastery
|
||||
x => x.system.itemLinks[this.parent.uuid] === CONFIG.DH.ITEM.itemLinkFeatureTypes.mastery
|
||||
);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -9,8 +9,8 @@ export default class DHWeapon extends AttachableItem {
|
|||
label: 'TYPES.Item.weapon',
|
||||
type: 'weapon',
|
||||
hasDescription: true,
|
||||
isInventoryItem: true
|
||||
// hasInitialAction: true
|
||||
isInventoryItem: true,
|
||||
isItemLinkable: true
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue