2020-11-24 15:20:05 +01:00
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
2021-12-04 23:02:08 +01:00
|
|
|
import { HIDE_DICE, SHOW_DICE } from "./constants.js";
|
2021-04-29 02:57:56 +02:00
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
2024-10-17 02:07:24 +02:00
|
|
|
const imgHeures = [1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 11, 12].map(heure => {
|
2021-05-01 15:53:26 +02:00
|
|
|
if (heure < 10) {
|
|
|
|
heure = '0' + heure;
|
2021-04-30 00:51:07 +02:00
|
|
|
}
|
2024-10-17 02:07:24 +02:00
|
|
|
return `<img src="systems/foundryvtt-reve-de-dragon/icons/heures/hd${heure}.webp" class="dice-img" />`
|
|
|
|
})
|
2021-04-30 00:51:07 +02:00
|
|
|
|
2024-10-17 02:07:24 +02:00
|
|
|
const imgSigneDragon = imgHeures[4]
|
2021-04-29 02:57:56 +02:00
|
|
|
|
2021-11-21 22:41:53 +01:00
|
|
|
/** De pour les jets de rencontre */
|
2024-07-10 23:16:59 +02:00
|
|
|
export class DeTMR extends Die {
|
2021-04-29 02:57:56 +02:00
|
|
|
/** @override */
|
2021-11-21 22:41:53 +01:00
|
|
|
static DENOMINATION = "t";
|
2021-04-30 00:51:07 +02:00
|
|
|
|
2021-04-29 23:17:29 +02:00
|
|
|
static diceSoNiceData(system) {
|
2021-05-01 15:53:26 +02:00
|
|
|
return {
|
2021-11-21 22:41:53 +01:00
|
|
|
type: "dt",
|
2021-05-01 15:53:26 +02:00
|
|
|
font: "HeuresDraconiques",
|
2024-10-17 02:07:24 +02:00
|
|
|
fontScale: 0.8,
|
2021-05-01 15:53:26 +02:00
|
|
|
labels: ['1', '2', '3', '4', '5', '6', 'd', '0'],
|
|
|
|
system: system
|
|
|
|
}
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
2021-04-30 00:51:07 +02:00
|
|
|
|
2021-04-29 02:57:56 +02:00
|
|
|
constructor(termData) {
|
|
|
|
termData.faces = 8;
|
|
|
|
super(termData);
|
|
|
|
}
|
2021-04-30 00:51:07 +02:00
|
|
|
|
2024-06-14 00:03:06 +02:00
|
|
|
async evaluate(options) {
|
2024-10-17 02:07:24 +02:00
|
|
|
await super.evaluate(options)
|
|
|
|
await this.reroll('r=8', { recursive: true })
|
2021-04-29 02:57:56 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
get total() {
|
2024-10-17 02:07:24 +02:00
|
|
|
return this.values.map(it => Misc.modulo(it, 8)).reduce(Misc.sum(), 0);
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
|
2021-06-02 23:01:32 +02:00
|
|
|
getResultLabel(diceTerm) {
|
|
|
|
switch (diceTerm.result) {
|
2021-05-01 15:53:26 +02:00
|
|
|
case 7: return imgSigneDragon;
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
2021-06-02 23:01:32 +02:00
|
|
|
return diceTerm.result.toString();
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** DeDraconique pour le D8 sans limite avec 8=>0 */
|
2024-07-10 23:16:59 +02:00
|
|
|
export class DeDraconique extends Die {
|
2024-10-17 02:07:24 +02:00
|
|
|
/** @override */
|
2021-04-29 02:57:56 +02:00
|
|
|
static DENOMINATION = "r";
|
|
|
|
|
2021-04-29 23:17:29 +02:00
|
|
|
static diceSoNiceData(system) {
|
2021-05-01 15:53:26 +02:00
|
|
|
return {
|
|
|
|
type: "dr",
|
|
|
|
font: "HeuresDraconiques",
|
2024-10-17 02:07:24 +02:00
|
|
|
fontScale: 0.8,
|
2021-05-01 15:53:26 +02:00
|
|
|
labels: ['1', '2', '3', '4', '5', '6', 'd', '0'],
|
|
|
|
system: system
|
|
|
|
}
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
constructor(termData) {
|
|
|
|
termData.faces = 8;
|
|
|
|
super(termData);
|
|
|
|
}
|
|
|
|
|
2024-06-14 00:03:06 +02:00
|
|
|
async evaluate(options) {
|
|
|
|
await super.evaluate(options);
|
2024-10-17 02:07:24 +02:00
|
|
|
await this.explode("x=7");
|
2021-04-29 02:57:56 +02:00
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
get total() {
|
|
|
|
return this.values.filter(it => it != 8).reduce(Misc.sum(), 0);
|
|
|
|
}
|
|
|
|
|
2021-06-02 23:01:32 +02:00
|
|
|
getResultLabel(diceTerm) {
|
|
|
|
switch (diceTerm.result) {
|
2024-10-17 02:07:24 +02:00
|
|
|
case 7: return imgSigneDragon
|
2021-06-02 23:01:32 +02:00
|
|
|
case 8: return '0';
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
2021-06-02 23:01:32 +02:00
|
|
|
return diceTerm.result.toString();
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
}
|
2020-11-24 15:20:05 +01:00
|
|
|
|
2021-04-30 00:51:07 +02:00
|
|
|
/** De 12 avec les heures */
|
2024-07-10 23:16:59 +02:00
|
|
|
export class DeHeure extends Die {
|
2021-04-30 00:51:07 +02:00
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static DENOMINATION = "h";
|
|
|
|
|
|
|
|
static diceSoNiceData(system) {
|
|
|
|
return {
|
|
|
|
type: "dh",
|
2021-05-01 15:53:26 +02:00
|
|
|
font: "HeuresDraconiques",
|
2024-10-17 02:07:24 +02:00
|
|
|
fontScale: 1.2,
|
2021-05-01 15:53:26 +02:00
|
|
|
labels: ['v', 'i', 'f', 'o', 'd', 'e', 'l', 's', 'p', 'a', 'r', 'c'],
|
2021-04-30 00:51:07 +02:00
|
|
|
system: system
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
constructor(termData) {
|
|
|
|
termData.faces = 12;
|
|
|
|
super(termData);
|
|
|
|
}
|
|
|
|
|
2021-06-02 23:01:32 +02:00
|
|
|
getResultLabel(diceTerm) {
|
2024-10-17 02:07:24 +02:00
|
|
|
return imgHeures[diceTerm.result - 1]
|
2021-04-30 00:51:07 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-11-16 03:54:43 +01:00
|
|
|
export class RdDDice {
|
2021-04-29 02:57:56 +02:00
|
|
|
static init() {
|
2024-10-17 02:07:24 +02:00
|
|
|
CONFIG.Dice.terms[DeTMR.DENOMINATION] = DeTMR
|
|
|
|
CONFIG.Dice.terms[DeDraconique.DENOMINATION] = DeDraconique
|
|
|
|
CONFIG.Dice.terms[DeHeure.DENOMINATION] = DeHeure
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
2021-12-03 22:53:38 +01:00
|
|
|
|
2021-06-02 16:14:41 +02:00
|
|
|
static onReady() {
|
|
|
|
if (game.modules.get("dice-so-nice")?.active) {
|
|
|
|
if (game.settings.get("core", "noCanvas")) {
|
|
|
|
ui.notifications.warn("Dice So Nice! n'affichera pas de dés car vous avez coché l'option de Foundry 'Scène de jeu désactivé' 'Disable Game Canvas' ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-29 02:57:56 +02:00
|
|
|
|
2024-10-17 02:07:24 +02:00
|
|
|
static diceSoNiceReady(dice3d) {
|
|
|
|
dice3d.DiceFactory.systems.keys().forEach(system => {
|
|
|
|
dice3d.addDicePreset(DeTMR.diceSoNiceData(system));
|
|
|
|
dice3d.addDicePreset(DeDraconique.diceSoNiceData(system));
|
|
|
|
dice3d.addDicePreset(DeHeure.diceSoNiceData(system));
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2024-10-02 00:46:11 +02:00
|
|
|
static async rollHeure(options = { showDice: HIDE_DICE }) {
|
|
|
|
return await RdDDice.rollTotal("1dh", options) - 1
|
|
|
|
}
|
|
|
|
|
2022-10-08 17:36:11 +02:00
|
|
|
static async rollTotal(formula, options = { showDice: HIDE_DICE }) {
|
|
|
|
return (await RdDDice.roll(formula, options)).total;
|
|
|
|
}
|
|
|
|
|
2021-12-03 22:53:38 +01:00
|
|
|
static async roll(formula, options = { showDice: SHOW_DICE, rollMode: undefined }) {
|
2022-10-08 17:36:11 +02:00
|
|
|
const roll = new Roll(RdDDice._formulaOrFake(formula, options));
|
2024-05-31 21:48:19 +02:00
|
|
|
await roll.evaluate();
|
2022-10-08 17:36:11 +02:00
|
|
|
await this.showDiceSoNice(roll, options);
|
2021-05-11 21:45:43 +02:00
|
|
|
return roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async rollOneOf(array) {
|
2022-11-16 03:00:38 +01:00
|
|
|
if (array == undefined || array.length == 0) {
|
|
|
|
return undefined;
|
|
|
|
}
|
2021-05-11 21:45:43 +02:00
|
|
|
const roll = await RdDDice.rollTotal(`1d${array.length}`);
|
2021-06-02 16:14:41 +02:00
|
|
|
return array[roll - 1];
|
2021-05-11 21:45:43 +02:00
|
|
|
}
|
|
|
|
|
2020-11-16 03:54:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-10-08 17:36:11 +02:00
|
|
|
static async showDiceSoNice(roll, options) {
|
|
|
|
if (options.showDice == HIDE_DICE || !game.modules.get("dice-so-nice")?.active || !game.dice3d) {
|
|
|
|
return;
|
|
|
|
}
|
2023-11-20 00:37:43 +01:00
|
|
|
|
2024-10-16 23:18:15 +02:00
|
|
|
let { whisper, blind } = ChatUtility.applyRollMode({}, options?.rollMode);
|
2022-10-08 17:36:11 +02:00
|
|
|
if (options.forceDiceResult?.total) {
|
|
|
|
let terms = await RdDDice._getForcedTerms(options);
|
|
|
|
if (terms) {
|
|
|
|
await game.dice3d.show({ throws: [{ dice: terms }] })
|
|
|
|
return;
|
2020-11-16 03:54:43 +01:00
|
|
|
}
|
|
|
|
}
|
2022-10-08 17:36:11 +02:00
|
|
|
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
|
|
|
|
}
|
|
|
|
|
|
|
|
static _formulaOrFake(formula, options) {
|
|
|
|
if (options?.forceDiceResult?.total) {
|
|
|
|
options.forceDiceResult.formula = formula;
|
|
|
|
return options.forceDiceResult.total.toString()
|
|
|
|
}
|
|
|
|
return formula;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async _getForcedTerms(options) {
|
|
|
|
const total = options.forceDiceResult.total;
|
|
|
|
switch (options.forceDiceResult.formula) {
|
|
|
|
case '1d100':
|
|
|
|
return terms1d100(total);
|
|
|
|
case "2d10":
|
2022-10-09 02:19:33 +02:00
|
|
|
return await terms2d10(total);
|
2022-10-08 17:36:11 +02:00
|
|
|
}
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
function terms1d100(total) {
|
|
|
|
const unites = total % 10;
|
|
|
|
const dizaines = Math.floor(total / 10);
|
2023-11-20 00:37:43 +01:00
|
|
|
return [
|
|
|
|
{ type: "d100", result: dizaines, resultLabel: dizaines * 10, vectors: [], options: {}, d100Result: total },
|
|
|
|
{ type: "d10", result: unites, resultLabel: unites, vectors: [], options: {}, d100Result: total }
|
|
|
|
];
|
2022-10-08 17:36:11 +02:00
|
|
|
}
|
2022-10-09 02:19:33 +02:00
|
|
|
|
|
|
|
async function terms2d10(total) {
|
2023-11-20 00:37:43 +01:00
|
|
|
if (total > 20 || total < 2) { return undefined }
|
|
|
|
const first = await RdDDice.fakeD10(Math.min(10, total - 1));
|
|
|
|
const second = total - first;
|
|
|
|
return [
|
|
|
|
{ type: "d10", result: first, resultLabel: first, vectors: [], options: {} },
|
|
|
|
{ type: "d10", result: second, resultLabel: second, vectors: [], options: {} }
|
|
|
|
];
|
2022-10-09 02:19:33 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-20 00:37:43 +01:00
|
|
|
static async fakeD10(faces) {
|
|
|
|
let roll = new Roll(`1d${faces}`);
|
2024-05-31 21:48:19 +02:00
|
|
|
await roll.evaluate();
|
2022-10-09 02:19:33 +02:00
|
|
|
return roll.total;
|
2022-10-08 17:36:11 +02:00
|
|
|
}
|
2020-11-16 03:54:43 +01:00
|
|
|
}
|