Auto add Attack action to newly created weapon

This commit is contained in:
Dapoolp 2025-06-25 10:26:43 +02:00
parent 22075e7490
commit 1bd2bbd02d
3 changed files with 21 additions and 7 deletions

View file

@ -51,6 +51,24 @@ export default class DHWeapon extends BaseDataItem {
};
}
async _preCreate(data, options, user) {
const actionType = 'attack',
cls = actionsTypes.attack,
action = new cls(
{
_id: foundry.utils.randomID(),
type: actionType,
name: game.i18n.localize(SYSTEM.ACTIONS.actionTypes[actionType].name),
...cls.getSourceConfig(this.parent)
},
{
parent: this.parent
}
);
this.updateSource({actions: [action]});
return super._preCreate(data, options, user);
}
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;