diff --git a/lang/en.json b/lang/en.json index fe358714..6acb0aab 100755 --- a/lang/en.json +++ b/lang/en.json @@ -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" diff --git a/module/applications/characterCreation/characterCreation.mjs b/module/applications/characterCreation/characterCreation.mjs index 1dabc8c2..48ad3bfb 100644 --- a/module/applications/characterCreation/characterCreation.mjs +++ b/module/applications/characterCreation/characterCreation.mjs @@ -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 } }); diff --git a/module/applications/sheets/actors/character.mjs b/module/applications/sheets/actors/character.mjs index e3fa7367..c568d422 100644 --- a/module/applications/sheets/actors/character.mjs +++ b/module/applications/sheets/actors/character.mjs @@ -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) { diff --git a/module/config/itemConfig.mjs b/module/config/itemConfig.mjs index 6d8488ba..b446bc28 100644 --- a/module/config/itemConfig.mjs +++ b/module/config/itemConfig.mjs @@ -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' } }; diff --git a/module/data/actor/character.mjs b/module/data/actor/character.mjs index a9d9bfc6..1938157c 100644 --- a/module/data/actor/character.mjs +++ b/module/data/actor/character.mjs @@ -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); } diff --git a/module/data/item/base.mjs b/module/data/item/base.mjs index 5946dc15..de93e90c 100644 --- a/module/data/item/base.mjs +++ b/module/data/item/base.mjs @@ -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) + ); + } } diff --git a/module/data/item/beastform.mjs b/module/data/item/beastform.mjs index b069f910..2f50ab21 100644 --- a/module/data/item/beastform.mjs +++ b/module/data/item/beastform.mjs @@ -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') { diff --git a/module/data/item/class.mjs b/module/data/item/class.mjs index efda7163..ad0d8082 100644 --- a/module/data/item/class.mjs +++ b/module/data/item/class.mjs @@ -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; diff --git a/module/data/item/feature.mjs b/module/data/item/feature.mjs index 85a9c42f..a5b5cb3c 100644 --- a/module/data/item/feature.mjs +++ b/module/data/item/feature.mjs @@ -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()) }; } diff --git a/module/data/item/subclass.mjs b/module/data/item/subclass.mjs index 179cd534..eac1b288 100644 --- a/module/data/item/subclass.mjs +++ b/module/data/item/subclass.mjs @@ -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) { diff --git a/templates/sheets/actors/character/features.hbs b/templates/sheets/actors/character/features.hbs index 1ac18a1e..6ec47c1f 100644 --- a/templates/sheets/actors/character/features.hbs +++ b/templates/sheets/actors/character/features.hbs @@ -4,7 +4,12 @@ data-group='{{tabs.features.group}}' >
- {{#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}} --}}
\ No newline at end of file diff --git a/templates/sheets/global/partials/inventory-fieldset-items.hbs b/templates/sheets/global/partials/inventory-fieldset-items.hbs index cd99fe17..e73988c7 100644 --- a/templates/sheets/global/partials/inventory-fieldset-items.hbs +++ b/templates/sheets/global/partials/inventory-fieldset-items.hbs @@ -2,51 +2,29 @@ {{title}} diff --git a/templates/sheets/global/partials/inventory-item.hbs b/templates/sheets/global/partials/inventory-item.hbs index 2e0ea2e6..0dcc485a 100644 --- a/templates/sheets/global/partials/inventory-item.hbs +++ b/templates/sheets/global/partials/inventory-item.hbs @@ -1,4 +1,4 @@ -
  • +
  • {{#if isCompanion}}