foundryvtt-reve-de-dragon/module/rdd-dice.js
Vincent Vandemeulebrouck a0c1d063f1 Fix dé dragon sans bords pour tous
Pas uniquement pour le système rdd
2021-04-30 00:51:38 +02:00

116 lines
3.1 KiB
JavaScript

import { ChatUtility } from "./chat-utility.js";
import { SYSTEM_RDD } from "./constants.js";
import { Misc } from "./misc.js";
const signeDragon = 'systems/foundryvtt-reve-de-dragon/icons/heures/hdragon.webp';
const imgSigneDragon = `<img src="${signeDragon}" class="dice-img" />`;
const labelsDeDragon = ['1', '2', '3', '4', '5', '6', signeDragon, '0'];
const bumpsDeDragon = [, , , , , , signeDragon, ];
/** De7 pour les jets de rencontre */
export class De7 extends Die {
/** @override */
static DENOMINATION = "7";
static diceSoNiceData(system) {
return { type: "d7", labels: labelsDeDragon, bumpMaps: bumpsDeDragon, system: system }
}
constructor(termData) {
termData.faces = 8;
super(termData);
}
evaluate() {
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) {
case 7: return imgSigneDragon
}
return result;
}
}
/** DeDraconique pour le D8 sans limite avec 8=>0 */
export class DeDraconique extends Die {
static DENOMINATION = "r";
static diceSoNiceData(system) {
return { type: "dr", labels: labelsDeDragon, bumpMaps: bumpsDeDragon, system: system }
}
constructor(termData) {
termData.faces = 8;
super(termData);
}
evaluate() {
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) {
case 7: return imgSigneDragon
}
return result;
}
}
export class RdDDice {
static init() {
CONFIG.Dice.terms[De7.DENOMINATION] = De7;
CONFIG.Dice.terms[DeDraconique.DENOMINATION] = DeDraconique;
}
static diceSoNiceReady(dice3d) {
for (const system of Object.keys(dice3d.DiceFactory.systems)) {
dice3d.addDicePreset(De7.diceSoNiceData(system));
dice3d.addDicePreset(DeDraconique.diceSoNiceData(system));
}
}
/* -------------------------------------------- */
static async show(roll, rollMode = undefined) {
if (roll.showDice || game.settings.get(SYSTEM_RDD, "dice-so-nice") == true) {
await this.showDiceSoNice(roll, rollMode);
}
return roll;
}
/* -------------------------------------------- */
static async showDiceSoNice(roll, rollMode = undefined) {
if (game.modules.get("dice-so-nice") && game.modules.get("dice-so-nice").active) {
let whisper = null;
let blind = false;
rollMode = rollMode ?? game.settings.get("core", "rollMode");
switch (rollMode) {
case "blindroll": //GM only
blind = true;
case "gmroll": //GM + rolling player
whisper = ChatUtility.getUsers(user => user.isGM);
break;
case "roll": //everybody
whisper = ChatUtility.getUsers(user => user.active);
break;
case "selfroll":
whisper = [game.user._id];
break;
}
await game.dice3d.showForRoll(roll, game.user, true, whisper, blind);
}
}
}