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 bfe1578c..105984cb 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"; @@ -543,7 +542,7 @@ export class RdDActor extends Actor { message.content += `Vous avez suffisament rêvé, au delà de votre seuil. `; } 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 abfa4d45..00000000 --- a/module/de-draconique.js +++ /dev/null @@ -1,27 +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] = rerolls; - this.results[this.results.length - 1] = 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 db0985d7..bce05efc 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"; @@ -258,7 +257,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 81d41057..9ba7aa11 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 0d030779..dbdc66d0 100644 --- a/module/rdd-main.js +++ b/module/rdd-main.js @@ -22,13 +22,13 @@ import { RdDTokenHud } from "./rdd-token-hud.js"; import { RdDCommands } from "./rdd-commands.js"; import { RdDCombatManager, RdDCombat } from "./rdd-combat.js"; import { ChatUtility } from "./chat-utility.js"; -import { RdDItemCompetence } from "./item-competence.js"; import { StatusEffects } from "./status-effects.js"; import { RddCompendiumOrganiser } from "./rdd-compendium-organiser.js"; import { ReglesOptionelles } from "./regles-optionelles.js"; import { TMRRencontres } from "./tmr-rencontres.js"; import { RdDHotbar } from "./rdd-hotbar-drop.js" import { EffetsDraconiques } from "./tmr/effets-draconiques.js"; +import { RdDDice } from "./rdd-dice.js"; /* -------------------------------------------- */ /* Foundry VTT Initialization */ @@ -154,6 +154,7 @@ Hooks.once("init", async function () { CONFIG.Combat.entityClass = RdDCombatManager; // préparation des différents modules + RdDDice.init(); RdDCommands.init(); RdDCombat.init(); RdDCombatManager.init(), @@ -212,7 +213,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 6905b6cc..4babca0f 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 {