mirror of
https://github.com/Foundryborne/daggerheart.git
synced 2026-03-08 06:56:12 +01:00
Updated all item types except Class/Subclass
This commit is contained in:
parent
3753452559
commit
18d6bd7dcf
20 changed files with 250 additions and 174 deletions
|
|
@ -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,6 +1,6 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import { armorFeatures } from '../../config/itemConfig.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DHArmor extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -22,7 +22,7 @@ export default class DHArmor extends BaseDataItem {
|
|||
tier: new fields.NumberField({ required: true, integer: true, initial: 1, min: 1 }),
|
||||
equipped: new fields.BooleanField({ initial: false }),
|
||||
baseScore: new fields.NumberField({ integer: true, initial: 0 }),
|
||||
features: new fields.ArrayField(
|
||||
armorFeatures: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
value: new fields.StringField({
|
||||
required: true,
|
||||
|
|
@ -40,32 +40,28 @@ export default class DHArmor extends BaseDataItem {
|
|||
major: new fields.NumberField({ integer: true, initial: 0 }),
|
||||
severe: new fields.NumberField({ integer: true, initial: 0 })
|
||||
}),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
|
||||
get featureInfo() {
|
||||
return this.feature ? CONFIG.DH.ITEM.armorFeatures[this.feature] : null;
|
||||
}
|
||||
|
||||
async _preUpdate(changes, options, user) {
|
||||
const allowed = await super._preUpdate(changes, options, user);
|
||||
if (allowed === false) return false;
|
||||
|
||||
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));
|
||||
if (changes.system?.armorFeatures) {
|
||||
const removed = this.armorFeatures.filter(x => !changes.system.armorFeatures.includes(x));
|
||||
const added = changes.system.armorFeatures.filter(x => !this.armorFeatures.includes(x));
|
||||
|
||||
for (var feature of removed) {
|
||||
for (var effectId of feature.effectIds) {
|
||||
for (var armorFeature of removed) {
|
||||
for (var effectId of armorFeature.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 => !armorFeature.actionIds.includes(x._id));
|
||||
}
|
||||
|
||||
for (var feature of added) {
|
||||
const featureData = armorFeatures[feature.value];
|
||||
for (var armorFeature of added) {
|
||||
const featureData = armorFeatures[armorFeature.value];
|
||||
if (featureData.effects?.length > 0) {
|
||||
const embeddedItems = await this.parent.createEmbeddedDocuments('ActiveEffect', [
|
||||
{
|
||||
|
|
@ -74,7 +70,7 @@ export default class DHArmor extends BaseDataItem {
|
|||
changes: featureData.effects.flatMap(x => x.changes)
|
||||
}
|
||||
]);
|
||||
feature.effectIds = embeddedItems.map(x => x.id);
|
||||
armorFeature.effectIds = embeddedItems.map(x => x.id);
|
||||
}
|
||||
if (featureData.actions?.length > 0) {
|
||||
const newActions = featureData.actions.map(action => {
|
||||
|
|
@ -85,7 +81,7 @@ export default class DHArmor extends BaseDataItem {
|
|||
);
|
||||
});
|
||||
changes.system.actions = [...this.actions, ...newActions];
|
||||
feature.actionIds = newActions.map(x => x._id);
|
||||
armorFeature.actionIds = newActions.map(x => x._id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
// import { actionsTypes } from '../action/_module.mjs';
|
||||
import { actionsTypes } from '../action/_module.mjs';
|
||||
|
||||
/**
|
||||
* Describes metadata about the item data model type
|
||||
|
|
@ -60,8 +60,7 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
|
|||
const actionType = {
|
||||
weapon: 'attack'
|
||||
}[this.constructor.metadata.type],
|
||||
cls = game.system.api.models.actionsTypes[actionType],
|
||||
// cls = actionsTypes.attack,
|
||||
cls = actionsTypes[actionType],
|
||||
action = new cls(
|
||||
{
|
||||
_id: foundry.utils.randomID(),
|
||||
|
|
|
|||
|
|
@ -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' })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DHConsumable extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -19,7 +19,7 @@ export default class DHConsumable extends BaseDataItem {
|
|||
return {
|
||||
...super.defineSchema(),
|
||||
consumeOnUse: new fields.BooleanField({ initial: false }),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DHDomainCard extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -30,7 +30,7 @@ export default class DHDomainCard extends BaseDataItem {
|
|||
}),
|
||||
foundation: new fields.BooleanField({ initial: false }),
|
||||
inVault: new fields.BooleanField({ initial: false }),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DHMiscellaneous extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -15,10 +15,9 @@ export default class DHMiscellaneous 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,6 @@
|
|||
import BaseDataItem from './base.mjs';
|
||||
import ActionField from '../fields/actionField.mjs';
|
||||
import { actionsTypes } from '../action/_module.mjs';
|
||||
import ForeignDocumentUUIDArrayField from '../fields/foreignDocumentUUIDArrayField.mjs';
|
||||
|
||||
export default class DHWeapon extends BaseDataItem {
|
||||
/** @inheritDoc */
|
||||
|
|
@ -37,7 +38,7 @@ export default class DHWeapon extends BaseDataItem {
|
|||
initial: 'physical'
|
||||
})
|
||||
}),
|
||||
features: new fields.ArrayField(
|
||||
weaponFeatures: new fields.ArrayField(
|
||||
new fields.SchemaField({
|
||||
value: new fields.StringField({
|
||||
required: true,
|
||||
|
|
@ -48,7 +49,7 @@ export default class DHWeapon extends BaseDataItem {
|
|||
actionIds: new fields.ArrayField(new fields.StringField({ required: true }))
|
||||
})
|
||||
),
|
||||
actions: new fields.ArrayField(new ActionField())
|
||||
features: new ForeignDocumentUUIDArrayField({ type: 'Item' })
|
||||
};
|
||||
}
|
||||
|
||||
|
|
@ -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) {
|
||||
const removed = this.features.filter(x => !changes.system.features.includes(x));
|
||||
const added = changes.system.features.filter(x => !this.features.includes(x));
|
||||
if (changes.system?.weaponFeatures) {
|
||||
const removed = this.weaponFeatures.filter(x => !changes.system.weaponFeatures.includes(x));
|
||||
const added = changes.system.weaponFeatures.filter(x => !this.weaponFeatures.includes(x));
|
||||
|
||||
for (var feature of removed) {
|
||||
for (var effectId of feature.effectIds) {
|
||||
for (var 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 (var 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