diff --git a/daggerheart.mjs b/daggerheart.mjs index efd93387..ed2d9a25 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -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 - } - } */ }); \ No newline at end of file diff --git a/module/applications/ui/combatTracker.mjs b/module/applications/ui/combatTracker.mjs index e5414d47..f9f49ad1 100644 --- a/module/applications/ui/combatTracker.mjs +++ b/module/applications/ui/combatTracker.mjs @@ -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) { diff --git a/module/applications/ui/fearTracker.mjs b/module/applications/ui/fearTracker.mjs index c2f56c4c..ace2bbb2 100644 --- a/module/applications/ui/fearTracker.mjs +++ b/module/applications/ui/fearTracker.mjs @@ -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); */ } } diff --git a/module/data/action/baseAction.mjs b/module/data/action/baseAction.mjs index dc8fb275..ef0921fa 100644 --- a/module/data/action/baseAction.mjs +++ b/module/data/action/baseAction.mjs @@ -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; } diff --git a/module/data/action/effectAction.mjs b/module/data/action/effectAction.mjs index 6ef3e93c..e2586c6d 100644 --- a/module/data/action/effectAction.mjs +++ b/module/data/action/effectAction.mjs @@ -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 }), diff --git a/module/dice/dhRoll.mjs b/module/dice/dhRoll.mjs index c180bc54..4c035252 100644 --- a/module/dice/dhRoll.mjs +++ b/module/dice/dhRoll.mjs @@ -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); + } + }); +}; \ No newline at end of file diff --git a/module/systemRegistration/socket.mjs b/module/systemRegistration/socket.mjs index 0be0a633..d7f79df9 100644 --- a/module/systemRegistration/socket.mjs +++ b/module/systemRegistration/socket.mjs @@ -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); +} diff --git a/templates/ui/combatTracker/combatTracker.hbs b/templates/ui/combatTracker/combatTracker.hbs index 13bd512e..0ae59ceb 100644 --- a/templates/ui/combatTracker/combatTracker.hbs +++ b/templates/ui/combatTracker/combatTracker.hbs @@ -1,8 +1,8 @@
{{#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}}
\ No newline at end of file