Feature/253 weapon attack action (#290)

* Step #1

* Add Attack to Weapon & Override settings to Roll
This commit is contained in:
Dapoulp 2025-07-07 20:50:48 +02:00 committed by GitHub
parent 52be430eff
commit 7d7fb88035
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
23 changed files with 168 additions and 91 deletions

View file

@ -31,7 +31,8 @@ export class DHActionRollData extends foundry.abstract.DataModel {
label: 'Should be'
}),
treshold: new fields.NumberField({ initial: 1, integer: true, min: 1, label: 'Treshold' })
})
}),
useDefault: new fields.BooleanField({ initial: false })
};
}
@ -47,7 +48,6 @@ export class DHActionRollData extends foundry.abstract.DataModel {
formula = `${multiplier}${this.diceRolling.dice}cs${CONFIG.DH.ACTIONS.diceCompare[this.diceRolling.compare].operator}${this.diceRolling.treshold}`;
break;
default:
// formula = `${(!!this.parent?.actor?.system?.attack ? `@attackBonus` : `@traits.${this.trait}.total`)}`;
formula = '';
break;
}

View file

@ -14,9 +14,15 @@ export default class DHAttackAction extends DHDamageAction {
prepareData() {
super.prepareData();
if (this.damage.includeBase && !!this.item?.system?.damage) {
const baseDamage = this.getParentDamage();
this.damage.parts.unshift(new DHDamageData(baseDamage));
if(!!this.item?.system?.attack) {
if (this.damage.includeBase) {
const baseDamage = this.getParentDamage();
this.damage.parts.unshift(new DHDamageData(baseDamage));
}
if(this.roll.useDefault) {
this.roll.trait = this.item.system.attack.roll.trait;
this.roll.type = 'weapon';
}
}
}
@ -24,10 +30,10 @@ export default class DHAttackAction extends DHDamageAction {
return {
value: {
multiplier: 'prof',
dice: this.item?.system?.damage.dice,
bonus: this.item?.system?.damage.bonus ?? 0
dice: this.item?.system?.attack.damage.parts[0].value.dice,
bonus: this.item?.system?.attack.damage.parts[0].value.bonus ?? 0
},
type: this.item?.system?.damage.type,
type: this.item?.system?.attack.damage.parts[0].type,
base: true
};
}

View file

@ -156,17 +156,22 @@ export default class DHBaseAction extends foundry.abstract.DataModel {
static getSourceConfig(parent) {
const updateSource = {};
updateSource.img ??= parent?.img ?? parent?.system?.img;
if (parent?.system?.trait) {
updateSource['roll'] = {
type: this.getRollType(parent),
trait: parent.system.trait
};
}
if (parent?.type === 'weapon' && !!this.schema.fields.damage) {
if (parent?.type === 'weapon') {
updateSource['damage'] = { includeBase: true };
}
if (parent?.system?.range) {
updateSource['range'] = parent?.system?.range;
updateSource['range'] = parent?.system?.attack?.range;
updateSource['roll'] = {
useDefault: true
}
} else {
if (parent?.system?.trait) {
updateSource['roll'] = {
type: this.getRollType(parent),
trait: parent.system.trait
};
}
if (parent?.system?.range) {
updateSource['range'] = parent?.system?.range;
}
}
return updateSource;
}

View file

@ -61,7 +61,9 @@ export default class DhpAdversary extends BaseDataActor {
damage: {
parts: [
{
multiplier: 'flat'
value: {
multiplier: 'flat'
}
}
]
}

View file

@ -42,6 +42,10 @@ export default class BaseDataItem extends foundry.abstract.TypeDataModel {
return this.parent.actor;
}
get actionsList() {
return this.actions;
}
/**
* Obtain a data object used to evaluate any dice rolls associated with this Item Type
* @param {object} [options] - Options which modify the getRollData method.

View file

@ -11,7 +11,7 @@ export default class DHWeapon extends BaseDataItem {
hasDescription: true,
isQuantifiable: true,
isInventoryItem: true,
hasInitialAction: true
// hasInitialAction: true
});
}
@ -25,19 +25,8 @@ export default class DHWeapon extends BaseDataItem {
//SETTINGS
secondary: new fields.BooleanField({ initial: false }),
trait: new fields.StringField({ required: true, choices: CONFIG.DH.ACTOR.abilities, initial: 'agility' }),
range: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.range, initial: 'melee' }),
burden: new fields.StringField({ required: true, choices: CONFIG.DH.GENERAL.burden, initial: 'oneHanded' }),
//DAMAGE
damage: new fields.SchemaField({
dice: new fields.StringField({ choices: CONFIG.DH.GENERAL.diceTypes, initial: 'd6' }),
bonus: new fields.NumberField({ nullable: true, initial: null }),
type: new fields.StringField({
required: true,
choices: CONFIG.DH.GENERAL.damageTypes,
initial: 'physical'
})
}),
features: new fields.ArrayField(
new fields.SchemaField({
value: new fields.StringField({
@ -49,10 +38,42 @@ export default class DHWeapon extends BaseDataItem {
actionIds: new fields.ArrayField(new fields.StringField({ required: true }))
})
),
attack: new ActionField({
initial: {
name: 'Attack',
img: 'icons/skills/melee/blood-slash-foam-red.webp',
_id: foundry.utils.randomID(),
systemPath: 'attack',
type: 'attack',
range: 'melee',
target: {
type: 'any',
amount: 1
},
roll: {
trait: 'agility',
type: 'weapon'
},
damage: {
parts: [
{
value: {
multiplier: 'prof',
dice: "d8"
}
}
]
}
}
}),
actions: new fields.ArrayField(new ActionField())
};
}
get actionsList() {
return [this.attack, ...this.actions];
}
async _preUpdate(changes, options, user) {
const allowed = await super._preUpdate(changes, options, user);
if (allowed === false) return false;