Amelioration des commandes de tchat et aide
This commit is contained in:
@ -138,26 +138,10 @@ Hooks.once("ready", function() {
|
||||
/* -------------------------------------------- */
|
||||
/* Foundry VTT Initialization */
|
||||
/* -------------------------------------------- */
|
||||
const table2func = { "queues": TMRUtility.getQueue, "ombre": TMRUtility.getOmbre, "tetehr": TMRUtility.getTeteHR, "tete": TMRUtility.getTete, "souffle": TMRUtility.getSouffle };
|
||||
Hooks.on("chatMessage", (html, content, msg) => {
|
||||
let regExp;
|
||||
regExp = /(\S+)/g;
|
||||
let commands = content.match(regExp);
|
||||
|
||||
// Setup new message's visibility
|
||||
let rollMode = game.settings.get("core", "rollMode");
|
||||
if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperIDs("GM");
|
||||
if (rollMode === "blindroll") msg["blind"] = true;
|
||||
msg["type"] = 0;
|
||||
|
||||
let regExp;
|
||||
regExp = /(\S+)/g;
|
||||
let commands = content.match(regExp);
|
||||
let command = commands[0];
|
||||
|
||||
// Roll on a table
|
||||
if (command === "/table") {
|
||||
let tableName = commands[1].toLowerCase();
|
||||
table2func[tableName]();
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
return RdDUtility.processChatCommand( commands, content, msg );
|
||||
} );
|
||||
|
@ -5,6 +5,7 @@
|
||||
import { RdDUtility } from "./rdd-utility.js";
|
||||
import { TMRUtility } from "./tmr-utility.js";
|
||||
|
||||
/** Helper functions */
|
||||
export class RdDTMRDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
@ -1,6 +1,7 @@
|
||||
/* Common useful functions shared between objects */
|
||||
|
||||
import { RdDActor } from "./actor.js";
|
||||
import { TMRUtility } from "./tmr-utility.js";
|
||||
|
||||
const level_category = {
|
||||
"generale": "-4",
|
||||
@ -76,6 +77,12 @@ const fatigueMarche = { "aise": { "4":1, "6":2, "8":3, "10":4, "12":6 },
|
||||
"malaise": { "4":2, "6":3, "8":4, "10":6 },
|
||||
"difficile": { "4":3, "6":4, "8":6 },
|
||||
"tresdifficile": { "4":4, "6":6 } }
|
||||
/* Static tables for commands /table */
|
||||
const table2func = { "queues": {descr: "queues : Tire une queue de Dragon", func: TMRUtility.getQueue},
|
||||
"ombre": { descr: "ombre: Tire une Ombre de Dragon", func: TMRUtility.getOmbre },
|
||||
"tetehr": {descr: "tetehr: Tire une Tête de Dragon pour Hauts Revants", fund: TMRUtility.getTeteHR},
|
||||
"tete" : { descr: "tete: Tire une Tête de Dragon", func: TMRUtility.getTete},
|
||||
"souffle": { descr: "souffle: Tire un Souffle de Dragon", func: TMRUtility.getSouffle} };
|
||||
|
||||
/* -------------------------------------------- */
|
||||
export class RdDUtility {
|
||||
@ -587,4 +594,43 @@ export class RdDUtility {
|
||||
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Display help for /table */
|
||||
static displayHelpTable( msg )
|
||||
{
|
||||
msg.content = "";
|
||||
for (let [name, tableData] of Object.entries(table2func)) {
|
||||
msg.content += "<br>" + tableData.descr;
|
||||
}
|
||||
ChatMessage.create( msg );
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* Manage chat commands */
|
||||
static processChatCommand( commands, content, msg ) {
|
||||
// Setup new message's visibility
|
||||
let rollMode = game.settings.get("core", "rollMode");
|
||||
if (["gmroll", "blindroll"].includes(rollMode)) msg["whisper"] = ChatMessage.getWhisperIDs("GM");
|
||||
if (rollMode === "blindroll") msg["blind"] = true;
|
||||
msg["type"] = 0;
|
||||
|
||||
let command = commands[0];
|
||||
|
||||
// Roll on a table
|
||||
if (command === "/table") {
|
||||
if ( commands[1] ) {
|
||||
let tableName = commands[1].toLowerCase();
|
||||
table2func[tableName]();
|
||||
} else {
|
||||
this.displayHelpTable( msg );
|
||||
}
|
||||
return false
|
||||
} else if (command === "/tmrr") {
|
||||
TMRUtility.getRencontre(commands[1], commands[2] )
|
||||
return false
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -399,5 +399,35 @@ export class TMRUtility {
|
||||
return TMRUtility.genericGetTableResult( "Ombre de Thanatos", toChat);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/**
|
||||
* Retourne une recontre en fonction de la case ou du tirage
|
||||
* @param {*} caseName
|
||||
* @param {*} roll
|
||||
*/
|
||||
static getRencontre( caseName, roll ) {
|
||||
if (!roll) {
|
||||
roll = new Roll("1d100").roll().total;
|
||||
}
|
||||
if ( !caseName) {
|
||||
ChatMessage.create({ content: "Un nom de case doit être indiqué (ie /tmrr desert ou /tmrr cite)" });
|
||||
return false;
|
||||
}
|
||||
caseName = caseName.toLowerCase();
|
||||
caseName = caseName.normalize("NFD").replace(/[\u0300-\u036f]/g, "");
|
||||
//console.log("Case : ", caseName);
|
||||
for( let renc of rencontresTable) {
|
||||
let scoreDef = renc.data[caseName];
|
||||
let min = scoreDef.substr(0,2);
|
||||
let max = scoreDef.substr(3,2);
|
||||
if ( roll >= min && roll <= max) {
|
||||
let force = new Roll(renc.data.force).roll().total;
|
||||
ChatMessage.create({ content: "Vous rencontrez un " + renc.name + " d'une force de " + force + " Points de Rêve" });
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user