update command to use new dice roll.

This commit is contained in:
IrkTheImp 2025-07-01 21:29:52 -05:00
parent c2669a8de6
commit d25212d9d7
5 changed files with 87 additions and 76 deletions

View file

@ -215,46 +215,20 @@ Hooks.on('chatMessage', (_, message) => {
const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`; const hopeAndFearRoll = `1${rollCommand.hope ?? 'd12'}+1${rollCommand.fear ?? 'd12'}`;
const advantageRoll = `${advantageState === true ? '+d6' : advantageState === false ? '-d6' : ''}`; const advantageRoll = `${advantageState === true ? '+d6' : advantageState === false ? '-d6' : ''}`;
const attributeRoll = `${trait?.value ? `${trait.value > 0 ? `+${trait.value}` : `${trait.value}`}` : ''}`; const attributeRoll = `${trait?.value ? `${trait.value > 0 ? `+${trait.value}` : `${trait.value}`}` : ''}`;
const roll = new DualityRoll(`${hopeAndFearRoll}${advantageRoll}${attributeRoll}`); const formula = `${hopeAndFearRoll}${advantageRoll}${attributeRoll}`;
await roll.evaluate();
console.log('roll result', roll.result); const config = {
setDiceSoNiceForDualityRoll(roll, advantageState);
resolve({
roll,
trait: trait
? {
value: trait.value,
label: `${game.i18n.localize(abilities[traitValue].label)} ${trait.value >= 0 ? `+` : ``}${trait.value}`
}
: undefined,
title
});
}).then(async ({ roll, trait, title }) => {
const cls = getDocumentClass('ChatMessage');
const systemData = new DHDualityRoll({
title: title, title: title,
origin: target?.id, roll: { formula },
roll: roll, targets: target,
modifiers: trait ? [trait] : [], hasSave: false,
hope: { dice: rollCommand.hope ?? 'd12', value: roll.dice[0].total }, dialog: { configure: false },
fear: { dice: rollCommand.fear ?? 'd12', value: roll.dice[1].total }, evaluate: true
advantage: advantageState !== null ? { dice: 'd6', value: roll.dice[2].total } : undefined,
advantageState
});
const msgData = {
type: 'dualityRoll',
sound: CONFIG.sounds.dice,
system: systemData,
user: game.user.id,
content: 'systems/daggerheart/templates/chat/duality-roll.hbs',
rolls: [roll]
}; };
cls.create(msgData); await CONFIG.Dice.daggerheart['DualityRoll'].build(config);
resolve();
}); });
} }

View file

@ -1,6 +1,10 @@
export default class DhpChatMessage extends foundry.documents.ChatMessage { export default class DhpChatMessage extends foundry.documents.ChatMessage {
async renderHTML() { async renderHTML() {
if(this.system.messageTemplate) this.content = await foundry.applications.handlebars.renderTemplate(this.system.messageTemplate, this.system); if (this.system.messageTemplate)
this.content = await foundry.applications.handlebars.renderTemplate(
this.system.messageTemplate,
this.system
);
/* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */ /* We can change to fully implementing the renderHTML function if needed, instead of augmenting it. */
const html = await super.renderHTML(); const html = await super.renderHTML();
@ -14,7 +18,7 @@ export default class DhpChatMessage extends foundry.documents.ChatMessage {
break; break;
case -1: case -1:
html.classList.add('fear'); html.classList.add('fear');
break; break;
default: default:
html.classList.add('critical'); html.classList.add('critical');
break; break;

View file

@ -1,6 +1,7 @@
import DHDamageRoll from '../data/chat-message/damageRoll.mjs'; import DHDamageRoll from '../data/chat-message/damageRoll.mjs';
import D20RollDialog from '../dialogs/d20RollDialog.mjs'; import D20RollDialog from '../dialogs/d20RollDialog.mjs';
import DamageDialog from '../dialogs/damageDialog.mjs'; import DamageDialog from '../dialogs/damageDialog.mjs';
import { setDiceSoNiceForDualityRoll } from '../helpers/utils.mjs';
/* /*
- Damage & other resources roll - Damage & other resources roll
@ -54,7 +55,6 @@ export class DHRoll extends Roll {
} }
static async buildPost(roll, config, message) { static async buildPost(roll, config, message) {
console.log(config);
for (const hook of config.hooks) { for (const hook of config.hooks) {
if (Hooks.call(`${SYSTEM.id}.postRoll${hook.capitalize()}`, config, message) === false) return null; if (Hooks.call(`${SYSTEM.id}.postRoll${hook.capitalize()}`, config, message) === false) return null;
} }
@ -95,7 +95,8 @@ export class DHRoll extends Roll {
} }
static applyKeybindings(config) { static applyKeybindings(config) {
config.dialog.configure ??= !(config.event.shiftKey || config.event.altKey || config.event.ctrlKey); if (config.event)
config.dialog.configure ??= !(config.event.shiftKey || config.event.altKey || config.event.ctrlKey);
} }
constructFormula(config) { constructFormula(config) {
@ -161,12 +162,20 @@ export class D20Roll extends DHRoll {
} }
static applyKeybindings(config) { static applyKeybindings(config) {
const keys = { let keys = {
normal: config.event.shiftKey || config.event.altKey || config.event.ctrlKey, normal: true,
advantage: config.event.altKey, advantage: false,
disadvantage: config.event.ctrlKey disadvantage: false
}; };
if (config.event) {
keys = {
normal: config.event.shiftKey || config.event.altKey || config.event.ctrlKey,
advantage: config.event.altKey,
disadvantage: config.event.ctrlKey
};
}
// Should the roll configuration dialog be displayed? // Should the roll configuration dialog be displayed?
config.dialog.configure ??= !Object.values(keys).some(k => k); config.dialog.configure ??= !Object.values(keys).some(k => k);
@ -372,12 +381,23 @@ export class DualityRoll extends D20Roll {
} }
applyBaseBonus() { applyBaseBonus() {
this.options.roll.modifiers = [ if (this.options.roll.trait) {
{ this.options.roll.modifiers = [
label: 'HI', {
value: Roll.replaceFormulaData(`@traits.${this.options.roll.trait}.total`, this.data) label: `DAGGERHEART.Abilities.${this.options.roll.trait}.name`,
} value: Roll.replaceFormulaData(`@traits.${this.options.roll.trait}.total`, this.data)
]; }
];
} else {
this.options.roll.modifiers = [];
}
}
static async buildEvaluate(roll, config = {}, message = {}) {
if (config.evaluate !== false) await roll.evaluate();
const advantageState = this.hasAdvantage ? true : this.hasDisadvantage ? false : null;
setDiceSoNiceForDualityRoll(roll, advantageState);
this.postEvaluate(roll, config);
} }
static postEvaluate(roll, config = {}) { static postEvaluate(roll, config = {}) {

View file

@ -1,6 +1,6 @@
import CostSelectionDialog from '../../applications/costSelectionDialog.mjs'; import CostSelectionDialog from '../../applications/costSelectionDialog.mjs';
import { DHActionDiceData, DHActionRollData, DHDamageData, DHDamageField } from './actionDice.mjs'; import { DHActionDiceData, DHActionRollData, DHDamageData, DHDamageField } from './actionDice.mjs';
import DhpActor from '../../documents/actor.mjs'; //import DhpActor from '../../documents/actor.mjs';
import D20RollDialog from '../../dialogs/d20RollDialog.mjs'; import D20RollDialog from '../../dialogs/d20RollDialog.mjs';
const fields = foundry.data.fields; const fields = foundry.data.fields;
@ -129,13 +129,13 @@ export class DHBaseAction extends foundry.abstract.DataModel {
return this.parent.parent; return this.parent.parent;
} }
get actor() { // get actor() {
return this.item instanceof DhpActor // return this.item instanceof DhpActor
? this.item // ? this.item
: this.item?.parent instanceof DhpActor // : this.item?.parent instanceof DhpActor
? this.item.parent // ? this.item.parent
: this.item?.actor; // : this.item?.actor;
} // }
get chatTemplate() { get chatTemplate() {
return 'systems/daggerheart/templates/chat/duality-roll.hbs'; return 'systems/daggerheart/templates/chat/duality-roll.hbs';
@ -402,11 +402,18 @@ export class DHBaseAction extends foundry.abstract.DataModel {
hasCost(costs) { hasCost(costs) {
const realCosts = this.getRealCosts(costs), const realCosts = this.getRealCosts(costs),
hasFearCost = realCosts.findIndex(c => c.type === 'fear'); hasFearCost = realCosts.findIndex(c => c.type === 'fear');
if(hasFearCost > -1) { if (hasFearCost > -1) {
const fearCost = realCosts.splice(hasFearCost, 1); const fearCost = realCosts.splice(hasFearCost, 1);
if(!game.user.isGM || fearCost[0].total > game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear)) return false; if (
!game.user.isGM ||
fearCost[0].total > game.settings.get(SYSTEM.id, SYSTEM.SETTINGS.gameSettings.Resources.Fear)
)
return false;
} }
return realCosts.reduce((a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value), true); return realCosts.reduce(
(a, c) => a && this.actor.system.resources[c.type]?.value >= (c.total ?? c.value),
true
);
} }
/* COST */ /* COST */
@ -498,19 +505,25 @@ export class DHBaseAction extends foundry.abstract.DataModel {
/* SAVE */ /* SAVE */
async rollSave(target, event, message) { async rollSave(target, event, message) {
if(!target?.actor) return; if (!target?.actor) return;
return target.actor.diceRoll({ return target.actor
event, .diceRoll({
title: 'Roll Save', event,
roll: { title: 'Roll Save',
trait: this.save.trait, roll: {
difficulty: this.save.difficulty, trait: this.save.trait,
type: "reaction" difficulty: this.save.difficulty,
}, type: 'reaction'
data: target.actor.getRollData() },
}).then(async (result) => { data: target.actor.getRollData()
if(result) this.updateChatMessage(message, target.id, {result: result.roll.total, success: result.roll.success}); })
}) .then(async result => {
if (result)
this.updateChatMessage(message, target.id, {
result: result.roll.total,
success: result.roll.success
});
});
} }
async updateChatMessage(message, targetId, changes, chain = true) { async updateChatMessage(message, targetId, changes, chain = true) {

View file

@ -124,8 +124,8 @@ export const getCommandTarget = () => {
export const setDiceSoNiceForDualityRoll = (rollResult, advantageState) => { export const setDiceSoNiceForDualityRoll = (rollResult, advantageState) => {
const diceSoNicePresets = getDiceSoNicePresets(); const diceSoNicePresets = getDiceSoNicePresets();
rollResult.dice[0].options.appearance = diceSoNicePresets.hope; rollResult.dice[0].options = { appearance: diceSoNicePresets.hope };
rollResult.dice[1].options.appearance = diceSoNicePresets.fear; rollResult.dice[1].options = { appearance: diceSoNicePresets.fear }; //diceSoNicePresets.fear;
if (rollResult.dice[2]) { if (rollResult.dice[2]) {
if (advantageState === true) { if (advantageState === true) {
rollResult.dice[2].options.appearance = diceSoNicePresets.advantage; rollResult.dice[2].options.appearance = diceSoNicePresets.advantage;