ds4/src/dice/roll.js

35 lines
1.2 KiB
JavaScript
Raw Normal View History

2021-06-26 22:02:00 +02:00
// SPDX-FileCopyrightText: 2021 Johannes Loher
//
// SPDX-License-Identifier: MIT
2022-11-04 21:47:18 +01:00
import { getGame } from "../utils/utils";
import { DS4Check } from "./check";
export class DS4Roll extends Roll {
2023-07-10 22:23:13 +02:00
/** @override */
static CHAT_TEMPLATE = "systems/ds4/templates/dice/roll.hbs";
2023-07-10 22:23:13 +02:00
/**
* @override
* @remarks
* 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.
*/
async render({ flavor, template = this.constructor.CHAT_TEMPLATE, isPrivate = false } = {}) {
if (!this._evaluated) await this.evaluate({ async: true });
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 : flavor,
user: getGame().user?.id,
tooltip: isPrivate ? "" : await this.getTooltip(),
total: isPrivate ? "?" : Math.round((this.total ?? 0) * 100) / 100,
isCoup: isPrivate ? null : isCoup,
isFumble: isPrivate ? null : isFumble,
};
return renderTemplate(template, chatData);
}
}