Add Trait choice in roll dialog

This commit is contained in:
Dapoolp 2025-08-24 11:30:29 +02:00
parent b5ba7e7fba
commit 6b7912f3f4
6 changed files with 55 additions and 25 deletions

View file

@ -2015,6 +2015,7 @@
},
"title": "Title",
"total": "Total",
"traitModifier": "Trait Modifier",
"true": "True",
"type": "Type",
"unarmed": "Unarmed",

View file

@ -1,3 +1,5 @@
import { abilities } from "../../config/actorConfig.mjs";
const { ApplicationV2, HandlebarsApplicationMixin } = foundry.applications.api;
export default class D20RollDialog extends HandlebarsApplicationMixin(ApplicationV2) {
@ -113,15 +115,21 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
context.isLite = this.config.roll?.lite;
context.extraFormula = this.config.extraFormula;
context.formula = this.roll.constructFormula(this.config);
if(this.actor.system.traits) context.abilities = this.getTraitModifiers();
context.showReaction = !context.config.roll?.type && context.rollType === 'DualityRoll';
context.showReaction = !this.config.roll?.type && context.rollType === 'DualityRoll';
context.reactionOverride = this.reactionOverride;
}
return context;
}
getTraitModifiers() {
return Object.values(abilities).map(a => ({ id: a.id, label: `${game.i18n.localize(a.label)} (${this.actor.system.traits[a.id]?.value.signedString() ?? 0})` }))
}
static updateRollConfiguration(event, _, formData) {
const { ...rest } = foundry.utils.expandObject(formData.object);
this.config.selectedRollMode = rest.selectedRollMode;
if (this.config.costs) {
@ -133,6 +141,7 @@ export default class D20RollDialog extends HandlebarsApplicationMixin(Applicatio
this.roll[key] = value;
});
}
if(rest.trait) this.config.roll.trait = rest.trait;
this.config.extraFormula = rest.extraFormula;
this.render();
}

View file

@ -72,27 +72,27 @@ export class DHActionRollData extends foundry.abstract.DataModel {
if (!this.parent?.actor) return modifiers;
switch (this.parent.actor.type) {
case 'character':
const spellcastingTrait =
this.type === 'spellcast'
? (this.parent.actor?.system?.spellcastModifierTrait?.key ?? 'agility')
: null;
const trait =
this.useDefault || !this.trait
? (spellcastingTrait ?? this.parent.item.system.attack?.roll?.trait ?? 'agility')
: this.trait;
if (
this.type === CONFIG.DH.GENERAL.rollTypes.attack.id ||
this.type === CONFIG.DH.GENERAL.rollTypes.trait.id
)
modifiers.push({
label: `DAGGERHEART.CONFIG.Traits.${trait}.name`,
value: this.parent.actor.system.traits[trait].value
});
else if (this.type === CONFIG.DH.GENERAL.rollTypes.spellcast.id)
modifiers.push({
label: `DAGGERHEART.CONFIG.RollTypes.spellcast.name`,
value: this.parent.actor.system.spellcastModifier
});
// const spellcastingTrait =
// this.type === 'spellcast'
// ? (this.parent.actor?.system?.spellcastModifierTrait?.key ?? 'agility')
// : null;
// const trait =
// this.useDefault || !this.trait
// ? (spellcastingTrait ?? this.parent.item.system.attack?.roll?.trait ?? 'agility')
// : this.trait;
// if (
// this.type === CONFIG.DH.GENERAL.rollTypes.attack.id ||
// this.type === CONFIG.DH.GENERAL.rollTypes.trait.id
// )
// modifiers.push({
// label: `DAGGERHEART.CONFIG.Traits.${trait}.name`,
// value: this.parent.actor.system.traits[trait].value
// });
// else if (this.type === CONFIG.DH.GENERAL.rollTypes.spellcast.id)
// modifiers.push({
// label: `DAGGERHEART.CONFIG.RollTypes.spellcast.name`,
// value: this.parent.actor.system.spellcastModifier
// });
break;
case 'companion':
case 'adversary':
@ -107,6 +107,21 @@ export class DHActionRollData extends foundry.abstract.DataModel {
}
return modifiers;
}
get rollTrait() {
if(this.parent?.actor?.type !== "character") return null;
switch (this.type) {
case CONFIG.DH.GENERAL.rollTypes.spellcast.id:
return this.parent.actor?.system?.spellcastModifierTrait?.key ?? 'agility';
case CONFIG.DH.GENERAL.rollTypes.attack.id:
case CONFIG.DH.GENERAL.rollTypes.trait.id:
return this.useDefault || !this.trait
? this.parent.item.system.attack?.roll?.trait ?? 'agility'
: this.trait;
default:
return null;
}
}
}
export default class RollField extends fields.EmbeddedDataField {
@ -145,6 +160,7 @@ export default class RollField extends fields.EmbeddedDataField {
baseModifiers: this.roll.getModifier(),
label: 'Attack',
type: this.roll?.type,
trait: this.roll?.rollTrait,
difficulty: this.roll?.difficulty,
formula: this.roll.getFormula(),
advantage: CONFIG.DH.ACTIONS.advantageState[this.roll.advState].value

View file

@ -153,10 +153,10 @@ export default class DualityRoll extends D20Roll {
applyBaseBonus() {
const modifiers = super.applyBaseBonus();
if (this.options.roll.trait && this.data.traits[this.options.roll.trait])
modifiers.unshift({
label: `DAGGERHEART.CONFIG.Traits.${this.options.roll.trait}.name`,
label: this.options.roll.type === CONFIG.DH.GENERAL.rollTypes.spellcast.id ? "DAGGERHEART.CONFIG.RollTypes.spellcast.name" : `DAGGERHEART.CONFIG.Traits.${this.options.roll.trait}.name`,
value: this.data.traits[this.options.roll.trait].value
});

View file

@ -1,5 +1,5 @@
<fieldset class="flex">
<legend>{{localize "DAGGERHEART.GENERAL.save"}}</legend>
<legend>{{localize "DAGGERHEART.GENERAL.Roll.reaction"}}</legend>
{{formField fields.trait label="Trait" name="save.trait" value=source.trait localize=true}}
{{formField fields.difficulty label="Difficulty" name="save.difficulty" value=source.difficulty disabled=(not source.trait) placeholder=@root.baseSaveDifficulty}}
{{formField fields.damageMod label="Damage on Save" name="save.damageMod" value=source.damageMod localize=true disabled=(not source.trait)}}

View file

@ -126,6 +126,10 @@
{{selectOptions diceOptions selected=@root.roll.dAdvantage.denomination}}
</select>
</div>
<span>{{localize "DAGGERHEART.GENERAL.traitModifier"}}</span>
<select name="trait">
{{selectOptions abilities selected=@root.rollConfig.roll.trait valueAttr="id" labelAttr="label" localize=true}}
</select>
{{/unless}}
{{#if @root.rallyDie.length}}
<span class="formula-label">{{localize "DAGGERHEART.CLASS.Feature.rallyDice"}}</span>