diff --git a/icons/heures/hdragon.webp b/icons/heures/hdragon.webp new file mode 100644 index 00000000..48659c68 Binary files /dev/null and b/icons/heures/hdragon.webp differ diff --git a/module/actor.js b/module/actor.js index 097b4348..82187227 100644 --- a/module/actor.js +++ b/module/actor.js @@ -13,7 +13,6 @@ import { RdDItemSort } from "./item-sort.js"; import { Grammar } from "./grammar.js"; import { RdDEncaisser } from "./rdd-roll-encaisser.js"; import { RdDCombat } from "./rdd-combat.js"; -import { DeDraconique } from "./de-draconique.js"; import { RdDAudio } from "./rdd-audio.js"; import { RdDItemCompetence } from "./item-competence.js"; import { RdDItemArme } from "./item-arme.js"; @@ -629,7 +628,7 @@ export class RdDActor extends Actor { } } else { - let deRecuperation = (await DeDraconique.ddr("selfroll")).total; + let deRecuperation = new Roll("1dr + 7").evaluate().total; console.log("recuperationReve", deRecuperation); if (deRecuperation >= 7) { // Rêve de Dragon ! diff --git a/module/constants.js b/module/constants.js new file mode 100644 index 00000000..708e4ab5 --- /dev/null +++ b/module/constants.js @@ -0,0 +1 @@ +export const SYSTEM_RDD = "foundryvtt-reve-de-dragon"; diff --git a/module/de-draconique.js b/module/de-draconique.js deleted file mode 100644 index 4cd5d6bd..00000000 --- a/module/de-draconique.js +++ /dev/null @@ -1,26 +0,0 @@ -import { RdDDice } from "./rdd-dice.js"; - -export class DeDraconique extends Roll{ - - static async ddr(rollMode=undefined) { - let ddr = new DeDraconique().evaluate(); - await RdDDice.show(ddr, rollMode); - return ddr; - } - - constructor(){ - super("1d8x8 - 0") - } - - evaluate() { - super.evaluate(); - const rerolls = Math.ceil(this.total / 8); - this.terms[this.terms.length - 1].number = rerolls; - this._total -= rerolls; - return this; - } - - async render(chatOptions) { - return super.render(chatOptions) - } -} \ No newline at end of file diff --git a/module/rdd-commands.js b/module/rdd-commands.js index 996b6972..f8b44405 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -1,6 +1,5 @@ /* -------------------------------------------- */ -import { DeDraconique } from "./de-draconique.js"; import { RdDItemCompetence } from "./item-competence.js"; import { Misc } from "./misc.js"; import { RdDCarac } from "./rdd-carac.js"; @@ -272,7 +271,7 @@ export class RdDCommands { /* -------------------------------------------- */ async rollDeDraconique(msg) { - let ddr = new DeDraconique().evaluate(); + let ddr = new Roll("1dr + 7").evaluate(); ddr.showDice = true; await RdDDice.showDiceSoNice(ddr); RdDCommands._chatAnswer(msg, `Lancer d'un Dé draconique: ${ddr.total}`); diff --git a/module/rdd-dice.js b/module/rdd-dice.js index 94df5543..03e74da4 100644 --- a/module/rdd-dice.js +++ b/module/rdd-dice.js @@ -1,15 +1,95 @@ 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 = ``; +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() { + return { type: "d7", labels: labelsDeDragon, bumpMaps: bumpsDeDragon, system: SYSTEM_RDD } + } + + 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() { + return { type: "dr", labels: labelsDeDragon, bumpMaps: bumpsDeDragon, system: SYSTEM_RDD } + } + + 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) { + dice3d.addSystem({ id: SYSTEM_RDD, name: "Rêve de Dragon" }); + dice3d.addDicePreset(De7.diceSoNiceData()); + dice3d.addDicePreset(DeDraconique.diceSoNiceData()); + } /* -------------------------------------------- */ static async show(roll, rollMode = undefined) { - if (roll.showDice || game.settings.get("foundryvtt-reve-de-dragon", "dice-so-nice") == true) { + 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) { diff --git a/module/rdd-main.js b/module/rdd-main.js index f76c177c..5e9cadcc 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -30,6 +30,7 @@ import { RdDHotbar } from "./rdd-hotbar-drop.js" import { EffetsDraconiques } from "./tmr/effets-draconiques.js"; import { RdDHerbes } from "./rdd-herbes.js"; import { RdDItem } from "./item.js"; +import { RdDDice } from "./rdd-dice.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -171,6 +172,7 @@ Hooks.once("init", async function () { // préparation des différents modules RdDUtility.init(); + RdDDice.init(); RdDCommands.init(); RdDCombat.init(); RdDCombatManager.init(), @@ -230,7 +232,12 @@ Hooks.once("ready", function () { }); /* -------------------------------------------- */ -/* Foundry VTT Initialization */ +/* Dice-so-nice ready */ +/* -------------------------------------------- */ +Hooks.once('diceSoNiceReady', (dice3d) => RdDDice.diceSoNiceReady(dice3d)); + +/* -------------------------------------------- */ +/* Foundry VTT chat message */ /* -------------------------------------------- */ Hooks.on("chatMessage", (html, content, msg) => { if (content[0] == '/') { diff --git a/module/tmr-rencontres.js b/module/tmr-rencontres.js index 0a98c6cf..4c03dd19 100644 --- a/module/tmr-rencontres.js +++ b/module/tmr-rencontres.js @@ -1,4 +1,3 @@ -import { DeDraconique } from "./de-draconique.js"; import { Grammar } from "./grammar.js"; import { Misc } from "./misc.js"; import { TMRUtility } from "./tmr-utility.js"; @@ -382,7 +381,7 @@ export class TMRRencontres { /* -------------------------------------------- */ static async evaluerForceRencontre(rencontre) { if (TMRRencontres.isReveDeDragon(rencontre)) { - const ddr = await DeDraconique.ddr("selfroll") + const ddr = new Roll("1dr + 7").evaluate(); rencontre.force = 7 + ddr.total; } else {