This commit is contained in:
Dapoolp 2025-07-06 18:58:47 +02:00
parent 7f4700fe26
commit 532c245ca3
8 changed files with 100 additions and 70 deletions

View file

@ -17,6 +17,7 @@ import {
socketRegistration
} from './module/systemRegistration/_module.mjs';
import { placeables } from './module/canvas/_module.mjs';
import { registerRollDiceHooks } from './module/dice/dhRoll.mjs';
Hooks.once('init', () => {
CONFIG.DH = SYSTEM;
@ -152,6 +153,7 @@ Hooks.on('ready', () => {
registerCountdownHooks();
socketRegistration.registerSocketHooks();
registerCountdownApplicationHooks();
registerRollDiceHooks();
});
Hooks.once('dicesoniceready', () => {});
@ -263,42 +265,4 @@ Hooks.on('renderJournalDirectory', async (tab, html, _, options) => {
new NarrativeCountdowns().open();
};
}
});
Hooks.on(`daggerheart.postRollDuality`, async(config, message) => {
if(config.roll.type !== 'action') return;
/* const actor = fromUuid(config.source.actor),
rollResult = config.roll.result || config.targets.some(t => t.hit),
actorResources = {},
looseSpotlight = false;
if(config.roll.isCritical || config.roll.result.duality === 1)
actorResources.resources.hope.value += 1;
if(config.roll.isCritical)
actorResources.resources.stress.value -= 1;
if(config.roll.result.duality === -1) fear.value += 1;
if(!rollResult || config.roll.result.duality === -1) looseSpotlight = true;
if(Object.keys(actorResources).length) actor.update();
if(looseSpotlight)
looseSpotlight();
if(config.roll.isCritical) {
// Gain Hope
// Clear Stress
} else if(rollResult) {
if(config.roll.result.duality === 1) {
// Gain Hope
} else {
// GM Gain Fear
// Loose Spotlight
}
} else {
if(config.roll.result.duality === 1) {
// Gain Hope
// Loose Spotlight
} else {
// GM Gain Fear
// Loose Spotlight
}
} */
});

View file

@ -65,6 +65,20 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
];
}
async setCombatantSpotlight(combatantId) {
const combatant = this.viewed.combatants.get(combatantId);
const toggleTurn = this.viewed.combatants.contents
.sort(this.viewed._sortCombatants)
.map(x => x.id)
.indexOf(combatantId);
if (this.viewed.turn !== toggleTurn) Hooks.callAll(CONFIG.DH.HOOKS.spotlight, {});
await this.viewed.update({ turn: this.viewed.turn === toggleTurn ? null : toggleTurn });
await combatant.update({ 'system.spotlight.requesting': false });
}
static async requestSpotlight(_, target) {
const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {};
const combatant = this.viewed.combatants.get(combatantId);
@ -79,17 +93,7 @@ export default class DhCombatTracker extends foundry.applications.sidebar.tabs.C
static async toggleSpotlight(_, target) {
const { combatantId } = target.closest('[data-combatant-id]')?.dataset ?? {};
const combatant = this.viewed.combatants.get(combatantId);
const toggleTurn = this.viewed.combatants.contents
.sort(this.viewed._sortCombatants)
.map(x => x.id)
.indexOf(combatantId);
if (this.viewed.turn !== toggleTurn) Hooks.callAll(CONFIG.DH.HOOKS.spotlight, {});
await this.viewed.update({ turn: this.viewed.turn === toggleTurn ? null : toggleTurn });
await combatant.update({ 'system.spotlight.requesting': false });
await this.setCombatantSpotlight(combatantId);
}
static async setActionTokens(_, target) {

View file

@ -1,3 +1,5 @@
import { emitAsGM, GMUpdateEvent, socketEvent } from "../../systemRegistration/socket.mjs";
const { HandlebarsApplicationMixin, ApplicationV2 } = foundry.applications.api;
/**
@ -96,6 +98,7 @@ export default class FearTracker extends HandlebarsApplicationMixin(ApplicationV
}
static async increaseFear(event, target) {
if (!game.user.isGM) return;
let value = target.dataset.increment ?? 0,
operator = value.split('')[0] ?? null;
value = Number(value);
@ -103,8 +106,19 @@ export default class FearTracker extends HandlebarsApplicationMixin(ApplicationV
}
async updateFear(value) {
if (!game.user.isGM) return;
return emitAsGM(GMUpdateEvent.UpdateFear, game.settings.set.bind(game.settings, CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear), value);
/* if(!game.user.isGM)
await game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.GMUpdate,
data: {
action: GMUpdateEvent.UpdateFear,
update: value
}
});
else
game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear, value); */
/* if (!game.user.isGM) return;
value = Math.max(0, Math.min(this.maxFear, value));
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear, value);
await game.settings.set(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Resources.Fear, value); */
}
}

View file

@ -227,7 +227,8 @@ export default class DHBaseAction extends foundry.abstract.DataModel {
if (Hooks.call(`${CONFIG.DH.id}.preUseAction`, this, config) === false) return;
// Display configuration window if necessary
if (config.dialog?.configure && this.requireConfigurationDialog(config)) {
// if (config.dialog?.configure && this.requireConfigurationDialog(config)) {
if (this.requireConfigurationDialog(config)) {
config = await D20RollDialog.configure(config);
if (!config) return;
}

View file

@ -3,13 +3,13 @@ import DHBaseAction from './baseAction.mjs';
export default class DHEffectAction extends DHBaseAction {
static extraSchemas = ['effects', 'target'];
async use(event, ...args) {
/* async use(event, ...args) {
const config = await super.use(event, args);
if (['error', 'warning'].includes(config.type)) return;
return await this.chatApplyEffects(event, config);
}
} */
async chatApplyEffects(event, data) {
async trigger(event, data) {
const cls = getDocumentClass('ChatMessage'),
systemData = {
title: game.i18n.format('DAGGERHEART.Chat.ApplyEffect.Title', { name: this.name }),

View file

@ -51,7 +51,6 @@ export default class DHRoll extends Roll {
static async buildPost(roll, config, message) {
for (const hook of config.hooks) {
console.log(hook)
if (Hooks.call(`${CONFIG.DH.id}.postRoll${hook.capitalize()}`, config, message) === false) return null;
}
@ -136,3 +135,36 @@ export default class DHRoll extends Roll {
return modifierTotal;
}
}
export const registerRollDiceHooks = () => {
Hooks.on(`${CONFIG.DH.id}.postRollDuality`, async(config, message) => {
if(config.roll.type !== 'action') return;
const actor = await fromUuid(config.source.actor),
rollResult = config.roll.result || config.targets.some(t => t.hit),
updates = [];
let looseSpotlight = false;
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(!rollResult || config.roll.result.duality === -1) looseSpotlight = true;
if(updates.length)
actor.modifyResource(updates);
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);
}
});
};

View file

@ -39,20 +39,16 @@ export const registerSocketHooks = () => {
}
break;
case GMUpdateEvent.UpdateSetting:
if (game.user.isGM) {
await game.settings.set(CONFIG.DH.id, data.uuid, data.update);
}
await game.settings.set(CONFIG.DH.id, data.uuid, data.update);
break;
case GMUpdateEvent.UpdateFear:
if (game.user.isGM) {
await game.settings.set(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Resources.Fear,
Math.max(Math.min(data.update, 6), 0)
);
Hooks.callAll(socketEvent.DhpFearUpdate);
await game.socket.emit(`system.${CONFIG.DH.id}`, { action: socketEvent.DhpFearUpdate });
}
await game.settings.set(
CONFIG.DH.id,
CONFIG.DH.SETTINGS.gameSettings.Resources.Fear,
Math.max(0, Math.min(game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.Homebrew).maxFear, data.update))
);
/* Hooks.callAll(socketEvent.DhpFearUpdate);
await game.socket.emit(`system.${CONFIG.DH.id}`, { action: socketEvent.DhpFearUpdate }); */
break;
}
@ -66,3 +62,22 @@ export const registerSocketHooks = () => {
}
});
};
export const emitAsGM = async (eventName, callback, args) => {
if(!game.user.isGM) {
return new Promise(async (resolve, reject) => {
try {
const response = await game.socket.emit(`system.${CONFIG.DH.id}`, {
action: socketEvent.GMUpdate,
data: {
action: eventName,
update: args
}
});
resolve(response);
} catch (error) {
reject(error);
}
})
} else return callback(args);
}

View file

@ -1,8 +1,8 @@
<div class="combat-tracker">
{{#if (gt this.characters.length 0)}}
{{> 'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Character.Plural") turns=this.characters}}
{{> 'systems/daggerheart/templates/ui/combatTracker/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Character.Plural") turns=this.characters}}
{{/if}}
{{#if (gt this.adversaries.length 0)}}
{{> 'systems/daggerheart/templates/ui/combat/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Adversary.Plural") turns=this.adversaries}}
{{> 'systems/daggerheart/templates/ui/combatTracker/combatTrackerSection.hbs' this title=(localize "DAGGERHEART.General.Adversary.Plural") turns=this.adversaries}}
{{/if}}
</div>