2020-11-24 15:20:05 +01:00
|
|
|
import { ChatUtility } from "./chat-utility.js";
|
2021-04-29 02:57:56 +02:00
|
|
|
import { SYSTEM_RDD } from "./constants.js";
|
|
|
|
import { Misc } from "./misc.js";
|
|
|
|
|
2021-04-30 00:51:07 +02:00
|
|
|
function img(src) {
|
|
|
|
return `<img src="${src}" class="dice-img" />`
|
|
|
|
}
|
|
|
|
|
2021-05-01 15:53:26 +02:00
|
|
|
function iconHeure(heure) {
|
|
|
|
if (heure < 10) {
|
|
|
|
heure = '0' + heure;
|
2021-04-30 00:51:07 +02:00
|
|
|
}
|
|
|
|
return `systems/foundryvtt-reve-de-dragon/icons/heures/hd${heure}.webp`
|
|
|
|
}
|
2021-05-01 15:53:26 +02:00
|
|
|
const imagesHeures = [1, 2, 3, 4, 5, 6, 7, 9, 9, 10, 11, 12].map(it => iconHeure(it));
|
2021-04-30 00:51:07 +02:00
|
|
|
|
2021-05-01 15:53:26 +02:00
|
|
|
const imgSigneDragon = img(imagesHeures[4]);
|
2021-04-29 02:57:56 +02:00
|
|
|
|
|
|
|
/** De7 pour les jets de rencontre */
|
|
|
|
export class De7 extends Die {
|
|
|
|
/** @override */
|
|
|
|
static DENOMINATION = "7";
|
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 {
|
|
|
|
type: "d7",
|
|
|
|
font: "HeuresDraconiques",
|
2021-05-11 21:45:43 +02:00
|
|
|
fontScale: 0.7,
|
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
|
|
|
|
2021-05-11 21:45:43 +02:00
|
|
|
async evaluate() {
|
2021-04-29 02:57:56 +02:00
|
|
|
super.evaluate();
|
|
|
|
this.explode("x=8");
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
get total() {
|
|
|
|
return this.values.filter(it => it != 8).reduce(Misc.sum(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getResultLabel(result) {
|
|
|
|
switch (result) {
|
2021-05-01 15:53:26 +02:00
|
|
|
case 7: return imgSigneDragon;
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/** DeDraconique pour le D8 sans limite avec 8=>0 */
|
|
|
|
export class DeDraconique extends Die {
|
|
|
|
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",
|
2021-05-11 21:45:43 +02:00
|
|
|
fontScale: 0.7,
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-11 21:45:43 +02:00
|
|
|
async evaluate() {
|
2021-04-29 02:57:56 +02:00
|
|
|
super.evaluate();
|
|
|
|
this.explode("x=7");
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
|
|
|
get total() {
|
|
|
|
return this.values.filter(it => it != 8).reduce(Misc.sum(), 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getResultLabel(result) {
|
|
|
|
switch (result) {
|
2021-05-01 15:53:26 +02:00
|
|
|
case 7: return imgSigneDragon;
|
|
|
|
case 8: return 0;
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2020-11-24 15:20:05 +01:00
|
|
|
|
2021-04-30 00:51:07 +02:00
|
|
|
/** De 12 avec les heures */
|
|
|
|
export class DeHeure extends Die {
|
|
|
|
|
|
|
|
/** @override */
|
|
|
|
static DENOMINATION = "h";
|
|
|
|
|
|
|
|
static diceSoNiceData(system) {
|
|
|
|
return {
|
|
|
|
type: "dh",
|
2021-05-01 15:53:26 +02:00
|
|
|
font: "HeuresDraconiques",
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
static getResultLabel(result) {
|
2021-05-11 21:45:43 +02:00
|
|
|
return img(imagesHeures[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() {
|
|
|
|
CONFIG.Dice.terms[De7.DENOMINATION] = De7;
|
|
|
|
CONFIG.Dice.terms[DeDraconique.DENOMINATION] = DeDraconique;
|
2021-04-30 00:51:07 +02:00
|
|
|
CONFIG.Dice.terms[DeHeure.DENOMINATION] = DeHeure;
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
|
|
|
|
2021-05-11 21:45:43 +02:00
|
|
|
static async roll(formula, options = { showDice: false }) {
|
|
|
|
const roll = new Roll(formula);
|
|
|
|
await roll.evaluate({ async: true });
|
|
|
|
if (options.showDice) {
|
|
|
|
roll.showDice = options.showDice;
|
|
|
|
}
|
|
|
|
await RdDDice.show(roll, game.settings.get("core", "rollMode"));
|
|
|
|
return roll;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async rollTotal(formula) {
|
|
|
|
const roll = new Roll(formula);
|
|
|
|
await roll.evaluate({ async: true });
|
|
|
|
return roll.total;
|
|
|
|
}
|
|
|
|
|
|
|
|
static async rollOneOf(array) {
|
|
|
|
const roll = await RdDDice.rollTotal(`1d${array.length}`);
|
|
|
|
return array[roll-1];
|
|
|
|
}
|
|
|
|
|
2021-04-29 02:57:56 +02:00
|
|
|
static diceSoNiceReady(dice3d) {
|
2021-04-29 23:17:29 +02:00
|
|
|
for (const system of Object.keys(dice3d.DiceFactory.systems)) {
|
|
|
|
dice3d.addDicePreset(De7.diceSoNiceData(system));
|
|
|
|
dice3d.addDicePreset(DeDraconique.diceSoNiceData(system));
|
2021-04-30 00:51:07 +02:00
|
|
|
dice3d.addDicePreset(DeHeure.diceSoNiceData(system));
|
2021-04-29 23:17:29 +02:00
|
|
|
}
|
2021-04-29 02:57:56 +02:00
|
|
|
}
|
2020-11-16 03:54:43 +01:00
|
|
|
|
2020-11-21 09:10:31 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-24 15:20:05 +01:00
|
|
|
static async show(roll, rollMode = undefined) {
|
2021-04-29 02:57:56 +02:00
|
|
|
if (roll.showDice || game.settings.get(SYSTEM_RDD, "dice-so-nice") == true) {
|
2020-11-21 09:10:31 +01:00
|
|
|
await this.showDiceSoNice(roll, rollMode);
|
2020-11-17 11:35:05 +01:00
|
|
|
}
|
2020-11-16 03:54:43 +01:00
|
|
|
return roll;
|
|
|
|
}
|
2021-04-29 02:57:56 +02:00
|
|
|
|
2020-11-16 03:54:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-11-24 15:20:05 +01:00
|
|
|
static async showDiceSoNice(roll, rollMode = undefined) {
|
2020-11-16 03:54:43 +01:00
|
|
|
if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) {
|
|
|
|
let whisper = null;
|
|
|
|
let blind = false;
|
2021-01-09 19:33:19 +01:00
|
|
|
rollMode = rollMode ?? game.settings.get("core", "rollMode");
|
2020-11-16 03:54:43 +01:00
|
|
|
switch (rollMode) {
|
|
|
|
case "blindroll": //GM only
|
|
|
|
blind = true;
|
|
|
|
case "gmroll": //GM + rolling player
|
2020-11-24 18:39:27 +01:00
|
|
|
whisper = ChatUtility.getUsers(user => user.isGM);
|
2020-11-16 03:54:43 +01:00
|
|
|
break;
|
|
|
|
case "roll": //everybody
|
2020-11-24 18:39:27 +01:00
|
|
|
whisper = ChatUtility.getUsers(user => user.active);
|
2020-11-24 15:20:05 +01:00
|
|
|
break;
|
|
|
|
case "selfroll":
|
2021-03-25 03:18:27 +01:00
|
|
|
whisper = [game.user.id];
|
2020-11-16 03:54:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|