Companions can't be put into CombatState anymore. Companions now have a Action Roll button

This commit is contained in:
WBHarry 2025-08-22 19:11:17 +02:00
parent ee786544c7
commit 9b3d1cddc4
4 changed files with 66 additions and 0 deletions

View file

@ -13,6 +13,9 @@ export default class DHTokenHUD extends foundry.applications.hud.TokenHUD {
async _prepareContext(options) {
const context = await super._prepareContext(options);
const nonCombatTypes = ['environment', 'companion'];
context.canToggleCombat = nonCombatTypes.includes(this.actor.type) ? false : context.canToggleCombat;
context.systemStatusEffects = Object.keys(context.statusEffects).reduce((acc, key) => {
const effect = context.statusEffects[key];
if (effect.systemEffect) acc[key] = effect;

View file

@ -8,6 +8,7 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
classes: ['actor', 'companion'],
position: { width: 340 },
actions: {
actionRoll: DhCompanionSheet.#actionRoll,
levelManagement: DhCompanionSheet.#levelManagement
}
};
@ -45,6 +46,52 @@ export default class DhCompanionSheet extends DHBaseActorSheet {
/* Application Clicks Actions */
/* -------------------------------------------- */
/**
*
*/
static async #actionRoll(event) {
const partner = this.actor.system.partner;
const config = {
event,
title: `${game.i18n.localize('DAGGERHEART.GENERAL.Roll.action')}: ${this.actor.name}`,
headerTitle: `Companion ${game.i18n.localize('DAGGERHEART.GENERAL.Roll.action')}`,
roll: {
trait: partner.system.spellcastModifierTrait?.key
},
hasRoll: true,
data: partner.getRollData()
};
const result = await partner.diceRoll(config);
this.consumeResource(result?.costs);
}
// Remove when Action Refactor part #2 done
async consumeResource(costs) {
if (!costs?.length) return;
const partner = this.actor.system.partner;
const usefulResources = {
...foundry.utils.deepClone(partner.system.resources),
fear: {
value: game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear),
max: game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).maxFear,
reversed: false
}
};
const resources = game.system.api.fields.ActionFields.CostField.getRealCosts(costs).map(c => {
const resource = usefulResources[c.key];
return {
key: c.key,
value: (c.total ?? c.value) * (resource.isReversed ? 1 : -1),
target: resource.target,
keyIsID: resource.keyIsID
};
});
await partner.modifyResource(resources);
}
/**
* Opens the companions level management window.
* @type {ApplicationClickAction}

View file

@ -77,4 +77,17 @@
}
}
}
.action-section {
display: flex;
padding: 0 10px;
margin-top: 20px;
width: 100%;
button {
height: 40px;
width: 100%;
font-weight: 600;
}
}
}

View file

@ -56,4 +56,7 @@
</div>
{{/each}}
</div>
<div class="action-section">
<button type="button" data-action="actionRoll">{{localize "DAGGERHEART.GENERAL.Roll.action"}}</button>
</div>
</section>