From a532a989d6e2987a09b376f84666f3a474c407b5 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 25 Mar 2021 00:14:56 +0100 Subject: [PATCH 1/3] Jets de masse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Quelques exemples: - `/rdd dexterite bricolage -2` - `/rdd vue survie en sous-sol -2` - `/rdd vue désert 0` - `/rdd vue vigi -3` - `/rdd vol vigi 0` : Volonté Vigilance - `/rdd chance-actuelle 0` - `/rdd reve-actuel -8` Attention: - `/rdd vue vig 0` => Navigation et Vigilance correspondent, c'est Navigation qui est pris (premier dans l'ordre alphabétique), avec un message. --- module/actor.js | 64 +++++++++++++++++++++++++++++++-------- module/item-competence.js | 15 +++++++-- module/rdd-commands.js | 31 ++++++++++++++++--- 3 files changed, 92 insertions(+), 18 deletions(-) diff --git a/module/actor.js b/module/actor.js index 8097e01c..55427b63 100644 --- a/module/actor.js +++ b/module/actor.js @@ -171,8 +171,8 @@ export class RdDActor extends Actor { } /* -------------------------------------------- */ getReveActuel() { - const actorData = Misc.data(this); - return Misc.toInt(actorData.data.reve?.reve?.value ?? actorData.data.carac.reve.value); + const templateData = Misc.templateData(this); + return Misc.toInt(templateData.reve?.reve?.value ?? templateData.carac.reve.value); } /* -------------------------------------------- */ getChanceActuel() { @@ -1613,6 +1613,12 @@ export class RdDActor extends Actor { return 0; } + /* -------------------------------------------- */ + appliquerExperience(rollData) { + const callback = this.createCallbackExperience(); + if (callback.condition(rollData)) { callback.action(rollData); } + } + /* -------------------------------------------- */ createCallbackExperience() { return { @@ -1948,6 +1954,32 @@ export class RdDActor extends Actor { RdDResolutionTable.displayRollData(rollData, this, 'chat-resultat-general.html'); } + async rollCaracCompetence(caracName, compName, diff) { + const carac = this.getCaracByName(caracName); + if (!carac) { + ui.notifications.warn(`${this.name} n'a pas de caractéristique correspondant à ${caracName}`) + return; + } + const competence = this.getCompetence(compName); + if (compName && !competence) { + ui.notifications.warn(`${this.name} n'a pas de compétence correspondant à ${compName}`) + return; + } + let rollData = { + alias: this.name, + caracValue: Number(carac.value), + selectedCarac: carac, + competence: competence, + finalLevel: (competence?.data.niveau??0) + diff, + diffLibre: diff, + showDice: true, + show: { title: "Jets multiples" } + }; + await RdDResolutionTable.rollData(rollData); + this.appliquerExperience(rollData); + RdDResolutionTable.displayRollData( rollData, this ) + } + /* -------------------------------------------- */ async rollCompetence(name) { let rollData = { competence: this.getCompetence(name) } @@ -2380,19 +2412,29 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ static _findCaracByName(carac, name) { - name = name.toLowerCase(); + name = Grammar.toLowerCaseNoAccent(name); switch (name) { case 'reve-actuel': case 'rêve actuel': return carac.reve; case 'chance-actuelle': case 'chance actuelle': return carac.chance; } - for (const [key, value] of Object.entries(carac)) { - if (name == key || name == value.label.toLowerCase()) { - return carac[key]; - } + const keys = Object.entries(carac) + .filter(it => it[0].includes(name) || Grammar.toLowerCaseNoAccent(it[1].label).includes(name)) + .map(it => it[0]); + if (keys.length>1){ + const names = keys.reduce((a, b) => `${a}
${b}`); + ui.notifications.info(`Plusieurs caractéristiques possibles:
${names}
La première sera choisie.`); } - return carac[name]; // Per default + if (keys.length>0){ + return carac[keys[0]]; + } + // for (const [key, value] of Object.entries(carac)) { + // if (key.includes(name) || Grammar.toLowerCaseNoAccent(value.label).includes('name')) { + // return carac[key]; + // } + // } + return undefined; // Per default } /* -------------------------------------------- */ @@ -3070,22 +3112,20 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ _deleteStatusEffectsByIds(effectIds, options) { this.deleteEmbeddedEntity('ActiveEffect', effectIds, options); - this.applyActiveEffects(); } /* -------------------------------------------- */ - async addStatusEffectById(id, options = { renderSheet: true }) { + async addStatusEffectById(id, options = { renderSheet: false }) { const statusEffect = CONFIG.statusEffects.find(it => it.id == id); await this.addStatusEffect(statusEffect, options); } /* -------------------------------------------- */ - async addStatusEffect(statusEffect, options = { renderSheet: true }) { + async addStatusEffect(statusEffect, options = { renderSheet: false }) { this.deleteStatusEffectById(statusEffect.id, options); const effet = duplicate(statusEffect); effet["flags.core.statusId"] = effet.id; await this.createEmbeddedEntity('ActiveEffect', effet, options); - this.applyActiveEffects(); } /* -------------------------------------------- */ diff --git a/module/item-competence.js b/module/item-competence.js index a399e6fd..a07482b9 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -1,3 +1,5 @@ +import { Grammar } from "./grammar.js"; + const competenceTroncs = [["Esquive", "Dague", "Corps à corps"], ["Epée à 1 main", "Epée à 2 mains", "Hache à 1 main", "Hache à 2 mains", "Lance", "Masse à 1 main", "Masse à 2 mains"]]; @@ -183,8 +185,17 @@ export class RdDItemCompetence extends Item { /* -------------------------------------------- */ static findCompetence(list, name) { - name = name.toLowerCase(); - return list.find(it => it.name.toLowerCase() == name && (it.type == "competence" || it.type == "competencecreature")) + name = Grammar.toLowerCaseNoAccent(name); + const competences = list.filter(it => Grammar.toLowerCaseNoAccent(it.name).includes(name) && (it.type == "competence" || it.type == "competencecreature")); + if (competences.length == 0) { + return undefined; + } + const competence = competences[0]; + if (competences.length>1) { + const names = competences.map(it => it.name).reduce((a, b) => `${a}
${b}`); + ui.notifications.info(`Plusieurs compétences possibles:
${names}
La première sera choisie: ${competence.name}`); + } + return competence; } /* -------------------------------------------- */ diff --git a/module/rdd-commands.js b/module/rdd-commands.js index dddfdb2c..db0985d7 100644 --- a/module/rdd-commands.js +++ b/module/rdd-commands.js @@ -11,9 +11,9 @@ import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js"; import { RdDRollTables } from "./rdd-rolltables.js"; import { RdDUtility } from "./rdd-utility.js"; import { TMRRencontres } from "./tmr-rencontres.js"; -import { TMRType, TMRUtility } from "./tmr-utility.js"; +import { TMRUtility } from "./tmr-utility.js"; -const rddRollNumeric = /(\d+)\s*([\+\-]?\d+)?\s*(s)?/; +const rddRollNumeric = /$(\d+)\s*([\+\-]?\d+)?\s*(s)?/; /* -------------------------------------------- */ export class RdDCommands { @@ -64,9 +64,11 @@ export class RdDCommands { descr: `Effectue un jet de dés dans la table de résolution. Exemples:
/rdd ouvre la table de résolution
/rdd 10 3 effectue un jet 10 à +3 -
/rdd 10 +2 effectue un jet 10 à +2
/rdd 15 -2 effectue un jet 15 à -2 -
/rdd 15 0 s effectue un jet 15 à 0, avec significative requise` +
/rdd 15 0 s effectue un jet 15 à 0, avec significative requise +
/rdd Vue Vigilance -2 effectue un jet de Vue/Vigilance à -2 pour les tokens sélectionnés +
/rdd vol déser +2 effectue un jet de Volonté/Survie en désert à +2 pour les tokens sélectionnés + ` }); rddCommands.registerCommand({ path: ["/ddr"], func: (content, msg, params) => rddCommands.rollDeDraconique(msg), descr: "Lance un Dé Draconique" }); @@ -217,6 +219,27 @@ export class RdDCommands { await this.rollRdDNumeric(msg, carac, diff, significative); return; } + + let actors = canvas.tokens.controlled.map(it => it.actor).filter(it => it); + if (actors && actors.length > 0){ + let length = params.length; + let diff = Number(params[length-1]); + if (Number.isInteger(Number(diff))){ + length --; + } + else { + diff = 0; + } + const caracName = params[0]; + const compName = length>1 ? params.slice(1, length).reduce((a, b) => `${a} ${b}`): undefined; + for (let actor of actors) { + await actor.rollCaracCompetence(caracName, compName, diff); + } + return; + } + else{ + ui.notifications.warn("Sélectionnez au moins un personnage pour lancer les dés") + } } } From 39f6307058cab1e2cddd9a38ae4c229eec0b552d Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 25 Mar 2021 00:16:53 +0100 Subject: [PATCH 2/3] Version 1.3.38 --- system.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/system.json b/system.json index 8b605ad0..77d39f13 100644 --- a/system.json +++ b/system.json @@ -2,7 +2,7 @@ "name": "foundryvtt-reve-de-dragon", "title": "Rêve de Dragon", "description": "Rêve de Dragon RPG for FoundryVTT", - "version": "1.3.37", + "version": "1.3.38", "manifestPlusVersion": "1.0.0", "minimumCoreVersion": "0.7.5", "compatibleCoreVersion": "0.7.9", From e8a59b56a4ab14bcf4f99dca92848917a281ed33 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Thu, 25 Mar 2021 01:57:48 +0100 Subject: [PATCH 3/3] =?UTF-8?q?Fix:=20privil=C3=A9gier=20le=20nom=20exact?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/item-competence.js | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/module/item-competence.js b/module/item-competence.js index a07482b9..dacf1b9f 100644 --- a/module/item-competence.js +++ b/module/item-competence.js @@ -190,10 +190,13 @@ export class RdDItemCompetence extends Item { if (competences.length == 0) { return undefined; } - const competence = competences[0]; - if (competences.length>1) { - const names = competences.map(it => it.name).reduce((a, b) => `${a}
${b}`); - ui.notifications.info(`Plusieurs compétences possibles:
${names}
La première sera choisie: ${competence.name}`); + let competence = competences.find(it => Grammar.toLowerCaseNoAccent(it.name) == name); + if (!competence) { + competence = competences[0]; + if (competences.length>1) { + const names = competences.map(it => it.name).reduce((a, b) => `${a}
${b}`); + ui.notifications.info(`Plusieurs compétences possibles:
${names}
La première sera choisie: ${competence.name}`); + } } return competence; }