From 8f9b1f1e76bb5048306b0c8d9ba7abd388374802 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 24 Nov 2020 15:20:05 +0100 Subject: [PATCH 1/4] =?UTF-8?q?Gestion=20du=20rollMode=20affecte=20tous=20?= =?UTF-8?q?les=20jets=20d'un=20actor=20sur=20la=20table=20de=20r=C3=A9solu?= =?UTF-8?q?tion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- module/actor.js | 8 ++--- module/chat-utility.js | 70 ++++++++++++++++++++++++++++++++++++++++++ module/rdd-dice.js | 22 ++++++------- module/rdd-utility.js | 48 ++++++++++++++++++----------- 4 files changed, 115 insertions(+), 33 deletions(-) create mode 100644 module/chat-utility.js diff --git a/module/actor.js b/module/actor.js index e171b65a..6ee43b3b 100644 --- a/module/actor.js +++ b/module/actor.js @@ -12,6 +12,7 @@ import { Misc } from "./misc.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDDice } from "./rdd-dice.js"; import { RdDRollTables } from "./rdd-rolltables.js"; +import { ChatUtility } from "./chat-utility.js"; export class RdDActor extends Actor { @@ -232,11 +233,10 @@ export class RdDActor extends Actor { + "
Difficultés libre : " + rollData.diffLibre + " / conditions : " + Misc.toSignedString(rollData.diffConditions) +" / état : " + rollData.etat + RdDResolutionTable.explain(rolled) + "
" + quality + "" - + explications + xpmsg, - user: game.user._id, - title: "Résultat du test" + + explications + xpmsg } - ChatMessage.create(chatOptions); + + ChatUtility.chatWithRollMode(chatOptions, this.name) // This an attack, generate the defense message if (defenseMsg) { diff --git a/module/chat-utility.js b/module/chat-utility.js new file mode 100644 index 00000000..6f63f483 --- /dev/null +++ b/module/chat-utility.js @@ -0,0 +1,70 @@ + +/** + * Class providing helper methods to get the list of users, and + */ +export class ChatUtility { + + static chatWithRollMode(chatOptions, name) { + let rollMode = game.settings.get("core", "rollMode"); + chatOptions.user = game.user._id; + + switch (rollMode) { + case "blindroll": {//GM only + if (!game.user.isGM) { + ChatUtility.blindMessageToGM(chatOptions); + + chatOptions = { + user: game.user._id, + whisper: [game.user._id], + content: "Message envoyé en aveugle au Gardien" + } + } + else { + chatOptions.whisper = ChatUtility.getUsers(user => user.isGM); + } + } + break; + case "gmroll": //GM + rolling player + chatOptions.user = game.user._id; + chatOptions.whisper = ChatUtility.getWhisperRecipientsAndGMs(name); + break; + case "selfroll": // only the user + chatOptions.user = game.user._id; + chatOptions.whisper = [game.user._id]; + break; + default: + case "roll": //everybody + chatOptions.whisper = undefined; + break; + } + + console.log("roll message", chatOptions); + ChatMessage.create(chatOptions); + } + + static getWhisperRecipientsAndGMs(name) { + return ChatMessage.getWhisperRecipients(name) + .concat(this.getUsers(user => user.isGM)); + } + + static getUsers(filter) { + return game.users.filter(filter).map(user => user.data._id); + } + + static blindMessageToGM(chatOptions) { + let chatGM = duplicate(chatOptions); + chatGM.whisper = ChatUtility.getUsers(user => user.isGM); + chatGM.content = "Message aveugle de " + game.user.name + "
" + chatOptions.content; + console.log("blindMessageToGM", chatGM); + game.socket.emit("system.foundryvtt-reve-de-dragon", { msg: "msg_gm_chat_message", data: chatGM }); + } + + static handleGMChatMessage(data) { + console.log("blindMessageToGM", data); + if (game.user.isGM) { // message privé pour GM only + data.user = game.user._id; + ChatMessage.create(data); + } + } + +} diff --git a/module/rdd-dice.js b/module/rdd-dice.js index 3d208c13..bdd3be73 100644 --- a/module/rdd-dice.js +++ b/module/rdd-dice.js @@ -1,3 +1,5 @@ +import { ChatUtility } from "./chat-utility.js"; + export class RdDDice { /* -------------------------------------------- */ @@ -9,32 +11,30 @@ export class RdDDice { /* -------------------------------------------- */ - static async show(roll, rollMode = "roll") { + static async show(roll, rollMode = undefined) { if (roll.showDice || game.settings.get("foundryvtt-reve-de-dragon", "dice-so-nice") == true) { await this.showDiceSoNice(roll, rollMode); } return roll; } - + /* -------------------------------------------- */ - static async showDiceSoNice(roll, rollMode = "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 == undefined ? game.settings.get("core", "rollMode") : rollMode; switch (rollMode) { case "blindroll": //GM only blind = true; case "gmroll": //GM + rolling player - let gmList = game.users.filter(user => user.isGM); - let gmIDList = []; - gmList.forEach(gm => gmIDList.push(gm.data._id)); - whisper = gmIDList; + whisper = ChatUtility.getUsersIds(user => user.isGM); break; case "roll": //everybody - let userList = game.users.filter(user => user.active); - let userIDList = []; - userList.forEach(user => userIDList.push(user.data._id)); - whisper = userIDList; + whisper = ChatUtility.getUsersIds(user => user.active); + break; + case "selfroll": + whisper = [game.user._id]; break; } await game.dice3d.showForRoll(roll, game.user, true, whisper, blind); diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 9d752b95..652a98f4 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -2,6 +2,7 @@ import { TMRUtility } from "./tmr-utility.js"; import { RdDRollTables } from "./rdd-rolltables.js"; +import { ChatUtility } from "./chat-utility.js"; const level_category = { "generale": "-4", @@ -601,27 +602,38 @@ export class RdDUtility { static performSocketMesssage( sockmsg ) { console.log(">>>>> MSG RECV", sockmsg); - if ( sockmsg.msg == "msg_encaisser" ) { - if ( game.user.isGM ) { // Seul le GM effectue l'encaissement sur la fiche - let rollData = game.system.rdd.rollDataHandler[sockmsg.data.attackerid]; // Retrieve the rolldata from the store - let defenderActor = game.actors.get( sockmsg.data.defenderid ); - defenderActor.encaisserDommages( rollData ); - } - } else if (sockmsg.msg == "msg_defense" ) { - let defenderActor = game.actors.get( sockmsg.data.defenderid ); - if ( defenderActor ) { - if ( (game.user.isGM && !defenderActor.hasPlayerOwner) || (defenderActor.hasPlayerOwner && (game.user.character.id == defenderActor.id) ) ) { - console.log("User is pushing message...", game.user.name); - game.system.rdd.rollDataHandler[sockmsg.data.attackerid] = duplicate(sockmsg.data.rollData); - sockmsg.data.whisper = [ game.user ]; - sockmsg.data.blind = true; - sockmsg.data.rollMode = "blindroll"; - ChatMessage.create( sockmsg.data ); - } + switch(sockmsg.msg) { + case "msg_encaisser": + return RdDUtility._handleMsgEncaisser(sockmsg.data); + case "msg_defense" : + return RdDUtility._handleMsgDefense(sockmsg.data); + case "msg_gm_chat_message": + return ChatUtility.handleGMChatMessage(sockmsg.data); + } + } + + static _handleMsgDefense(data) { + let defenderActor = game.actors.get(data.defenderid); + if (defenderActor) { + if ((game.user.isGM && !defenderActor.hasPlayerOwner) || (defenderActor.hasPlayerOwner && (game.user.character.id == defenderActor.id))) { + console.log("User is pushing message...", game.user.name); + game.system.rdd.rollDataHandler[data.attackerid] = duplicate(data.rollData); + data.whisper = [game.user]; + data.blind = true; + data.rollMode = "blindroll"; + ChatMessage.create(data); } } } - + + static _handleMsgEncaisser(data) { + if (game.user.isGM) { // Seul le GM effectue l'encaissement sur la fiche + let rollData = game.system.rdd.rollDataHandler[data.attackerid]; // Retrieve the rolldata from the store + let defenderActor = game.actors.get(data.defenderid); + defenderActor.encaisserDommages(rollData); + } + } + /* -------------------------------------------- */ static async chatListeners( html ) { From 968a95fb997c08e315a05dc5fb89b5d4662f68e0 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 24 Nov 2020 15:43:03 +0100 Subject: [PATCH 2/4] Netttoyage ChatMessage * pas de title * n'enlever que ses propres messages de bienvenue --- module/actor.js | 15 +++++++++------ module/rdd-main.js | 18 ++++++------------ module/rdd-tmr-dialog.js | 4 ++-- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/module/actor.js b/module/actor.js index 6ee43b3b..b1930f06 100644 --- a/module/actor.js +++ b/module/actor.js @@ -322,7 +322,7 @@ export class RdDActor extends Actor { await this.update({ "data.reve.reve": myReve }); if (myReve.value == 0) { // 0 points de reve - ChatMessage.create({ title: "Zero Points de Reve !", content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); + ChatMessage.create({ content: this.name + " est réduit à 0 Points de Rêve, et tombe endormi !" }); closeTMR = true; } if (closeTMR) { @@ -333,7 +333,10 @@ export class RdDActor extends Actor { /* -------------------------------------------- */ async dormir(heures=1) { - let message = { title : "Récupération", content :"Vous dormez " + heures + " heure" + (heures > 1 ? "s": "") }; + let message = { + whisper: ChatUtility.getWhisperRecipientsAndGMs( this.name ), + content : "Vous dormez " + heures + " heure" + (heures > 1 ? "s": "") + }; await this.recupereEndurance(message); for (let i=0; i { }); function messageDeBienvenue(){ - game.messages.filter(it => { - console.log(it); - return it.data.content.match(/^Bienvenu(e)? dans le Rêve des Dragons/); - }) - .forEach(it => { - console.log("deleting",it); - it.delete(); - }); + game.messages + .filter(it => it.user._id == game.user._id && it.data.content.match(/^Bienvenu(e)? dans le Rêve des Dragons/)) + .forEach(it => it.delete()); ChatMessage.create( { - whisper: [game.user], - title: "Bienvenue dans le Rêve !", + user: game.user._id, + whisper: [game.user._id], content : "Bienvenue dans le Rêve des Dragons !
" + "Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs}" } ); @@ -216,4 +210,4 @@ Hooks.on("chatMessage", (html, content, msg) => { let commands = content.match(regExp); return RdDUtility.processChatCommand( commands, content, msg ); -} ); +}); diff --git a/module/rdd-tmr-dialog.js b/module/rdd-tmr-dialog.js index 9882191b..8d7e530b 100644 --- a/module/rdd-tmr-dialog.js +++ b/module/rdd-tmr-dialog.js @@ -224,12 +224,12 @@ export class RdDTMRDialog extends Dialog { /* -------------------------------------------- */ _tellToUser(message) { - ChatMessage.create({ title: "TMR", content: message, user: game.user._id }); + ChatMessage.create({ content: message, user: game.user._id }); } /* -------------------------------------------- */ _tellToGM(message) { - ChatMessage.create({ title: "TMR", content: message, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") }); + ChatMessage.create({ content: message, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") }); } /* -------------------------------------------- */ From 7890ecfdf9714e70f14c61144d9dde7df99be1cf Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 24 Nov 2020 15:44:50 +0100 Subject: [PATCH 3/4] =?UTF-8?q?fix=20message=20en=20cas=20de=20particuli?= =?UTF-8?q?=C3=A8re?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit content au lieu de contet --- module/actor.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module/actor.js b/module/actor.js index b1930f06..70dfc9f1 100644 --- a/module/actor.js +++ b/module/actor.js @@ -198,7 +198,7 @@ export class RdDActor extends Actor { if (rolled.isSuccess) { // Message spécial pour la rapidité, qui reste difficile à gérer automatiquement if ( rollData.particuliereAttaque == 'rapidite') { - ChatMessage.create( { contet: "Vous avez attaqué en Rapidité. Ce cas n'est pas géré autmatiquement, donc suivez les directives de votre MJ pour gérer ce cas.", + ChatMessage.create( { content: "Vous avez attaqué en Rapidité. Ce cas n'est pas géré autmatiquement, donc suivez les directives de votre MJ pour gérer ce cas.", whisper: ChatMessage.getWhisperRecipients( this.name ) } ); } rollData.domArmePlusDom = this._calculBonusDommages(rollData.selectedCarac, rollData.arme, rollData.particuliereAttaque == 'force' ); From dcc7e7e25657b31d15c837da13cd1c39bcee4f51 Mon Sep 17 00:00:00 2001 From: Vincent Vandemeulebrouck Date: Tue, 24 Nov 2020 15:45:41 +0100 Subject: [PATCH 4/4] =?UTF-8?q?attendre=20le=20d=C3=A9=20draconique?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sinon on a une promesse non tenue dans le message de repos --- module/actor.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/module/actor.js b/module/actor.js index 70dfc9f1..53ac2d52 100644 --- a/module/actor.js +++ b/module/actor.js @@ -392,6 +392,7 @@ export class RdDActor extends Actor { }; return cumul; } + /* -------------------------------------------- */ async recuperationReve(message) { const seuil = this.data.data.reve.seuil.value; @@ -400,7 +401,7 @@ export class RdDActor extends Actor { message.content += "
Vous avez suffisament rêvé (seuil " + seuil + ", rêve actuel "+reve+")"; } else { - let deRecuperation = RdDDice.deDraconique(); + let deRecuperation = await RdDDice.deDraconique(); console.log("recuperationReve", deRecuperation); if (deRecuperation>=7) {