284 - Armor/Weapon Feature Improvements (#292)

* Added parsing of effect values from Item data model. Almost finished with itemConfig.

* Added the last to itemConfig

* Fixed armor

* ContextMenu localization fixes

* Better tooltips for tagify

* Corrected resource logic
This commit is contained in:
WBHarry 2025-07-09 13:06:49 +02:00 committed by GitHub
parent eae4f12910
commit b3e7c6b9b2
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
51 changed files with 3043 additions and 2310 deletions

View file

@ -10,7 +10,7 @@ export default class DHWeapon extends BaseDataItem {
type: 'weapon',
hasDescription: true,
isQuantifiable: true,
isInventoryItem: true,
isInventoryItem: true
// hasInitialAction: true
});
}
@ -26,8 +26,7 @@ export default class DHWeapon extends BaseDataItem {
//SETTINGS
secondary: new fields.BooleanField({ initial: false }),
burden: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.burden, initial: 'oneHanded' }),
features: new fields.ArrayField(
weaponFeatures: new fields.ArrayField(
new fields.SchemaField({
value: new fields.StringField({
required: true,
@ -59,7 +58,7 @@ export default class DHWeapon extends BaseDataItem {
{
value: {
multiplier: 'prof',
dice: "d8"
dice: 'd8'
}
}
]
@ -78,18 +77,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));
const removedEffectsUpdate = [];
const removedActionsUpdate = [];
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 => !weaponFeature.actionIds.includes(x._id));
removedEffectsUpdate.push(...weaponFeature.effectIds);
removedActionsUpdate.push(...weaponFeature.actionIds);
}
await this.parent.deleteEmbeddedDocuments('ActiveEffect', removedEffectsUpdate);
changes.system.actions = this.actions.filter(x => !removedActionsUpdate.includes(x._id));
for (let weaponFeature of added) {
const featureData = CONFIG.DH.ITEM.weaponFeatures[weaponFeature.value];
if (featureData.effects?.length > 0) {
@ -102,17 +103,37 @@ export default class DHWeapon extends BaseDataItem {
]);
weaponFeature.effectIds = embeddedItems.map(x => x.id);
}
const newActions = [];
if (featureData.actions?.length > 0) {
const newActions = featureData.actions.map(action => {
const cls = actionsTypes[action.type];
return new cls(
{ ...action, _id: foundry.utils.randomID(), name: game.i18n.localize(action.name) },
{ parent: this }
for (let action of featureData.actions) {
const embeddedEffects = await this.parent.createEmbeddedDocuments(
'ActiveEffect',
(action.effects ?? []).map(effect => ({
...effect,
transfer: false,
name: game.i18n.localize(effect.name),
description: game.i18n.localize(effect.description)
}))
);
});
changes.system.actions = [...this.actions, ...newActions];
weaponFeature.actionIds = newActions.map(x => x._id);
const cls = actionsTypes[action.type];
newActions.push(
new cls(
{
...action,
_id: foundry.utils.randomID(),
name: game.i18n.localize(action.name),
description: game.i18n.localize(action.description),
effects: embeddedEffects.map(x => ({ _id: x.id }))
},
{ parent: this }
)
);
}
}
changes.system.actions = [...this.actions, ...newActions];
weaponFeature.actionIds = newActions.map(x => x._id);
}
}
}