Feature/247 auto add yope fear clear stress (#285)

* cleanup

* test

* Step 1

* #2

* Fix Effect Action & Add Hope tumation settings to hook

* remove circular dependency

* Snuck in some localization fixes I noticed

* Remove success condition for duality roll gain

* Changed config.roll.type logic

---------

Co-authored-by: WBHarry <williambjrklund@gmail.com>
This commit is contained in:
Dapoulp 2025-07-07 01:38:39 +02:00 committed by GitHub
parent ee4a5d17a6
commit 52be430eff
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
21 changed files with 187 additions and 160 deletions

View file

@ -19,7 +19,7 @@ export default class DHRoll extends Roll {
}
static async buildConfigure(config = {}, message = {}) {
config.hooks = [...(config.hooks ?? []), ''];
config.hooks = [...this.getHooks(), ''];
config.dialog ??= {};
for (const hook of config.hooks) {
if (Hooks.call(`${CONFIG.DH.id}.preRoll${hook.capitalize()}`, config, message) === false) return null;
@ -94,6 +94,10 @@ export default class DHRoll extends Roll {
config.dialog.configure ??= !(config.event.shiftKey || config.event.altKey || config.event.ctrlKey);
}
static getHooks(hooks) {
return hooks ?? [];
}
formatModifier(modifier) {
const numTerm = modifier < 0 ? '-' : '+';
return [
@ -131,3 +135,32 @@ export default class DHRoll extends Roll {
return modifierTotal;
}
}
export const registerRollDiceHooks = () => {
Hooks.on(`${CONFIG.DH.id}.postRollDuality`, async (config, message) => {
if (
!game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Automation).hope ||
config.roll.type === 'reaction'
)
return;
const actor = await fromUuid(config.source.actor),
updates = [];
if (!actor) return;
if (config.roll.isCritical || config.roll.result.duality === 1) updates.push({ type: 'hope', value: 1 });
if (config.roll.isCritical) updates.push({ type: 'stress', value: -1 });
if (config.roll.result.duality === -1) updates.push({ type: 'fear', value: 1 });
if (updates.length) actor.modifyResource(updates);
if (!config.roll.hasOwnProperty('success') && !config.targets.length) return;
const rollResult = config.roll.success || config.targets.some(t => t.hit),
looseSpotlight = !rollResult || config.roll.result.duality === -1;
if (looseSpotlight && game.combat?.active) {
const currentCombatant = game.combat.combatants.get(game.combat.current?.combatantId);
if (currentCombatant?.actorId == actor.id) ui.combat.setCombatantSpotlight(currentCombatant.id);
}
});
};