2021-06-26 22:02:00 +02:00
|
|
|
// SPDX-FileCopyrightText: 2021 Johannes Loher
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
|
2021-03-14 08:47:03 +01:00
|
|
|
import { DS4Check } from "./check";
|
|
|
|
|
|
|
|
export class DS4Roll<D extends Record<string, unknown> = Record<string, unknown>> extends Roll<D> {
|
2021-04-25 18:31:19 +02:00
|
|
|
static CHAT_TEMPLATE = "systems/ds4/templates/dice/roll.hbs";
|
2021-03-14 08:47:03 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2021-06-30 04:32:10 +02:00
|
|
|
async render(chatOptions: Parameters<Roll["render"]>[0] = {}): Promise<string> {
|
2021-07-01 01:08:30 +02:00
|
|
|
chatOptions = foundry.utils.mergeObject(
|
2021-03-14 08:47:03 +01:00
|
|
|
{
|
2021-06-30 04:32:10 +02:00
|
|
|
user: game.user?.id,
|
2021-03-14 08:47:03 +01:00
|
|
|
flavor: null,
|
|
|
|
template: DS4Roll.CHAT_TEMPLATE,
|
|
|
|
blind: false,
|
|
|
|
},
|
|
|
|
chatOptions,
|
|
|
|
);
|
|
|
|
const isPrivate = chatOptions.isPrivate;
|
|
|
|
|
|
|
|
// Execute the roll, if needed
|
2021-06-30 04:32:10 +02:00
|
|
|
if (!this._evaluated) this.evaluate();
|
2021-03-14 08:47:03 +01:00
|
|
|
|
|
|
|
// 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
|
2021-03-16 07:11:12 +01:00
|
|
|
return renderTemplate(chatOptions.template ?? "", chatData);
|
2021-03-14 08:47:03 +01:00
|
|
|
}
|
|
|
|
}
|