mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-01-12 03:31:07 +01:00
264 - Action Feature Swap (#265)
* Removed action fields on Adversary/Environment in favor of using Feature Items * Added drag/drop for features onto adversary/environment settings * Added Drag of features from Adversary/Environment settings to anywhere in Foundry * Updated all item types except Class/Subclass * Added for Class/Subclass * Items now copy over their features to Character * Corrected back to actions for right items * Fixed adversary/environment features display * PR Fixes
This commit is contained in:
parent
eac58c1386
commit
e9ad9c539a
58 changed files with 1146 additions and 1114 deletions
|
|
@ -43,7 +43,6 @@ export default class DhpAdversary extends BaseDataActor {
|
|||
hitPoints: resourceField(),
|
||||
stress: resourceField()
|
||||
}),
|
||||
actions: new fields.ArrayField(new ActionField()),
|
||||
attack: new ActionField({
|
||||
initial: {
|
||||
name: 'Attack',
|
||||
|
|
@ -86,4 +85,8 @@ export default class DhpAdversary extends BaseDataActor {
|
|||
get attackBonus() {
|
||||
return this.attack.roll.bonus;
|
||||
}
|
||||
|
||||
get features() {
|
||||
return this.parent.items.filter(x => x.type === 'feature');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -97,7 +97,6 @@ export default class DhCharacter extends BaseDataActor {
|
|||
value: new ForeignDocumentUUIDField({ type: 'Item', nullable: true }),
|
||||
subclass: new ForeignDocumentUUIDField({ type: 'Item', nullable: true })
|
||||
}),
|
||||
actions: new fields.ArrayField(new ActionField()),
|
||||
levelData: new fields.EmbeddedDataField(DhLevelData),
|
||||
bonuses: new fields.SchemaField({
|
||||
armorScore: new fields.NumberField({ integer: true, initial: 0 }),
|
||||
|
|
@ -198,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 (let 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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,8 +30,11 @@ export default class DhEnvironment extends BaseDataActor {
|
|||
adversaries: new ForeignDocumentUUIDArrayField({ type: 'Actor' })
|
||||
})
|
||||
),
|
||||
actions: new fields.ArrayField(new ActionField()),
|
||||
notes: new fields.HTMLField()
|
||||
};
|
||||
}
|
||||
|
||||
get features() {
|
||||
return this.parent.items.filter(x => x.type === 'feature');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
export default class DHAncestry extends BaseDataItem {
|
||||
|
|
@ -13,10 +13,9 @@ export default class DHAncestry extends BaseDataItem {
|
|||
|
||||
/** @inheritDoc */
|
||||
static defineSchema() {
|
||||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,3 @@
|
|||
import { actionsTypes } from '../action/_module.mjs';
|
||||
|
||||
/**
|
||||
* Describes metadata about the item data model type
|
||||
* @typedef {Object} ItemDataModelMetadata
|
||||
|
|
@ -61,8 +59,8 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
if (!this.constructor.metadata.hasInitialAction || !foundry.utils.isEmpty(this.actions)) return;
|
||||
|
||||
const metadataType = this.constructor.metadata.type;
|
||||
const actionType = { weapon: "attack" }[metadataType];
|
||||
const ActionClass = actionsTypes[actionType];
|
||||
const actionType = { weapon: 'attack' }[metadataType];
|
||||
const ActionClass = game.system.api.models.actions.actionsTypes[actionType];
|
||||
|
||||
const action = new ActionClass(
|
||||
{
|
||||
|
|
@ -79,4 +77,31 @@ 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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') {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
|
||||
export default class DHClass extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -28,8 +27,8 @@ export default class DHClass extends BaseDataItem {
|
|||
label: 'DAGGERHEART.Sheets.Class.HitPoints'
|
||||
}),
|
||||
evasion: new fields.NumberField({ initial: 0, integer: true, label: 'DAGGERHEART.Sheets.Class.Evasion' }),
|
||||
hopeFeatures: new foundry.data.fields.ArrayField(new ActionField()),
|
||||
classFeatures: new foundry.data.fields.ArrayField(new ActionField()),
|
||||
hopeFeatures: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||
classFeatures: new ForeignDocumentUUIDArrayField({ type: 'Item' }),
|
||||
subclasses: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
|
||||
inventory: new fields.SchemaField({
|
||||
take: new ForeignDocumentUUIDArrayField({ type: 'Item', required: false }),
|
||||
|
|
@ -57,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;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
export default class DHCommunity extends BaseDataItem {
|
||||
|
|
@ -16,7 +16,7 @@ export default class DHCommunity extends BaseDataItem {
|
|||
const fields = foundry.data.fields;
|
||||
return {
|
||||
...super.defineSchema(),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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())
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,6 @@
|
|||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
import ForeignDocumentUUIDField from '../fields/foreignDocumentUUIDField.mjs';
|
||||
import BaseDataItem from './base.mjs';
|
||||
|
||||
const featureSchema = () => {
|
||||
return new foundry.data.fields.SchemaField({
|
||||
name: new foundry.data.fields.StringField({ required: true }),
|
||||
effects: new ForeignDocumentUUIDArrayField({ type: 'ActiveEffect', required: false }),
|
||||
actions: new foundry.data.fields.ArrayField(new ActionField())
|
||||
});
|
||||
};
|
||||
|
||||
export default class DHSubclass extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
static get metadata() {
|
||||
|
|
@ -31,20 +22,20 @@ export default class DHSubclass extends BaseDataItem {
|
|||
nullable: true,
|
||||
initial: null
|
||||
}),
|
||||
foundationFeature: featureSchema(),
|
||||
specializationFeature: featureSchema(),
|
||||
masteryFeature: featureSchema(),
|
||||
foundationFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
specializationFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
masteryFeature: new ForeignDocumentUUIDField({ type: 'Item' }),
|
||||
featureState: new fields.NumberField({ required: true, initial: 1, min: 1 }),
|
||||
isMulticlass: new fields.BooleanField({ initial: false })
|
||||
};
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import { actionsTypes } from '../action/_module.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
|
||||
export default class DHWeapon extends BaseDataItem {
|
||||
|
|
@ -56,20 +57,20 @@ export default class DHWeapon extends BaseDataItem {
|
|||
const allowed = await super._preUpdate(changes, options, user);
|
||||
if (allowed === false) return false;
|
||||
|
||||
if (changes.system.features) {
|
||||
if (changes.system?.features) {
|
||||
const removed = this.features.filter(x => !changes.system.features.includes(x));
|
||||
const added = changes.system.features.filter(x => !this.features.includes(x));
|
||||
|
||||
for (var feature of removed) {
|
||||
for (var effectId of feature.effectIds) {
|
||||
for (let weaponFeature of removed) {
|
||||
for (var effectId of weaponFeature.effectIds) {
|
||||
await this.parent.effects.get(effectId).delete();
|
||||
}
|
||||
|
||||
changes.system.actions = this.actions.filter(x => !feature.actionIds.includes(x._id));
|
||||
changes.system.actions = this.actions.filter(x => !weaponFeature.actionIds.includes(x._id));
|
||||
}
|
||||
|
||||
for (var feature of added) {
|
||||
const featureData = CONFIG.DH.ITEM.weaponFeatures[feature.value];
|
||||
for (let weaponFeature of added) {
|
||||
const featureData = CONFIG.DH.ITEM.weaponFeatures[weaponFeature.value];
|
||||
if (featureData.effects?.length > 0) {
|
||||
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
|
||||
{
|
||||
|
|
@ -78,18 +79,18 @@ export default class DHWeapon extends BaseDataItem {
|
|||
changes: featureData.effects.flatMap(x => x.changes)
|
||||
}
|
||||
]);
|
||||
feature.effectIds = embeddedItems.map(x => x.id);
|
||||
weaponFeature.effectIds = embeddedItems.map(x => x.id);
|
||||
}
|
||||
if (featureData.actions?.length > 0) {
|
||||
const newActions = featureData.actions.map(action => {
|
||||
const cls = CONFIG.DH.ACTIONS.actionsTypes[action.type];
|
||||
const cls = actionsTypes[action.type];
|
||||
return new cls(
|
||||
{ ...action, _id: foundry.utils.randomID(), name: game.i18n.localize(action.name) },
|
||||
{ parent: this }
|
||||
);
|
||||
});
|
||||
changes.system.actions = [...this.actions, ...newActions];
|
||||
feature.actionIds = newActions.map(x => x._id);
|
||||
weaponFeature.actionIds = newActions.map(x => x._id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue