diff --git a/daggerheart.mjs b/daggerheart.mjs index e0ec8e36..14ca2d5d 100644 --- a/daggerheart.mjs +++ b/daggerheart.mjs @@ -249,6 +249,7 @@ Hooks.on('chatMessage', (_, message) => { } if (message.startsWith('/fr')) { + console.log("fr message", message); const result = message.trim().toLowerCase() === '/fr' ? { result: {} } : rollCommandToJSON(message.replace(/\/fr\s?/, '')); if (!result) { @@ -258,6 +259,10 @@ Hooks.on('chatMessage', (_, message) => { const { result: rollCommand, flavor } = result; + console.log("rollCommand", rollCommand); + const fateType = rollCommand.type ?? "Hope"; + console.log("fateType", fateType); + const target = getCommandTarget({ allowNull: true }); const title = 'Fate'; @@ -265,6 +270,7 @@ Hooks.on('chatMessage', (_, message) => { target, title, label: 'test', + fateType }); return false; } diff --git a/module/dice/fateRoll.mjs b/module/dice/fateRoll.mjs index 14b76c7e..4abdf2e5 100644 --- a/module/dice/fateRoll.mjs +++ b/module/dice/fateRoll.mjs @@ -1,6 +1,6 @@ import D20RollDialog from '../applications/dialogs/d20RollDialog.mjs'; import D20Roll from './d20Roll.mjs'; -import { setDiceSoNiceForFateRoll } from '../helpers/utils.mjs'; +import { setDiceSoNiceForHopeFateRoll, setDiceSoNiceForFearFateRoll } from '../helpers/utils.mjs'; export default class FateRoll extends D20Roll { constructor(formula, data = {}, options = {}) { @@ -30,13 +30,27 @@ export default class FateRoll extends D20Roll { // this.#hopeDice = `d${face}`; } + get dFear() { + // if ( !(this.terms[1] instanceof foundry.dice.terms.Die) ) return; + if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); + return this.dice[0]; + // return this.#fearDice; + } + + set dFear(faces) { + if (!(this.dice[0] instanceof foundry.dice.terms.Die)) this.createBaseDice(); + this.dice[0].faces = this.getFaces(faces); + // this.#fearDice = `d${face}`; + } + get isCritical() { return false; } get fateDie() { - return "Hope"; + console.log("fateRoll this", this); + return this.data.fateType; } static getHooks(hooks) { @@ -64,18 +78,25 @@ export default class FateRoll extends D20Roll { console.log("config", config); console.log("message", message); - await setDiceSoNiceForFateRoll( - roll, - config.roll.fate.dice - ); + if (roll.fateDie === "Hope") { + await setDiceSoNiceForHopeFateRoll( + roll, + config.roll.fate.dice + ); + } else { + await setDiceSoNiceForFearFateRoll( + roll, + config.roll.fate.dice + ); + } } static postEvaluate(roll, config = {}) { const data = super.postEvaluate(roll, config); data.fate = { - dice: roll.dHope.denomination, - value: roll.dHope.total, + dice: roll.fateDie === "Hope" ? roll.dHope.denomination : roll.dFear.denomination, + value: roll.fateDie === "Hope" ? roll.dHope.total : roll.dFear.total, fateDie: roll.fateDie }; diff --git a/module/enrichers/FateRollEnricher.mjs b/module/enrichers/FateRollEnricher.mjs index 2fa8abb6..86418a6b 100644 --- a/module/enrichers/FateRollEnricher.mjs +++ b/module/enrichers/FateRollEnricher.mjs @@ -34,14 +34,15 @@ export const renderFateButton = async event => { { target, title: button.dataset.title, - label: button.dataset.label + label: button.dataset.label, + fateType }, event ); }; export const enrichedFateRoll = async ( - { target, title, label }, + { target, title, label, fateType }, event ) => { const config = { @@ -50,14 +51,15 @@ export const enrichedFateRoll = async ( roll: { label: label, }, - hasRoll: true + hasRoll: true, + fateType: fateType }; if (target) { await target.diceRoll(config); } else { // For no target, call FateRoll directly with basic data - config.data = { experiences: {}, traits: {} }; + config.data = { experiences: {}, traits: {}, fateType: fateType }; config.source = { actor: null }; await CONFIG.Dice.daggerheart.FateRoll.build(config); } diff --git a/module/helpers/utils.mjs b/module/helpers/utils.mjs index 0baad80d..af37b71b 100644 --- a/module/helpers/utils.mjs +++ b/module/helpers/utils.mjs @@ -69,13 +69,20 @@ export const setDiceSoNiceForDualityRoll = async (rollResult, advantageState, ho } }; -export const setDiceSoNiceForFateRoll = async (rollResult, hopeFaces) => { +export const setDiceSoNiceForHopeFateRoll = async (rollResult, hopeFaces) => { if (!game.modules.get('dice-so-nice')?.active) return; const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance); const diceSoNicePresets = await getDiceSoNicePreset(diceSoNice.hope, hopeFaces); rollResult.dice[0].options = diceSoNicePresets.hope; }; +export const setDiceSoNiceForFearFateRoll = async (rollResult, fearFaces) => { + if (!game.modules.get('dice-so-nice')?.active) return; + const { diceSoNice } = game.settings.get(CONFIG.DH.id, CONFIG.DH.SETTINGS.gameSettings.appearance); + const diceSoNicePresets = await getDiceSoNicePreset(diceSoNice.fear, fearFaces); + rollResult.dice[0].options = diceSoNicePresets.fear; +}; + export const chunkify = (array, chunkSize, mappingFunc) => { var chunkifiedArray = []; for (let i = 0; i < array.length; i += chunkSize) {