ds4/src/module/rolls/roll.ts

45 lines
1.6 KiB
TypeScript
Raw Normal View History

import { DS4Check } from "./check";
export class DS4Roll<D extends Record<string, unknown> = Record<string, unknown>> extends Roll<D> {
static CHAT_TEMPLATE = "systems/ds4/templates/roll/roll.hbs";
/**
* This only differs from {@link Roll.render} in that it provides `isCoup` and `isFumble` properties to the roll
* template if the first dice term is a ds4 check.
* @override
*/
async render(chatOptions: Roll.ChatOptions = {}): Promise<string> {
chatOptions = mergeObject(
{
user: game.user?._id,
flavor: null,
template: DS4Roll.CHAT_TEMPLATE,
blind: false,
},
chatOptions,
);
const isPrivate = chatOptions.isPrivate;
// Execute the roll, if needed
if (!this._rolled) this.roll();
// Define chat data
const firstDiceTerm = this.dice[0];
const isCoup = firstDiceTerm instanceof DS4Check && firstDiceTerm.coup;
const isFumble = firstDiceTerm instanceof DS4Check && firstDiceTerm.fumble;
const chatData = {
formula: isPrivate ? "???" : this._formula,
flavor: isPrivate ? null : chatOptions.flavor,
user: chatOptions.user,
tooltip: isPrivate ? "" : await this.getTooltip(),
total: isPrivate ? "?" : Math.round((this.total ?? 0) * 100) / 100,
isCoup: isPrivate ? null : isCoup,
isFumble: isPrivate ? null : isFumble,
};
// Render the roll display template
return renderTemplate(chatOptions.template ?? "", chatData);
}
}