/fr now supports type=X, where X is Hope or Fear, if not supplied, defaults to Hope

This commit is contained in:
Chris Ryan 2025-12-03 22:35:37 +10:00
parent bfd8031ecf
commit 265e35b680
4 changed files with 49 additions and 13 deletions

View file

@ -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;
}

View file

@ -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
};

View file

@ -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);
}

View file

@ -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) {