2020-12-29 00:11:58 +01:00
/* -------------------------------------------- */
2022-11-04 20:41:16 +01:00
import { DialogChronologie } from "./dialog-chronologie.js" ;
2021-05-11 21:21:33 +02:00
import { DialogCreateSigneDraconique } from "./dialog-create-signedraconique.js" ;
2021-10-08 23:28:55 +02:00
import { DialogStress } from "./dialog-stress.js" ;
2021-01-21 00:05:22 +01:00
import { RdDItemCompetence } from "./item-competence.js" ;
2020-12-29 00:11:58 +01:00
import { Misc } from "./misc.js" ;
2021-03-17 01:21:37 +01:00
import { RdDCarac } from "./rdd-carac.js" ;
2020-12-31 11:53:41 +01:00
import { RdDDice } from "./rdd-dice.js" ;
2022-06-25 22:18:46 +02:00
import { RdDMeteo } from "./rdd-meteo.js" ;
2021-02-10 15:25:14 +01:00
import { RdDNameGen } from "./rdd-namegen.js" ;
2020-12-29 00:11:58 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js" ;
2021-01-02 14:10:43 +01:00
import { RdDRollResolutionTable } from "./rdd-roll-resolution-table.js" ;
2020-12-29 00:11:58 +01:00
import { RdDRollTables } from "./rdd-rolltables.js" ;
import { RdDUtility } from "./rdd-utility.js" ;
2022-11-28 11:31:19 +01:00
import { CompendiumTableHelpers } from "./settings/system-compendiums.js" ;
2023-01-13 04:54:29 +01:00
import { FenetreRechercheTirage } from "./tirage/fenetre-recherche-tirage.js" ;
2021-03-25 00:14:56 +01:00
import { TMRUtility } from "./tmr-utility.js" ;
2020-12-29 00:11:58 +01:00
2021-05-29 20:20:30 +02:00
const rddRollNumeric = /^(\d+)\s*([\+\-]?\d+)?\s*(s)?/ ;
2020-12-29 00:11:58 +01:00
/* -------------------------------------------- */
export class RdDCommands {
static init ( ) {
2022-11-30 13:27:05 +01:00
const rddCommands = new RdDCommands ( ) ;
2023-01-13 04:54:29 +01:00
game . system . rdd . commands = rddCommands ;
2022-11-30 13:27:05 +01:00
Hooks . on ( "chatMessage" , ( html , content , msg ) => {
if ( content [ 0 ] == '/' ) {
let regExp = /(\S+)/g ;
let commands = content . match ( regExp ) ;
if ( rddCommands . processChatCommand ( commands , content , msg ) ) {
return false ;
}
}
return true ;
} ) ;
2022-11-28 16:00:49 +01:00
}
constructor ( ) {
this . commandsTable = undefined ;
}
_registerCommands ( ) {
this . commandsTable = { }
this . registerCommand ( { path : [ "/aide" ] , func : ( content , msg , params ) => this . help ( msg ) , descr : "Affiche l'aide pour toutes les commandes" } ) ;
this . registerCommand ( { path : [ "/help" ] , func : ( content , msg , params ) => this . help ( msg ) , descr : "Affiche l'aide pour toutes les commandes" } ) ;
this . registerCommand ( { path : [ "/liste" , "comp" ] , func : ( content , msg , params ) => RdDRollTables . getCompetence ( 'liste' ) , descr : "Affiche la liste des compétences" } ) ;
this . registerCommand ( { path : [ "/table" , "queue" ] , func : ( content , msg , params ) => RdDRollTables . getQueue ( 'liste' ) , descr : "Affiche la table des Queues de Dragon" } ) ;
this . registerCommand ( { path : [ "/table" , "ombre" ] , func : ( content , msg , params ) => RdDRollTables . getOmbre ( 'liste' ) , descr : "Affiche la table des Ombres de Thanatos" } ) ;
this . registerCommand ( { path : [ "/table" , "tetehr" ] , func : ( content , msg , params ) => RdDRollTables . getTeteHR ( 'liste' ) , descr : "Affiche la table des Têtes de Dragon pour Hauts Revants" } ) ;
this . registerCommand ( { path : [ "/table" , "tete" ] , func : ( content , msg , params ) => RdDRollTables . getTete ( 'liste' ) , descr : "Affiche la table des Tête de Dragon pour tous" } ) ;
this . registerCommand ( { path : [ "/table" , "souffle" ] , func : ( content , msg , params ) => RdDRollTables . getSouffle ( 'liste' ) , descr : "Affiche la table des Souffles de Dragon" } ) ;
this . registerCommand ( { path : [ "/table" , "tarot" ] , func : ( content , msg , params ) => RdDRollTables . getTarot ( 'liste' ) , descr : "Affiche la table les cartes du Tarot Draconique" } ) ;
this . registerCommand ( { path : [ "/table" , "ideefixe" ] , func : ( content , msg , params ) => RdDRollTables . getIdeeFixe ( 'liste' ) , descr : "Affiche la table des Idées fixes" } ) ;
this . registerCommand ( { path : [ "/table" , "desir" ] , func : ( content , msg , params ) => RdDRollTables . getDesirLancinant ( 'liste' ) , descr : "Affiche la table des Désirs Lancinants" } ) ;
this . registerCommand ( {
path : [ "/table" , "rencontre" ] , func : ( content , msg , params ) => this . tableRencontres ( msg , params ) ,
descr : ` Affiche la table des Rencontres
2022-11-26 03:13:45 +01:00
< br > < strong > / t a b l e r e n c o n t r e d e s o < / s t r o n g > a f f i c h e l a t a b l e d e s r e n c o n t r e s e n D é s o l a t i o n
2022-11-28 16:00:49 +01:00
< br > < strong > / t a b l e r e n c o n t r e m a u v a i s e < / s t r o n g > a f f i c h e l a t a b l e d e s m a u v a i s e s r e n c o n t r e s `
} ) ;
2022-11-30 13:27:05 +01:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( { path : [ "/tirer" , "comp" ] , func : ( content , msg , params ) => RdDRollTables . getCompetence ( 'chat' ) , descr : "Tire une compétence au hasard" } ) ;
this . registerCommand ( { path : [ "/tirer" , "queue" ] , func : ( content , msg , params ) => RdDRollTables . getQueue ( 'chat' ) , descr : "Tire une Queue de Dragon" } ) ;
this . registerCommand ( { path : [ "/tirer" , "ombre" ] , func : ( content , msg , params ) => RdDRollTables . getOmbre ( 'chat' ) , descr : "Tire une Ombre de Thanatos" } ) ;
this . registerCommand ( { path : [ "/tirer" , "tetehr" ] , func : ( content , msg , params ) => RdDRollTables . getTeteHR ( 'chat' ) , descr : "Tire une Tête de Dragon pour Hauts Revants" } ) ;
this . registerCommand ( { path : [ "/tirer" , "tete" ] , func : ( content , msg , params ) => RdDRollTables . getTete ( 'chat' ) , descr : "Tire une Tête de Dragon" } ) ;
this . registerCommand ( { path : [ "/tirer" , "souffle" ] , func : ( content , msg , params ) => RdDRollTables . getSouffle ( 'chat' ) , descr : "Tire un Souffle de Dragon" } ) ;
this . registerCommand ( { path : [ "/tirer" , "tarot" ] , func : ( content , msg , params ) => RdDRollTables . getTarot ( 'chat' ) , descr : "Tire une carte du Tarot Draconique" } ) ;
this . registerCommand ( { path : [ "/tirer" , "ideefixe" ] , func : ( content , msg , params ) => RdDRollTables . getIdeeFixe ( 'chat' ) , descr : "Tire une Idée fixe" } ) ;
this . registerCommand ( { path : [ "/tirer" , "desir" ] , func : ( content , msg , params ) => RdDRollTables . getDesirLancinant ( 'chat' ) , descr : "Tire un Désir Lancinant" } ) ;
this . registerCommand ( { path : [ "/tirer" , "rencontre" ] , func : ( content , msg , params ) => this . getRencontreTMR ( params ) , descr : ` Détermine une rencontre dans les TMR (synonyme de "/tmrr") ` } ) ;
2023-01-13 04:54:29 +01:00
this . registerCommand ( { path : [ "/tirage" ] , func : ( content , msg , params ) => this . tirage ( ) , descr : "Ouvre la fenêtre de recherche et tirage" } ) ;
2022-11-30 13:27:05 +01:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( { path : [ "/meteo" ] , func : ( content , msg , params ) => this . getMeteo ( msg , params ) , descr : "Propose une météo marine" } ) ;
this . registerCommand ( { path : [ "/nom" ] , func : ( content , msg , params ) => RdDNameGen . getName ( msg , params ) , descr : "Génère un nom aléatoire" } ) ;
this . registerCommand ( {
path : [ "/tmr" ] , func : ( content , msg , params ) => this . findTMR ( msg , params ) ,
descr : ` Cherche où se trouve une case des Terres médianes
2022-11-17 01:57:36 +01:00
< br > < strong > / t m r s o r d < / s t r o n g > i n d i q u e q u e l a c i t é S o r d i d e e s t e n D 1 3
2022-11-28 16:00:49 +01:00
< br > < strong > / t m r f o r e t < / s t r o n g > d o n n e l a l i s t e d e s T M R d o n t l e n o m c o n t i e n t " f o r e t " ( d o n c , t o u t e s l e s f o r ê t s ) `
} ) ;
this . registerCommand ( {
path : [ "/tmra" ] , func : ( content , msg , params ) => this . getTMRAleatoire ( msg , params ) ,
descr : ` Tire une case aléatoire des Terres médianes
2021-02-05 01:38:40 +01:00
< br > < strong > / t m r a f o r ê t < / s t r o n g > d é t e r m i n e u n e ' f o r ê t ' a l é a t o i r e
2022-11-28 16:00:49 +01:00
< br > < strong > / t m r a < / s t r o n g > d é t e r m i n e u n e c a s e a l é a t o i r e d a n s t o u t e s l e s T M R `
} ) ;
this . registerCommand ( {
path : [ "/tmrr" ] , func : ( content , msg , params ) => this . getRencontreTMR ( params ) ,
descr : ` Détermine une rencontre dans les TMR
2022-11-17 01:57:36 +01:00
< br > < strong > / t m r r f o r ê t < / s t r o n g > d é t e r m i n e u n e r e n c o n t r e a l é a t o i r e e n ' f o r ê t '
< br > < strong > / t m r r m a u v a i s e < / s t r o n g > d é t e r m i n e u n e m a u v a i s e r e n c o n t r e a l é a t o i r e
2022-11-28 16:00:49 +01:00
< br > < strong > / t m r r f o r 4 7 < / s t r o n g > d é t e r m i n e l a r e n c o n t r e e n ' f o r ê t ' p o u r u n j e t d e d é d e 4 7 `
} ) ;
2021-01-21 00:05:22 +01:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/xp" , "comp" ] , func : ( content , msg , params ) => this . getCoutXpComp ( msg , params ) ,
descr : ` Détermine le coût d'expérience pour augmenter une compétence. Exemples:
2021-01-21 00:05:22 +01:00
< br > / x p c o m p - 6 1 : p o u r p a s s e r d e - 6 à + 1
< br > / x p c o m p + 4 : p o u r a t t e i n d r e l e n i v e a u 4 ( d e p u i s + 3 ) `
2022-11-28 16:00:49 +01:00
} ) ;
2021-01-21 00:05:22 +01:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/xp" , "carac" ] , func : ( content , msg , params ) => this . getCoutXpCarac ( msg , params ) ,
descr : ` Détermine le coût d'expérience pour augmenter une caractéristique. Exemples:
2021-01-21 00:05:22 +01:00
< br > / x p c a r a c 1 5 : c o û t p o u r a t t e i n d r e 1 5 ( d e p u i s 1 4 ) `
2022-11-28 16:00:49 +01:00
} ) ;
2020-12-31 11:53:41 +01:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/rdd" ] , func : ( content , msg , params ) => this . rollRdd ( msg , params ) ,
descr : ` Effectue un jet de dés dans la table de résolution. Exemples:
2021-02-05 01:38:40 +01:00
< br > < strong > / r d d < / s t r o n g > o u v r e l a t a b l e d e r é s o l u t i o n
< br > < strong > / r d d 1 0 3 < / s t r o n g > e f f e c t u e u n j e t 1 0 à + 3
< br > < strong > / r d d 1 5 - 2 < / s t r o n g > e f f e c t u e u n j e t 1 5 à - 2
2021-03-25 00:14:56 +01:00
< br > < strong > / r d d 1 5 0 s < / s t r o n g > e f f e c t u e u n j e t 1 5 à 0 , a v e c s i g n i f i c a t i v e r e q u i s e
< br > < strong > / r d d V u e V i g i l a n c e - 2 < / s t r o n g > e f f e c t u e u n j e t d e V u e / V i g i l a n c e à - 2 p o u r l e s t o k e n s s é l e c t i o n n é s
< br > < strong > / r d d v o l d é s e r + 2 < / s t r o n g > e f f e c t u e u n j e t d e V o l o n t é / S u r v i e e n d é s e r t à + 2 p o u r l e s t o k e n s s é l e c t i o n n é s
`
2022-11-28 16:00:49 +01:00
} ) ;
this . registerCommand ( { path : [ "/ddr" ] , func : ( content , msg , params ) => this . rollDeDraconique ( msg ) , descr : "Lance un Dé Draconique" } ) ;
2020-12-29 00:11:58 +01:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/payer" ] , func : ( content , msg , params ) => RdDUtility . afficherDemandePayer ( params [ 0 ] , params [ 1 ] ) ,
descr : ` Demande aux joueurs de payer un montant. Exemples:
2021-02-05 01:38:40 +01:00
< br > < strong > / p a y e r 5 s 1 0 d < / s t r o n g > p e r m e t d ' e n v o y e r u n m e s s a g e p o u r p a y e r 5 s o l s e t 1 0 d e n i e r s
< br > < strong > / p a y e r 1 0 d < / s t r o n g > p e r m e t d ' e n v o y e r u n m e s s a g e p o u r p a y e r 1 0 d e n i e r s `
2022-11-28 16:00:49 +01:00
} ) ;
this . registerCommand ( {
path : [ "/astro" ] , func : ( content , msg , params ) => RdDUtility . afficherHeuresChanceMalchance ( Misc . join ( params , ' ' ) ) ,
descr : ` Affiche les heures de chance et de malchance selon l'heure de naissance donnée en argument. Exemples pour l'heure de la Lyre:
2021-06-04 18:30:06 +02:00
< br > < strong > / a s t r o 7 < / s t r o n g >
< br > < strong > / a s t r o L y r e < / s t r o n g >
< br > < strong > / a s t r o L y r < / s t r o n g > `
2022-11-28 16:00:49 +01:00
} ) ;
2021-05-11 00:52:25 +02:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/signe" , "+" ] , func : ( content , msg , params ) => this . creerSignesDraconiques ( ) ,
descr : "Crée un signe draconique et l'ajoute aux haut-rêvants choisis."
} ) ;
2021-05-11 00:52:25 +02:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/signe" , "-" ] , func : ( content , msg , params ) => this . supprimerSignesDraconiquesEphemeres ( ) ,
descr : "Supprime les signes draconiques éphémères"
} ) ;
2021-05-11 00:52:25 +02:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/stress" ] , func : ( content , msg , params ) => this . distribuerStress ( params ) ,
descr : ` Distribue du stress aux personnages. Exemples:
2021-10-08 23:28:55 +02:00
< br > < strong > / s t r e s s < / s t r o n g > : O u v r e u n e f e n ê t r e p o u r d o n n e r d u s t r e s s o u d e l ' e x p é r i e n c e à u n e n s e m b l e d e p e r s o n n a g e s
2021-05-19 22:44:14 +02:00
< br > < strong > / s t r e s s 6 < / s t r o n g > : D i s t r i b u e 6 p o i n t s d e s S t r e s s à t o u t l e s p e r s o n n a g e s j o u e u r s , s a n s r a i s o n r e n s e i g n é e
2021-10-08 23:28:55 +02:00
< br > < strong > / s t r e s s 6 T i g r e < / s t r o n g > : D i s t r i b u e 6 p o i n t s d e s S t r e s s à t o u t l e s p e r s o n n a g e s j o u e u r s , à c a u s e d ' u n T i g r e ( V e r t )
< br > < strong > / s t r e s s 6 G l o u P a u l o < / s t r o n g > : D i s t r i b u e 6 p o i n t s d e S t r e s s a u p e r s o n n a g e P a u l o n o u a u p e r s o n n a g e j o u e u r P a u l o , à c a u s e d ' u n G l o u `
2022-11-28 16:00:49 +01:00
} ) ;
2021-05-19 22:44:14 +02:00
2022-11-28 16:00:49 +01:00
this . registerCommand ( {
path : [ "/chrono" ] , func : ( content , msg , params ) => DialogChronologie . create ( ) ,
descr : ` Enregistre une entrée de chronologie dans un article de journal `
} ) ;
2020-12-29 00:11:58 +01:00
}
2021-02-17 11:16:27 +01:00
/* -------------------------------------------- */
2020-12-29 00:11:58 +01:00
registerCommand ( command ) {
2022-11-30 13:27:05 +01:00
this . _addCommand ( this . commandsTable , command . path , '' , command ) ;
2020-12-29 00:11:58 +01:00
}
2021-02-17 11:16:27 +01:00
/* -------------------------------------------- */
2020-12-31 11:53:41 +01:00
_addCommand ( targetTable , path , fullPath , command ) {
2020-12-29 00:11:58 +01:00
if ( ! this . _validateCommand ( targetTable , path , command ) ) {
return ;
}
const term = path [ 0 ] ;
2021-01-09 19:33:19 +01:00
fullPath = fullPath + term + ' '
2020-12-29 00:11:58 +01:00
if ( path . length == 1 ) {
2020-12-31 11:53:41 +01:00
command . descr = ` <strong> ${ fullPath } </strong>: ${ command . descr } ` ;
2020-12-29 00:11:58 +01:00
targetTable [ term ] = command ;
}
else {
if ( ! targetTable [ term ] ) {
targetTable [ term ] = { subTable : { } } ;
}
2020-12-31 11:53:41 +01:00
this . _addCommand ( targetTable [ term ] . subTable , path . slice ( 1 ) , fullPath , command )
2020-12-29 00:11:58 +01:00
}
}
2021-02-17 11:16:27 +01:00
/* -------------------------------------------- */
2020-12-29 00:11:58 +01:00
_validateCommand ( targetTable , path , command ) {
if ( path . length > 0 && path [ 0 ] && command . descr && ( path . length != 1 || targetTable [ path [ 0 ] ] == undefined ) ) {
return true ;
}
console . warn ( "RdDCommands._validateCommand failed " , targetTable , path , command ) ;
return false ;
}
/* -------------------------------------------- */
/* Manage chat commands */
2021-12-12 17:36:22 +01:00
processChatCommand ( commandLine , content = '' , msg = { } ) {
2020-12-29 00:11:58 +01:00
// Setup new message's visibility
let rollMode = game . settings . get ( "core" , "rollMode" ) ;
2022-11-30 13:27:05 +01:00
if ( [ "gmroll" , "blindroll" ] . includes ( rollMode ) ) {
msg [ "whisper" ] = ChatMessage . getWhisperRecipients ( "GM" ) ;
2023-01-05 02:14:23 +01:00
}
if ( rollMode === "blindroll" ) {
2022-11-30 13:27:05 +01:00
msg [ "blind" ] = true ;
2023-01-05 02:14:23 +01:00
}
2020-12-29 00:11:58 +01:00
msg [ "type" ] = 0 ;
2022-11-30 13:27:05 +01:00
if ( ! this . commandsTable ) {
this . _registerCommands ( ) ;
}
2023-01-05 02:14:23 +01:00
2021-11-27 00:04:34 +01:00
let command = commandLine [ 0 ] . toLowerCase ( ) ;
2022-11-30 13:27:05 +01:00
if ( this . _isCommandHandled ( command ) ) {
let params = commandLine . slice ( 1 ) ;
this . _processCommand ( this . commandsTable , command , params , content , msg ) ;
return true ;
}
return false ;
2020-12-29 00:11:58 +01:00
}
2023-01-05 02:14:23 +01:00
_isCommandHandled ( command ) {
2022-11-30 13:27:05 +01:00
return this . commandsTable [ command ] != undefined ;
2020-12-29 00:11:58 +01:00
}
2022-11-17 01:57:36 +01:00
async _processCommand ( commandsTable , name , params , content = '' , msg = { } , path = "" ) {
2020-12-29 00:11:58 +01:00
let command = commandsTable [ name ] ;
path = path + name + " " ;
if ( command && command . subTable ) {
if ( params [ 0 ] ) {
2022-11-30 13:27:05 +01:00
this . _processCommand ( command . subTable , params [ 0 ] , params . slice ( 1 ) , content , msg , path )
2020-12-29 00:11:58 +01:00
}
else {
this . help ( msg , command . subTable ) ;
}
2022-11-30 13:27:05 +01:00
return true ;
2020-12-29 00:11:58 +01:00
}
if ( command && command . func ) {
2022-11-30 13:27:05 +01:00
new Promise ( async ( ) => {
const result = await command . func ( content , msg , params ) ;
if ( result == false ) {
RdDCommands . _chatAnswer ( msg , command . descr ) ;
}
} ) ;
2020-12-29 00:11:58 +01:00
return true ;
}
return false ;
}
/* -------------------------------------------- */
2023-01-13 04:54:29 +01:00
async help ( msg , table = undefined ) {
2022-11-26 03:13:45 +01:00
let commands = [ ]
2022-11-30 13:27:05 +01:00
this . _buildSubTableHelp ( commands , table ? ? this . commandsTable ) ;
2021-05-01 12:54:45 +02:00
2022-11-26 03:13:45 +01:00
let html = await renderTemplate ( "systems/foundryvtt-reve-de-dragon/templates/settings/dialog-aide-commands.html" , { commands : commands } ) ;
2021-05-01 12:54:45 +02:00
let d = new Dialog (
{
title : "Commandes disponibles dans le tchat" ,
content : html ,
buttons : { } ,
} ,
{
2022-11-16 02:46:26 +01:00
width : 600 , height : 600 ,
2021-05-01 12:54:45 +02:00
} ) ;
d . render ( true ) ;
2021-01-21 00:05:22 +01:00
}
/* -------------------------------------------- */
static _chatAnswer ( msg , content ) {
2021-03-25 03:18:27 +01:00
msg . whisper = [ game . user . id ] ;
2021-01-21 00:05:22 +01:00
msg . content = content ;
2020-12-29 00:11:58 +01:00
ChatMessage . create ( msg ) ;
}
/* -------------------------------------------- */
2020-12-31 11:53:41 +01:00
_buildSubTableHelp ( list , table ) {
2020-12-29 00:11:58 +01:00
for ( let [ name , command ] of Object . entries ( table ) ) {
if ( command ) {
if ( command . subTable ) {
2020-12-31 11:53:41 +01:00
this . _buildSubTableHelp ( list , command . subTable ) ;
2020-12-29 00:11:58 +01:00
} else {
2020-12-31 11:53:41 +01:00
list . push ( command . descr ) ;
2020-12-29 00:11:58 +01:00
}
}
}
2020-12-31 11:53:41 +01:00
return list . sort ( ) ;
2020-12-29 00:11:58 +01:00
}
2021-01-21 00:05:22 +01:00
/* -------------------------------------------- */
2021-01-23 00:29:03 +01:00
async getRencontreTMR ( params ) {
2021-02-05 01:38:40 +01:00
if ( params . length == 1 || params . length == 2 ) {
2022-11-28 16:00:49 +01:00
return game . system . rdd . rencontresTMR . rollRencontre ( params [ 0 ] , params [ 1 ] )
2020-12-29 00:11:58 +01:00
}
2022-11-17 01:57:36 +01:00
return false ;
2020-12-29 00:11:58 +01:00
}
2021-01-21 00:05:22 +01:00
/* -------------------------------------------- */
2020-12-29 00:11:58 +01:00
async rollRdd ( msg , params ) {
if ( params . length == 0 ) {
2021-01-02 14:10:43 +01:00
RdDRollResolutionTable . open ( ) ;
2020-12-29 00:11:58 +01:00
}
else {
2021-11-26 23:29:06 +01:00
let flatParams = Misc . join ( params , ' ' ) ;
2020-12-29 00:11:58 +01:00
const numericParams = flatParams . match ( rddRollNumeric ) ;
if ( numericParams ) {
const carac = Misc . toInt ( numericParams [ 1 ] ) ;
const diff = Misc . toInt ( numericParams [ 2 ] || 0 ) ;
const significative = numericParams [ 3 ] == 's'
await this . rollRdDNumeric ( msg , carac , diff , significative ) ;
return ;
}
2021-03-25 00:14:56 +01:00
let actors = canvas . tokens . controlled . map ( it => it . actor ) . filter ( it => it ) ;
2021-05-01 12:54:45 +02:00
if ( actors && actors . length > 0 ) {
2021-03-25 00:14:56 +01:00
let length = params . length ;
2021-05-01 12:54:45 +02:00
let diff = Number ( params [ length - 1 ] ) ;
if ( Number . isInteger ( Number ( diff ) ) ) {
length -- ;
2021-03-25 00:14:56 +01:00
}
else {
diff = 0 ;
}
const caracName = params [ 0 ] ;
2023-01-05 02:14:23 +01:00
let competence = length > 1 ? actors [ 0 ] . getCompetence ( Misc . join ( params . slice ( 1 , length ) , ' ' ) ) : { name : undefined } ;
2022-07-08 01:22:53 +02:00
if ( competence ) {
for ( let actor of actors ) {
await actor . rollCaracCompetence ( caracName , competence . name , diff ) ;
}
2021-03-25 00:14:56 +01:00
}
return ;
}
2021-05-01 12:54:45 +02:00
else {
2021-03-25 00:14:56 +01:00
ui . notifications . warn ( "Sélectionnez au moins un personnage pour lancer les dés" )
}
2020-12-29 00:11:58 +01:00
}
}
2021-01-21 00:05:22 +01:00
/* -------------------------------------------- */
2020-12-29 00:11:58 +01:00
async rollRdDNumeric ( msg , carac , diff , significative = false ) {
let rollData = {
caracValue : carac ,
finalLevel : diff ,
2021-01-22 23:18:19 +01:00
diviseurSignificative : significative ? 2 : 1 ,
2021-10-08 23:28:55 +02:00
show : { title : "Table de résolution" }
2020-12-29 00:11:58 +01:00
} ;
await RdDResolutionTable . rollData ( rollData ) ;
2022-11-17 01:57:36 +01:00
return RdDCommands . _chatAnswer ( msg , await RdDResolutionTable . buildRollDataHtml ( rollData ) ) ;
2020-12-29 00:11:58 +01:00
}
2020-12-31 11:53:41 +01:00
2021-01-21 00:05:22 +01:00
/* -------------------------------------------- */
2020-12-31 11:53:41 +01:00
async rollDeDraconique ( msg ) {
2021-12-03 22:53:38 +01:00
let ddr = await RdDDice . rollTotal ( "1dr + 7" ) ;
2022-11-17 01:57:36 +01:00
return RdDCommands . _chatAnswer ( msg , ` Lancer d'un Dé draconique: ${ ddr } ` ) ;
2020-12-31 11:53:41 +01:00
}
2021-01-21 00:05:22 +01:00
2021-05-11 21:45:43 +02:00
async getTMRAleatoire ( msg , params ) {
2021-02-05 01:38:40 +01:00
if ( params . length < 2 ) {
let type = params [ 0 ] ;
2021-05-11 21:45:43 +02:00
const tmr = await TMRUtility . getTMRAleatoire ( type ? ( it => it . type == type ) : ( it => true ) ) ;
2022-11-17 01:57:36 +01:00
return RdDCommands . _chatAnswer ( msg , ` Case aléatoire: ${ tmr . coord } - ${ tmr . label } ` ) ;
2021-02-05 01:38:40 +01:00
}
else {
return false ;
}
}
2021-11-26 23:29:06 +01:00
async findTMR ( msg , params ) {
2022-11-17 01:57:36 +01:00
if ( params && params . length > 0 ) {
const search = Misc . join ( params , ' ' ) ;
const found = TMRUtility . findTMR ( search ) ;
if ( found ? . length > 0 ) {
return RdDCommands . _chatAnswer ( msg , ` Les TMRs correspondant à ' ${ search } ' sont: ` + Misc . join ( found . map ( it => ` <br> ${ it . coord } : ${ it . label } ` ) ) ) ;
}
return RdDCommands . _chatAnswer ( msg , 'Aucune TMR correspondant à ' + search ) ;
2021-11-26 23:29:06 +01:00
}
2022-11-17 01:57:36 +01:00
return false ;
2021-11-26 23:29:06 +01:00
}
2022-11-30 13:27:05 +01:00
2022-11-26 03:13:45 +01:00
async tableRencontres ( msg , params ) {
if ( params && params . length > 0 ) {
const search = Misc . join ( params , ' ' ) ;
const solvedTerrain = TMRUtility . findTMRLike ( search ) ;
if ( solvedTerrain == undefined ) {
return RdDCommands . _chatAnswer ( msg , 'Aucune TMR correspondant à ' + search ) ;
}
2022-11-28 11:31:19 +01:00
return await game . system . rdd . rencontresTMR . chatTable ( solvedTerrain ) ;
2022-11-26 03:13:45 +01:00
}
return false ;
}
2021-02-05 01:38:40 +01:00
2021-01-21 00:05:22 +01:00
/* -------------------------------------------- */
getCoutXpComp ( msg , params ) {
if ( params && ( params . length == 1 || params . length == 2 ) ) {
let to = params . length == 1 ? Number ( params [ 0 ] ) : Number ( params [ 1 ] ) ;
let from = params . length == 1 ? to - 1 : Number ( params [ 0 ] ) ;
2022-11-17 01:57:36 +01:00
return RdDCommands . _chatAnswer ( msg , ` Coût pour passer une compétence de ${ from } à ${ to } : ${ RdDItemCompetence . getDeltaXp ( from , to ) } ` ) ;
2021-01-21 00:05:22 +01:00
}
else {
return false ;
}
}
/* -------------------------------------------- */
getCoutXpCarac ( msg , params ) {
if ( params && params . length == 1 ) {
let to = Number ( params [ 0 ] ) ;
2022-11-17 01:57:36 +01:00
return RdDCommands . _chatAnswer ( msg , ` Coût pour passer une caractéristique de ${ to - 1 } à ${ to } : ${ RdDCarac . getCaracXp ( to ) } ` ) ;
2021-01-21 00:05:22 +01:00
}
else {
return false ;
}
}
2021-05-11 00:52:25 +02:00
async creerSignesDraconiques ( ) {
2023-01-05 02:14:23 +01:00
if ( game . user . isGM ) {
DialogCreateSigneDraconique . createSigneForActors ( ) ;
}
else {
ui . notifications . warn ( "Seul le MJ est autorisé à utiliser la commande /signe" ) ;
}
2021-05-11 00:52:25 +02:00
return true ;
}
async supprimerSignesDraconiquesEphemeres ( ) {
2023-01-05 02:14:23 +01:00
if ( game . user . isGM ) {
game . actors . forEach ( actor => {
const ephemeres = actor . items . filter ( item => item . type = 'signedraconique' && item . system . ephemere ) ;
if ( ephemeres . length > 0 ) {
actor . deleteEmbeddedDocuments ( "Item" , ephemeres . map ( item => item . id ) ) ;
}
} ) ;
}
else {
ui . notifications . warn ( "Seul le MJ est autorisé à utiliser la commande /signe" ) ;
}
2021-05-11 00:52:25 +02:00
return true ;
}
2021-10-08 23:28:55 +02:00
async distribuerStress ( params ) {
if ( ! game . user . isGM ) {
ui . notifications . warn ( "Seul le MJ est autorisé à utiliser la commande /stress" ) ;
return false ;
}
2021-11-26 23:29:06 +01:00
if ( params . length < 3 ) {
2021-10-08 23:28:55 +02:00
DialogStress . distribuerStress ( ) ;
}
else {
let stress = params [ 0 ]
if ( stress == undefined ) {
ui . notifications . warn ( "Pas de valeur de stress à distribuer!" ) ;
return ;
}
2021-11-26 23:29:06 +01:00
let motif = params . slice ( 1 , params . length - 2 ) ;
let name = params [ params . length - 1 ] ;
2021-10-08 23:28:55 +02:00
if ( name == undefined ) {
for ( let actor of game . actors ) {
actor . distribuerStress ( 'stress' , stress , motif ) ;
}
} else {
//console.log(stressValue, nomJoueur);
let actor = Misc . findActor ( name , game . actors . filter ( it => it . hasPlayerOwner ) ) ? ? Misc . findPlayer ( name ) ? . character
if ( actor ) {
actor . distribuerStress ( 'stress' , stress , motif ) ;
}
else {
ui . notifications . warn ( ` Pas de personnage ou de joueur correspondant à ${ name } ! ` ) ;
}
}
}
return true ;
}
2022-06-25 22:18:46 +02:00
async getMeteo ( msg , params ) {
return await RdDMeteo . getMeteo ( ) ;
}
2022-11-04 20:41:16 +01:00
2023-01-13 04:54:29 +01:00
async tirage ( ) {
2023-01-17 21:51:49 +01:00
FenetreRechercheTirage . create ( ) ;
2023-01-13 04:54:29 +01:00
}
2020-12-29 00:11:58 +01:00
}