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

@ -966,29 +966,6 @@
"Description": "This weapon can also be used with these statistics—{characterTrait}, {range}, {damage}."
}
},
"Feature": {
"Type": {
"ancestry": "Ancestry",
"community": "Community",
"class": "Class",
"subclass": "Subclass",
"classHope": "Class Hope",
"domainCard": "Domain Card",
"equipment": "Equipment"
},
"ValueType": {
"Normal": "Normal",
"Input": "Input",
"Dice": "Dice"
},
"Max": "Max",
"NewEffect": "New Effect"
},
"FeatureType": {
"Normal": "Normal",
"Input": "Input",
"Ticks": "Ticks"
},
"Application": {
"Downtime": {
"TakeDowntime": "Take Downtime"

View file

@ -349,8 +349,8 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
}
static async finish() {
const embeddedAncestries = await this.character.createEmbeddedDocuments('Item', [this.setup.ancestry]);
const embeddedCommunities = await this.character.createEmbeddedDocuments('Item', [this.setup.community]);
await this.character.createEmbeddedDocuments('Item', [this.setup.ancestry]);
await this.character.createEmbeddedDocuments('Item', [this.setup.community]);
await this.character.createEmbeddedDocuments('Item', [this.setup.class]);
await this.character.createEmbeddedDocuments('Item', [this.setup.subclass]);
await this.character.createEmbeddedDocuments('Item', Object.values(this.setup.domainCards));
@ -379,9 +379,7 @@ export default class DhCharacterCreation extends HandlebarsApplicationMixin(Appl
await this.character.update({
system: {
traits: this.setup.traits,
experiences: this.setup.experiences,
ancestry: embeddedAncestries[0].uuid,
community: embeddedCommunities[0].uuid
experiences: this.setup.experiences
}
});

View file

@ -307,13 +307,9 @@ export default class CharacterSheet extends DaggerheartSheet(ActorSheetV2) {
getItem(element) {
const listElement = (element.target ?? element).closest('[data-item-id]');
const itemId = listElement.dataset.itemId;
if (listElement.dataset.type === 'effect') {
return this.document.effects.get(itemId);
} else if (['armor', 'weapon', 'feature', 'consumable', 'miscellaneous'].includes(listElement.dataset.type)) {
return this.document.items.get(itemId);
} else {
return this.document.system[listElement.dataset.type].system.actions.find(x => x.id === itemId);
}
return listElement.dataset.type === 'effect'
? this.document.effects.get(itemId)
: this.document.items.get(itemId);
}
static triggerContextMenu(event, button) {

View file

@ -656,31 +656,47 @@ export const weaponFeatures = {
export const featureTypes = {
ancestry: {
id: 'ancestry',
label: 'DAGGERHEART.Feature.Type.ancestry'
label: 'TYPES.Item.ancestry'
},
community: {
id: 'community',
label: 'DAGGERHEART.Feature.Type.community'
label: 'TYPES.Item.community'
},
companion: {
id: 'companion',
label: 'TYPES.Actor.companion'
},
class: {
id: 'class',
label: 'DAGGERHEART.Feature.Type.class'
label: 'TYPES.Item.class'
},
subclass: {
id: 'subclass',
label: 'DAGGERHEART.Feature.Type.subclass'
},
classHope: {
id: 'classHope',
label: 'DAGGERHEART.Feature.Type.classHope'
label: 'TYPES.Item.subclass'
},
domainCard: {
id: 'domainCard',
label: 'DAGGERHEART.Feature.Type.domainCard'
label: 'TYPES.Item.domainCard'
},
equipment: {
id: 'equipment',
label: 'DAGGERHEART.Feature.Type.equipment'
armor: {
id: 'armor',
label: 'TYPES.Item.armor'
},
weapon: {
id: 'weapon',
label: 'TYPES.Item.weapon'
},
consumable: {
id: 'consumable',
label: 'TYPES.Item.consumable'
},
miscellaneous: {
id: 'miscellaneous',
label: 'TYPES.Item.miscellaneous'
},
beastform: {
if: 'beastform',
label: 'TYPES.Item.beastform'
}
};

View file

@ -197,6 +197,68 @@ export default class DhCharacter extends BaseDataActor {
return this.parent.items.find(x => x.type === 'armor' && x.system.equipped);
}
get sheetLists() {
const ancestryFeatures = [],
communityFeatures = [],
classFeatures = [],
subclassFeatures = [],
companionFeatures = [],
features = [];
for (var item of this.parent.items) {
if (item.system.type === CONFIG.DH.ITEM.featureTypes.ancestry.id) {
ancestryFeatures.push(item);
} else if (item.system.type === CONFIG.DH.ITEM.featureTypes.community.id) {
communityFeatures.push(item);
} else if (item.system.type === CONFIG.DH.ITEM.featureTypes.class.id) {
classFeatures.push(item);
} else if (item.system.type === CONFIG.DH.ITEM.featureTypes.subclass.id) {
const subclassState = this.class.subclass.system.featureState;
const identifier = item.system.identifier;
if (
identifier === 'foundationFeature' ||
(identifier === 'specializationFeature' && subclassState >= 2) ||
(identifier === 'masterFeature' && subclassState >= 3)
) {
subclassFeatures.push(item);
}
} else if (item.system.type === CONFIG.DH.ITEM.featureTypes.companion.id) {
companionFeatures.push(item);
} else if (item.type === 'feature' && !item.system.type) {
features.push(item);
}
}
return {
ancestryFeatures: {
title: `${game.i18n.localize('TYPES.Item.ancestry')} - ${this.ancestry?.name}`,
type: 'ancestry',
values: ancestryFeatures
},
communityFeatures: {
title: `${game.i18n.localize('TYPES.Item.community')} - ${this.community?.name}`,
type: 'community',
values: communityFeatures
},
classFeatures: {
title: `${game.i18n.localize('TYPES.Item.class')} - ${this.class.value?.name}`,
type: 'class',
values: classFeatures
},
subclassFeatures: {
title: `${game.i18n.localize('TYPES.Item.subclass')} - ${this.class.subclass?.name}`,
type: 'subclass',
values: subclassFeatures
},
companionFeatures: {
title: game.i18n.localize('DAGGERHEART.Sheets.PC.CompanionFeatures'),
type: 'companion',
values: companionFeatures
},
features: { title: game.i18n.localize('DAGGERHEART.Sheets.PC.Features'), type: 'feature', values: features }
};
}
get primaryWeapon() {
return this.parent.items.find(x => x.type === 'weapon' && x.system.equipped && !x.system.secondary);
}

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)
);
}
}

View file

@ -39,10 +39,7 @@ export default class DHBeastform extends BaseDataItem {
};
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;
async _preCreate() {
if (!this.actor) return;
if (this.actor.type !== 'character') {

View file

@ -56,6 +56,10 @@ export default class DHClass extends BaseDataItem {
return this.hopeFeatures.length > 0 ? this.hopeFeatures[0] : null;
}
get features() {
return [...this.hopeFeatures.filter(x => x), ...this.classFeatures.filter(x => x)];
}
async _preCreate(data, options, user) {
const allowed = await super._preCreate(data, options, user);
if (allowed === false) return;

View file

@ -16,6 +16,9 @@ export default class DHFeature extends BaseDataItem {
const fields = foundry.data.fields;
return {
...super.defineSchema(),
type: new fields.StringField({ choices: CONFIG.DH.ITEM.featureTypes, nullable: true, initial: null }),
originId: new fields.StringField({ nullable: true, initial: null }),
identifier: new fields.StringField(),
actions: new fields.ArrayField(new ActionField())
};
}

View file

@ -31,11 +31,11 @@ export default class DHSubclass extends BaseDataItem {
}
get features() {
return {
foundation: this.foundationFeature,
specialization: this.featureState >= 2 ? this.specializationFeature : null,
mastery: this.featureState === 3 ? this.masteryFeature : null
};
return [
{ ...this.foundationFeature.toObject(), identifier: 'foundationFeature' },
{ ...this.specializationFeature.toObject(), identifier: 'specializationFeature' },
{ ...this.masteryFeature.toObject(), identifier: 'masteryFeature' }
];
}
async _preCreate(data, options, user) {

View file

@ -4,7 +4,12 @@
data-group='{{tabs.features.group}}'
>
<div class="features-sections">
{{#if document.system.class.value}}
{{#each document.system.sheetLists}}
{{#if this.values}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=this.title values=this.values}}
{{/if}}
{{/each}}
{{!-- {{#if document.system.class.value}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(concat (localize 'TYPES.Item.class') ' - ' document.system.class.value.name) type='class'}}
{{/if}}
{{#if document.system.class.subclass}}
@ -21,6 +26,6 @@
{{/if}}
{{#if document.system.ancestry}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-fieldset-items.hbs' title=(concat (localize 'TYPES.Item.ancestry') ' - ' document.system.ancestry.name) type='ancestry'}}
{{/if}}
{{/if}} --}}
</div>
</section>

View file

@ -2,51 +2,29 @@
<legend>{{title}}</legend>
<ul class="items-list">
{{#unless (eq cardView 'card') }}
{{#each document.items as |item|}}
{{#if (eq item.type ../type)}}
{{#unless (or (eq ../type 'ancestry') (eq item.type 'class') (eq item.type 'subclass') (and (eq ../type 'domainCard') (or (and item.system.inVault (not ../isVault)) (and (not item.system.inVault) ../isVault))))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=item type=../type}}
{{/unless}}
{{#if (eq type 'domainCard')}}
{{#each document.items as |item|}}
{{#if (eq item.type ../type)}}
{{#unless (and (eq ../type 'domainCard') (or (and item.system.inVault (not ../isVault)) (and (not item.system.inVault) ../isVault)))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=item type=../type}}
{{/unless}}
{{/if}}
{{/each}}
{{else}}
{{#if (eq type 'effect')}}
{{#each document.effects as |effect|}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=effect type=../type}}
{{/each}}
{{else}}
{{#each values}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=this type=../type }}
{{/each}}
{{#each adversaries as |adversary|}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=adversary type='adversary' hideControls=true isActor=true categoryAdversary=@../key}}
{{/each}}
{{/if}}
{{/each}}
{{#each document.system.ancestry.system.actions as |action|}}
{{#if (or (eq ../type 'ancestry'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=action type=../type}}
{{/if}}
{{/each}}
{{#each document.system.class.value.system.classFeatures as |classFeature|}}
{{#if (or (eq ../type 'class'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=classFeature type=../type}}
{{/if}}
{{/each}}
{{#each document.system.class.value.system.classFeatures as |classFeature|}}
{{#if (or (eq ../type 'class'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=classFeature type=../type}}
{{/if}}
{{/each}}
{{#each document.appliedEffects as |effect|}}
{{#if (or (eq ../type 'effect'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=effect type=../type}}
{{/if}}
{{/each}}
{{#each document.system.actions as |action|}}
{{#if (or (eq ../type 'action'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=action type=../type}}
{{/if}}
{{/each}}
{{#each document.system.features as |feature|}}
{{#if (or (eq ../type 'features'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=feature}}
{{/if}}
{{/each}}
{{#each document.system.companionFeatures as |feature|}}
{{#if (or (eq ../type 'companionFeatures'))}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=feature companion=true}}
{{/if}}
{{/each}}
{{#each adversaries as |adversary|}}
{{> 'systems/daggerheart/templates/sheets/global/partials/inventory-item.hbs' item=adversary type='adversary' hideControls=true isActor=true categoryAdversary=@../key}}
{{/each}}
{{/if}}
{{/unless}}
</ul>

View file

@ -1,4 +1,4 @@
<li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-type="{{type}}" data-companion="{{companion}}">
<li class="inventory-item" data-item-id="{{item.id}}" data-item-uuid="{{item.uuid}}" data-type="{{type}}">
<img src="{{item.img}}" class="item-img {{#if isActor}}actor-img{{/if}}" data-action="useItem" {{#if (not noTooltip)}}data-tooltip="{{concat "#item#" item.uuid}}"{{/if}} />
<div class="item-label">
{{#if isCompanion}}