2020-05-22 22:37:02 +02:00
/* Common useful functions shared between objects */
2020-11-24 15:20:05 +01:00
import { ChatUtility } from "./chat-utility.js" ;
2021-03-15 00:07:53 +01:00
import { RdDCombat } from "./rdd-combat.js" ;
2021-02-06 01:34:01 +01:00
import { Misc } from "./misc.js" ;
2021-02-06 21:53:25 +01:00
import { Grammar } from "./grammar.js" ;
2021-05-04 12:22:19 +02:00
import { TMRUtility } from "./tmr-utility.js" ;
2024-06-01 00:17:39 +02:00
import { DialogItemAchat } from "./achat-vente/dialog-item-achat.js" ;
2023-06-20 23:43:24 +02:00
import { ReglesOptionnelles } from "./settings/regles-optionnelles.js" ;
2021-05-11 21:45:43 +02:00
import { RdDDice } from "./rdd-dice.js" ;
2021-06-02 16:04:35 +02:00
import { RdDItem } from "./item.js" ;
2021-11-21 12:04:42 +01:00
import { RdDPossession } from "./rdd-possession.js" ;
2022-07-22 01:31:21 +02:00
import { RdDNameGen } from "./rdd-namegen.js" ;
2022-10-04 23:23:43 +02:00
import { RdDConfirm } from "./rdd-confirm.js" ;
2022-12-03 22:32:32 +01:00
import { RdDItemCompetence } from "./item-competence.js" ;
2022-12-06 01:30:12 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js" ;
2023-03-29 22:53:40 +02:00
import { RdDTimestamp } from "./time/rdd-timestamp.js" ;
2023-01-18 01:37:22 +01:00
import { RdDRaretes } from "./item/raretes.js" ;
2023-04-21 18:18:20 +02:00
import { RdDEmpoignade } from "./rdd-empoignade.js" ;
2023-05-28 21:59:11 +02:00
import { ExperienceLog } from "./actor/experience-log.js" ;
2023-11-21 21:07:37 +01:00
import { RdDCoeur } from "./coeur/rdd-coeur.js" ;
2024-05-12 22:40:06 +02:00
import { APP _ASTROLOGIE _REFRESH } from "./sommeil/app-astrologie.js" ;
2024-07-04 20:31:24 +02:00
import { RDD _CONFIG } from "./constants.js" ;
2020-06-11 00:29:32 +02:00
2020-12-02 20:52:37 +01:00
/* -------------------------------------------- */
2020-08-13 22:28:56 +02:00
// This table starts at 0 -> niveau -10
2021-01-08 22:23:50 +01:00
const carac _array = [ "taille" , "apparence" , "constitution" , "force" , "agilite" , "dexterite" , "vue" , "ouie" , "odoratgout" , "volonte" , "intellect" , "empathie" , "reve" , "chance" , "melee" , "tir" , "lancer" , "derobee" ] ;
2023-03-14 02:38:21 +01:00
const difficultesLibres = Misc . intArray ( 0 , - 11 ) ;
2023-03-08 02:00:38 +01:00
const ajustementsConditions = Misc . intArray ( - 10 , 11 ) ;
const ajustementsEncaissement = Misc . intArray ( - 10 , 26 ) ;
2021-01-13 22:16:23 +01:00
2020-12-02 20:52:37 +01:00
/* -------------------------------------------- */
2020-11-17 13:08:52 +01:00
function _buildAllSegmentsFatigue ( max ) {
const cycle = [ 5 , 2 , 4 , 1 , 3 , 0 ] ;
2023-11-03 20:21:17 +01:00
const fatigue = [ [ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ] ] ;
2020-11-18 20:16:59 +01:00
for ( let i = 0 ; i <= max ; i ++ ) {
2024-05-02 14:08:02 +02:00
const ligneFatigue = foundry . utils . duplicate ( fatigue [ i ] ) ;
2020-11-17 13:08:52 +01:00
const caseIncrementee = cycle [ i % 6 ] ;
ligneFatigue [ caseIncrementee ] ++ ;
ligneFatigue [ caseIncrementee + 6 ] ++ ;
ligneFatigue . fatigueMax = 2 * ( i + 1 ) ;
2021-01-08 22:23:50 +01:00
fatigue [ i + 1 ] = ligneFatigue ;
2020-11-17 13:08:52 +01:00
}
return fatigue ;
}
2020-12-02 20:52:37 +01:00
/* -------------------------------------------- */
2020-11-18 20:16:59 +01:00
function _cumulSegmentsFatigue ( matrix ) {
let cumulMatrix = [ ] ;
2021-01-08 22:23:50 +01:00
for ( let line of matrix ) {
2024-05-02 14:08:02 +02:00
let cumul = foundry . utils . duplicate ( line ) ;
2021-01-08 22:23:50 +01:00
2020-11-18 20:16:59 +01:00
for ( let i = 1 ; i < 12 ; i ++ ) {
cumul [ i ] += cumul [ i - 1 ] ;
}
cumulMatrix . push ( cumul ) ;
}
return cumulMatrix ;
}
2020-11-17 13:08:52 +01:00
2020-12-02 20:52:37 +01:00
/* -------------------------------------------- */
2023-11-04 03:42:39 +01:00
export const MAX _ENDURANCE _FATIGUE = 60 ;
const fatigueMatrix = _buildAllSegmentsFatigue ( MAX _ENDURANCE _FATIGUE ) ;
2020-11-18 20:16:59 +01:00
const cumulFatigueMatrix = _cumulSegmentsFatigue ( fatigueMatrix ) ;
2020-11-17 13:08:52 +01:00
2021-01-08 22:23:50 +01:00
const fatigueMalus = [ 0 , 0 , 0 , - 1 , - 1 , - 1 , - 2 , - 3 , - 4 , - 5 , - 6 , - 7 ] ; // Provides the malus for each segment of fatigue
const fatigueLineSize = [ 3 , 6 , 7 , 8 , 9 , 10 , 11 , 12 ] ;
const fatigueLineMalus = [ 0 , - 1 , - 2 , - 3 , - 4 , - 5 , - 6 , - 7 ] ;
2020-12-06 21:11:30 +01:00
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
const nomEthylisme = [ "Emeché" , "Gris" , "Pinté" , "Pas frais" , "Ivre" , "Bu" , "Complètement fait" , "Ivre mort" ] ;
2020-12-06 21:11:30 +01:00
2020-12-02 20:52:37 +01:00
/* -------------------------------------------- */
2020-11-11 04:21:25 +01:00
const definitionsEncaissement = {
"mortel" : [
2023-11-21 21:07:37 +01:00
{ minimum : undefined , maximum : 0 , endurance : "0" , vie : "0" , gravite : - 1 } ,
{ minimum : 1 , maximum : 10 , endurance : "1d4" , vie : "0" , gravite : 0 } ,
{ minimum : 11 , maximum : 15 , endurance : "1d6" , vie : "0" , gravite : 2 } ,
{ minimum : 16 , maximum : 19 , endurance : "2d6" , vie : "2" , gravite : 4 } ,
{ minimum : 20 , maximum : undefined , endurance : "100" , vie : "4 + @over20" , gravite : 6 } ,
2020-11-11 04:21:25 +01:00
] ,
"non-mortel" : [
2023-11-21 21:07:37 +01:00
{ minimum : undefined , maximum : 0 , endurance : "0" , vie : "0" , gravite : - 1 } ,
2023-03-14 02:38:21 +01:00
{ minimum : 1 , maximum : 10 , endurance : "1d4" , vie : "0" , gravite : 0 } ,
{ minimum : 11 , maximum : 15 , endurance : "1d6" , vie : "0" , gravite : 0 } ,
{ minimum : 16 , maximum : 19 , endurance : "2d6" , vie : "0" , gravite : 2 } ,
{ minimum : 20 , maximum : undefined , endurance : "100" , vie : "0" , gravite : 2 } ,
2020-11-11 04:21:25 +01:00
] ,
2023-03-14 02:38:21 +01:00
"entiteincarnee" : [
2023-11-21 21:07:37 +01:00
{ minimum : undefined , maximum : 0 , endurance : "0" , vie : "0" , gravite : - 1 } ,
{ minimum : 1 , maximum : 10 , endurance : "1d4" , vie : "0" , gravite : 0 } ,
2023-03-14 02:38:21 +01:00
{ minimum : 11 , maximum : 15 , endurance : "1d6" , vie : "0" , gravite : 0 } ,
{ minimum : 16 , maximum : 19 , endurance : "2d6" , vie : "0" , gravite : 0 } ,
{ minimum : 20 , maximum : undefined , endurance : "3d6 + @over20" , vie : "0" , gravite : 0 } ,
2020-11-11 04:21:25 +01:00
]
} ;
2020-07-06 09:03:21 +02:00
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
export class RdDUtility {
2023-11-21 16:03:26 +01:00
// persistent handling of conteneur show/hide
static afficheContenu = { }
2021-03-29 23:41:08 +02:00
/* -------------------------------------------- */
static async init ( ) {
2024-05-27 00:37:19 +02:00
Hooks . on ( "renderChatMessage" , async ( app , html , msg ) => await ChatUtility . onRenderChatMessage ( app , html , msg ) )
Hooks . on ( "createChatMessage" , async ( chatMessage , options , id ) => await ChatUtility . onCreateChatMessage ( chatMessage , options , id ) )
Hooks . on ( 'renderChatLog' , ( log , html , chatLog ) => RdDUtility . chatListeners ( html ) )
2021-03-29 23:41:08 +02:00
}
2020-05-24 20:19:57 +02:00
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
static async preloadHandlebarsTemplates ( ) {
2020-05-24 20:19:57 +02:00
const templatePaths = [
//Character Sheets
'systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html' ,
2020-11-04 16:29:10 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor-creature-sheet.html' ,
2020-11-14 23:24:01 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor-entite-sheet.html' ,
2021-01-10 22:12:07 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor-vehicule-sheet.html' ,
2022-09-26 03:36:18 +02:00
// sous-parties de feuilles de personnages
2022-10-05 19:29:16 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/header-buttons.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/header-etat.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/header-compteurs.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/header-compteurs-creature.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/header-compteurs-entitee.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/header-effects.html' ,
2022-12-16 01:22:09 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor/header-hautreve.html' ,
2023-06-20 02:58:51 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/archetype.hbs' ,
2022-10-05 19:29:16 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/vue-detaillee.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/carac-main.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/carac-derivee.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/carac-creature.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/carac-entitee.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/comp-creature.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/comp-possession.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/carac-total.html' ,
2022-09-26 23:01:29 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/competence.html' ,
2022-10-05 19:29:16 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/competence-categorie.html' ,
2022-09-26 23:01:29 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/xp-competences.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/combat.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/blessures.html' ,
2023-03-10 22:37:21 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor/blessure.hbs' ,
2022-09-26 23:01:29 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/maladies-poisons.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/possessions.html' ,
2023-05-27 16:34:30 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/resonances.hbs' ,
2022-09-26 23:01:29 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/taches.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/taches.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/oeuvres.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/oeuvre.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/jeux.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/alchimie.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/astrologie.html' ,
2023-01-19 02:42:25 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor/chirurgie.html' ,
2022-09-26 23:01:29 +02:00
'systems/foundryvtt-reve-de-dragon/templates/actor/non-haut-revant.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/haut-revant.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/dragon-queues.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/dragon-queue.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/dragon-souffles.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/dragon-tetes.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/hr-signes-draconiques.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/hr-rencontres.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/hr-sorts.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/hr-sorts-reserve.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/hr-meditations.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/hr-casestmr.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/xp-journal.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/editor-notes-mj.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/inventaire.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html' ,
"systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-monnaie.html" ,
2023-11-21 16:03:26 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor/liens-animaux.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/liens-suivants.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/liens-vehicules.hbs' ,
2023-01-01 22:21:30 +01:00
'systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire.html' ,
'systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html' ,
2020-05-24 20:19:57 +02:00
//Items
2022-11-28 11:31:19 +01:00
'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete-script.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/scripts/autocomplete.hbs' ,
2022-12-03 22:32:32 +01:00
'systems/foundryvtt-reve-de-dragon/templates/item/boutons-comestible.html' ,
2023-11-20 17:19:52 +01:00
'systems/foundryvtt-reve-de-dragon/templates/item/icon-arme-broken.hbs' ,
2023-01-05 00:55:04 +01:00
'systems/foundryvtt-reve-de-dragon/templates/item/temporel.hbs' ,
2022-11-29 00:01:54 +01:00
'systems/foundryvtt-reve-de-dragon/templates/item/partial-inventaire.html' ,
2022-11-28 11:31:19 +01:00
'systems/foundryvtt-reve-de-dragon/templates/item/partial-environnement.html' ,
'systems/foundryvtt-reve-de-dragon/templates/item/partial-tab-environnement.html' ,
2023-01-05 00:55:04 +01:00
'systems/foundryvtt-reve-de-dragon/templates/item-queue-sheet.html' ,
2022-09-16 02:20:46 +02:00
'systems/foundryvtt-reve-de-dragon/templates/header-item.html' ,
2022-11-01 00:30:43 +01:00
// partial enums
2020-11-09 23:56:25 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-aspect-tarot.html' ,
2023-06-24 23:39:58 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-base-competence.html' ,
'systems/foundryvtt-reve-de-dragon/templates/enum-caracteristiques.html' ,
2023-06-13 01:55:38 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-categories.html' ,
2021-01-08 22:23:50 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-ingredient.html' ,
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-parade.html' ,
2022-11-01 00:30:43 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-potion.html' ,
2023-06-24 23:39:58 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-queue.html' ,
2021-01-10 22:12:07 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-categorie-vehicule.html' ,
2021-01-08 22:23:50 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-competence.html' ,
2023-06-24 23:39:58 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-draconic.html' ,
2022-11-01 01:03:35 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-heures.html' ,
2021-02-05 09:36:42 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-initpremierround.html' ,
2023-06-24 23:39:58 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-mortalite.html' ,
2022-11-01 00:30:43 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-niveau-ethylisme.html' ,
2023-01-07 23:28:30 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-periode.html' ,
2023-06-24 23:39:58 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-rarete.html' ,
2022-11-01 00:30:43 +01:00
'systems/foundryvtt-reve-de-dragon/templates/enum-tmr-effet.html' ,
2023-06-24 23:39:58 +02:00
'systems/foundryvtt-reve-de-dragon/templates/enum-tmr-type.html' ,
2021-04-20 23:16:18 +02:00
// Partials
2023-11-21 21:07:37 +01:00
'systems/foundryvtt-reve-de-dragon/templates/coeur/chat-effet-tendre-moment.hbs' ,
2023-11-27 23:45:33 +01:00
'systems/foundryvtt-reve-de-dragon/templates/coeur/afficher-coeur.hbs' ,
2023-01-30 22:07:15 +01:00
'systems/foundryvtt-reve-de-dragon/templates/tirage/liste-resultats-recherche.hbs' ,
2023-03-29 22:53:40 +02:00
'systems/foundryvtt-reve-de-dragon/templates/time/horloge.hbs' ,
2023-12-26 19:05:41 +01:00
'systems/foundryvtt-reve-de-dragon/templates/voyage/fatigue-actor.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/voyage/option-vitesse-fatigue.hbs' ,
2023-01-05 00:55:04 +01:00
'systems/foundryvtt-reve-de-dragon/templates/common/timestamp.hbs' ,
2024-05-27 00:37:19 +02:00
'systems/foundryvtt-reve-de-dragon/templates/common/date-heure.hbs' ,
2023-01-07 23:28:30 +01:00
'systems/foundryvtt-reve-de-dragon/templates/common/periodicite.hbs' ,
2023-01-05 00:55:04 +01:00
'systems/foundryvtt-reve-de-dragon/templates/common/enum-duree.hbs' ,
2022-12-03 18:31:05 +01:00
'systems/foundryvtt-reve-de-dragon/templates/common/compendium-link.hbs' ,
2021-04-22 19:08:37 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-description-overflow.html' ,
2021-04-24 00:50:20 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html' ,
2021-04-20 23:16:18 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html' ,
2023-12-08 22:26:29 +01:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-astrologique.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-coeur.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-competences.html' ,
2021-04-20 23:16:18 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffLibre.html' ,
2021-10-30 01:34:57 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffFixe.html' ,
2021-04-20 23:16:18 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-diffCondition.html' ,
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-enctotal.html' ,
2021-10-30 01:34:57 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-forcer.html' ,
2023-12-08 22:26:29 +01:00
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-moral.html' ,
'systems/foundryvtt-reve-de-dragon/templates/partial-roll-surenc.html' ,
2021-05-27 22:40:12 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-select-carac.html' ,
2022-11-24 00:48:06 +01:00
'systems/foundryvtt-reve-de-dragon/templates/partial-item-hautrevant.html' ,
'systems/foundryvtt-reve-de-dragon/templates/partial-item-frequence.html' ,
2021-06-29 16:03:10 +02:00
'systems/foundryvtt-reve-de-dragon/templates/partial-item-description.html' ,
2022-12-07 14:21:48 +01:00
'systems/foundryvtt-reve-de-dragon/templates/roll/explain.hbs' ,
2022-12-06 01:30:12 +01:00
'systems/foundryvtt-reve-de-dragon/templates/resolution-table.html' ,
2022-11-01 01:03:35 +01:00
// Dialogs
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-resolution.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-competence.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-encaisser.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-validation-encaissement.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-meditation.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html' ,
'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-alchimie.html' ,
2023-02-07 18:06:45 +01:00
'systems/foundryvtt-reve-de-dragon/templates/sommeil/sommeil-actor-moral.hbs' ,
2023-03-08 02:02:40 +01:00
'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-gardien.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-joueur.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/sommeil/astrologie-theme.hbs' ,
2020-12-20 02:07:27 +01:00
// HUD
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-init.html' ,
2021-01-01 21:11:56 +01:00
'systems/foundryvtt-reve-de-dragon/templates/hud-actor-attaque.html' ,
2021-01-01 22:25:32 +01:00
// messages tchat
2021-01-02 14:10:43 +01:00
'systems/foundryvtt-reve-de-dragon/templates/chat-infojet.html' ,
2021-06-23 11:05:38 +02:00
'systems/foundryvtt-reve-de-dragon/templates/chat-description.html' ,
2021-02-12 12:50:17 +01:00
'systems/foundryvtt-reve-de-dragon/templates/chat-info-appel-au-moral.html' ,
2022-10-07 23:28:41 +02:00
'systems/foundryvtt-reve-de-dragon/templates/chat-info-distance.html' ,
2023-10-30 19:08:34 +01:00
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-acteur.hbs' ,
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-turn-sante.hbs' ,
2021-01-03 18:19:18 +01:00
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-competence-xp.html' ,
2021-04-09 15:23:48 +02:00
'systems/foundryvtt-reve-de-dragon/templates/chat-actor-carac-xp.html' ,
2021-04-10 21:07:53 +02:00
'systems/foundryvtt-reve-de-dragon/templates/chat-potionenchantee-chateaudormant.html' ,
2021-05-11 00:52:25 +02:00
'systems/foundryvtt-reve-de-dragon/templates/chat-fabriquer-potion-base.html' ,
'systems/foundryvtt-reve-de-dragon/templates/chat-signe-draconique-actor.html'
2020-05-24 20:19:57 +02:00
] ;
2022-12-05 15:29:00 +01:00
Handlebars . registerHelper ( 'either' , ( a , b ) => a ? ? b ) ;
2021-02-12 12:50:17 +01:00
Handlebars . registerHelper ( 'upperFirst' , str => Misc . upperFirst ( str ? ? 'Null' ) ) ;
2022-06-25 22:18:46 +02:00
Handlebars . registerHelper ( 'lowerFirst' , str => Misc . lowerFirst ( str ? ? 'Null' ) ) ;
2023-03-10 22:41:11 +01:00
Handlebars . registerHelper ( 'upper' , str => str ? . toUpperCase ( ) ? ? '' ) ;
Handlebars . registerHelper ( 'lowercase' , str => str ? . toLowerCase ( ) ? ? '' ) ;
2021-02-12 12:50:17 +01:00
Handlebars . registerHelper ( 'le' , str => Grammar . articleDetermine ( str ) ) ;
2022-06-25 22:18:46 +02:00
Handlebars . registerHelper ( 'apostrophe' , ( article , str ) => Grammar . apostrophe ( article , str ) ) ;
2021-02-12 12:50:17 +01:00
Handlebars . registerHelper ( 'un' , str => Grammar . articleIndetermine ( str ) ) ;
2021-02-25 02:00:27 +01:00
Handlebars . registerHelper ( 'accord' , ( genre , ... args ) => Grammar . accord ( genre , args ) ) ;
2024-07-04 20:31:24 +02:00
Handlebars . registerHelper ( 'RDD_CONFIG' , path => RDD _CONFIG [ path ] )
Handlebars . registerHelper ( 'computeResolutionScore' , ( row , col ) => RdDResolutionTable . computePercentage ( row , col ) ) ;
Handlebars . registerHelper ( 'computeResolutionChances' , ( row , col ) => RdDResolutionTable . computeChances ( row , col ) ) ;
2023-01-28 15:43:31 +01:00
Handlebars . registerHelper ( 'buildLigneInventaire' , ( item , options ) => { return new Handlebars . SafeString ( RdDUtility . buildLigneInventaire ( item , options ) ) ; } ) ;
Handlebars . registerHelper ( 'buildInventaireConteneur' , ( actorId , itemId , options ) => { return new Handlebars . SafeString ( RdDUtility . buildInventaireConteneur ( actorId , itemId , options ) ) ; } ) ;
Handlebars . registerHelper ( 'buildContenuConteneur' , ( item , options ) => { return new Handlebars . SafeString ( RdDUtility . buildContenuConteneur ( item , options ) ) ; } ) ;
2023-01-03 01:37:50 +01:00
Handlebars . registerHelper ( 'calculerPrixCommercant' , item => item . calculerPrixCommercant ( ) ) ;
2021-05-04 12:22:19 +02:00
Handlebars . registerHelper ( 'caseTmr-label' , coord => TMRUtility . getTMRLabel ( coord ) ) ;
Handlebars . registerHelper ( 'caseTmr-type' , coord => TMRUtility . getTMRType ( coord ) ) ;
2022-11-26 03:13:45 +01:00
Handlebars . registerHelper ( 'typeTmr-name' , type => TMRUtility . typeTmrName ( type ) ) ;
2022-11-05 18:19:53 +01:00
Handlebars . registerHelper ( 'effetRencontre-name' , coord => TMRUtility . typeTmrName ( coord ) ) ;
2023-01-07 23:28:30 +01:00
2023-01-05 00:55:04 +01:00
Handlebars . registerHelper ( 'timestamp-imgSigneHeure' , ( heure ) => { return new Handlebars . SafeString ( RdDTimestamp . imgSigneHeure ( heure ) ) } ) ;
Handlebars . registerHelper ( 'timestamp-imgSigne' , ( heure ) => { return new Handlebars . SafeString ( RdDTimestamp . imgSigne ( heure ) ) } ) ;
Handlebars . registerHelper ( 'timestamp-extract' , timestamp => new RdDTimestamp ( timestamp ) . toCalendrier ( ) ) ;
Handlebars . registerHelper ( 'timestamp-formulesDuree' , ( ) => RdDTimestamp . formulesDuree ( ) ) ;
2023-01-07 23:28:30 +01:00
Handlebars . registerHelper ( 'timestamp-formulesPeriode' , ( ) => RdDTimestamp . formulesPeriode ( ) ) ;
2023-01-05 00:55:04 +01:00
2023-12-26 19:05:41 +01:00
Handlebars . registerHelper ( 'array-includes' , ( array , value ) => array . includes ( value ) ) ;
2021-06-04 20:29:03 +02:00
Handlebars . registerHelper ( 'min' , ( ... args ) => Math . min ( ... args . slice ( 0 , - 1 ) ) ) ;
2023-06-20 23:43:24 +02:00
Handlebars . registerHelper ( 'regle-optionnelle' , ( option ) => ReglesOptionnelles . isUsing ( option ) ) ;
2022-11-01 23:44:18 +01:00
Handlebars . registerHelper ( 'trier' , list => list . sort ( ( a , b ) => a . name . localeCompare ( b . name ) ) ) ;
2022-12-05 15:29:00 +01:00
Handlebars . registerHelper ( 'filtreTriCompetences' , competences => RdDItemCompetence . triVisible ( competences ) ) ;
Handlebars . registerHelper ( 'linkCompendium' , ( pack , id , name ) => RdDUtility . linkCompendium ( pack , id , name ) ) ;
Handlebars . registerHelper ( 'uniteQuantite' , ( itemId , actorId ) => RdDUtility . getItem ( itemId , actorId ) ? . getUniteQuantite ( ) ) ;
2022-12-03 15:33:16 +01:00
Handlebars . registerHelper ( 'isFieldInventaireModifiable' , ( type , field ) => RdDItem . isFieldInventaireModifiable ( type , field ) ) ;
2023-01-13 04:54:29 +01:00
Handlebars . registerHelper ( 'rarete-getChamp' , ( rarete , field ) => RdDRaretes . getChamp ( rarete , field ) ) ;
2023-11-21 21:07:37 +01:00
2023-11-10 23:23:58 +01:00
Handlebars . registerHelper ( 'plusMoins' , diff => ( diff > 0 ? '+' : '' ) + Math . round ( diff ) )
2023-05-28 21:59:11 +02:00
Handlebars . registerHelper ( 'experienceLog-topic' , topic => ExperienceLog . labelTopic ( topic ) ) ;
2024-05-31 21:48:19 +02:00
// Handle v12 removal of this helper
Handlebars . registerHelper ( 'select' , function ( selected , options ) {
const escapedValue = RegExp . escape ( Handlebars . escapeExpression ( selected ) ) ;
const rgx = new RegExp ( ' value=[\"\']' + escapedValue + '[\"\']' ) ;
const html = options . fn ( this ) ;
return html . replace ( rgx , "$& selected" ) ;
} ) ;
2020-05-24 20:19:57 +02:00
return loadTemplates ( templatePaths ) ;
}
2020-11-18 16:57:58 +01:00
2022-12-05 15:29:00 +01:00
static getItem ( itemId , actorId = undefined ) {
2022-12-28 23:36:48 +01:00
return actorId ? game . actors . get ( actorId ) ? . getItem ( itemId ) : game . items . get ( itemId ) ;
2022-12-05 15:29:00 +01:00
}
2022-12-03 18:31:05 +01:00
static linkCompendium ( pack , id , name ) {
return ` @Compendium[ ${ pack } . ${ id } ]{ ${ name } } ` ;
}
2021-04-10 21:07:53 +02:00
/* -------------------------------------------- */
2021-04-14 22:28:49 +02:00
static buildListOptions ( min , max ) {
2021-04-10 21:07:53 +02:00
let options = ""
2021-04-14 22:28:49 +02:00
for ( let i = min ; i <= max ; i ++ ) {
2021-04-10 21:07:53 +02:00
options += ` <option value=" ${ i } "> ${ i } </option> `
}
return options ;
}
2021-02-22 21:15:10 +01:00
2021-01-08 22:23:50 +01:00
/* -------------------------------------------- */
2022-06-12 08:17:59 +02:00
static arrayOrEmpty ( items ) {
if ( items ? . length ) {
2020-11-18 16:57:58 +01:00
return items ;
}
return [ ] ;
}
2020-12-06 20:11:30 +01:00
/* -------------------------------------------- */
2023-11-21 16:03:26 +01:00
static getNomEthylisme ( niveauEthylisme ) { return niveauEthylisme > 0 ? 'Aucun' : nomEthylisme [ - niveauEthylisme ] }
2020-12-06 21:11:30 +01:00
2020-12-01 22:18:15 +01:00
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
static toggleAfficheContenu ( conteneurId ) {
2023-11-21 16:03:26 +01:00
RdDUtility . afficheContenu [ conteneurId ] = ! RdDUtility . afficheContenu [ conteneurId ] ;
2020-12-01 22:18:15 +01:00
}
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
static getAfficheContenu ( conteneurId ) {
2021-02-12 12:50:17 +01:00
if ( conteneurId )
2023-11-21 16:03:26 +01:00
return RdDUtility . afficheContenu [ conteneurId ] ;
2021-01-10 22:12:07 +01:00
return undefined ;
2020-12-01 22:18:15 +01:00
}
2020-11-18 16:57:58 +01:00
/* -------------------------------------------- */
2023-06-05 20:17:19 +02:00
static buildArbreDeConteneurs ( conteneurs , inventaires ) {
2022-06-12 08:17:59 +02:00
let objetVersConteneur = { } ;
2020-11-18 16:57:58 +01:00
// Attribution des objets aux conteneurs
2021-05-07 01:47:51 +02:00
for ( let conteneur of conteneurs ) {
2022-06-12 08:17:59 +02:00
conteneur . subItems = [ ] ;
2022-05-03 09:01:10 +02:00
for ( let id of conteneur . system . contenu ? ? [ ] ) {
2023-06-05 20:17:19 +02:00
let objet = inventaires . find ( objet => ( id == objet . _id ) ) ;
2021-05-27 22:40:12 +02:00
if ( objet ) {
objet . estContenu = true ; // Permet de filtrer ce qui est porté dans le template
2022-06-12 08:17:59 +02:00
objetVersConteneur [ id ] = conteneur . _id ;
conteneur . subItems . push ( objet ) ;
2020-11-18 16:57:58 +01:00
}
}
}
2021-05-27 22:40:12 +02:00
for ( let conteneur of conteneurs ) {
2023-06-05 20:17:19 +02:00
conteneur . system . encTotal = RdDUtility . calculEncContenu ( conteneur , inventaires ) ;
2021-05-27 22:40:12 +02:00
}
2022-06-12 08:17:59 +02:00
return objetVersConteneur ;
2021-05-07 01:47:51 +02:00
}
2021-05-27 22:40:12 +02:00
2021-11-21 12:04:42 +01:00
/* -------------------------------------------- */
2023-06-05 20:17:19 +02:00
static calculEncContenu ( conteneur , inventaires ) {
2022-09-07 18:47:56 +02:00
const contenus = ( conteneur . system . contenu ? ? [ ] ) . filter ( id => id != undefined )
2023-06-05 20:17:19 +02:00
. map ( id => inventaires . find ( it => ( id == it . id ) ) )
2022-06-12 08:17:59 +02:00
. filter ( it => it ) ;
let enc = Number ( conteneur . system . encombrement ? ? 0 ) * Number ( conteneur . system . quantite ? ? 1 ) ;
2022-09-07 18:47:56 +02:00
for ( let contenu of contenus ) {
if ( contenu . type == 'conteneur' ) {
2023-06-05 20:17:19 +02:00
enc += RdDUtility . calculEncContenu ( contenu , inventaires ) ;
2021-05-27 22:40:12 +02:00
}
2021-12-05 16:48:18 +01:00
else {
2022-09-07 18:47:56 +02:00
enc += Number ( contenu . system . encombrement ? ? 0 ) * Number ( contenu . system . quantite ? ? 1 )
2021-05-27 22:40:12 +02:00
}
}
2022-06-12 08:17:59 +02:00
return enc
2021-05-27 22:40:12 +02:00
}
2021-11-21 12:04:42 +01:00
/* -------------------------------------------- */
2021-05-07 01:47:51 +02:00
// Construit la liste des conteneurs de niveau 1 (c'est à dire non contenu eux-même dans un conteneur)
static conteneursRacine ( conteneurs ) {
2021-05-27 22:40:12 +02:00
return conteneurs . filter ( ( conteneur , index , arr ) => ! conteneur . estContenu ) ;
2020-11-18 16:57:58 +01:00
}
2023-01-28 15:43:31 +01:00
static prepareOptionsArbreInventaire ( item , optionsArbre ) {
if ( ! optionsArbre . profondeur ) {
optionsArbre . profondeur = 1
} ;
if ( ! optionsArbre . templateItem ) {
optionsArbre . templateItem = item . parent ? . type == 'commerce'
? "systems/foundryvtt-reve-de-dragon/templates/actor/commerce-inventaire-item.html"
: "systems/foundryvtt-reve-de-dragon/templates/actor/inventaire-item.html" ;
}
item . niveau = optionsArbre . profondeur ;
}
2020-11-12 14:44:42 +01:00
/* -------------------------------------------- */
2023-01-28 15:43:31 +01:00
/ * *
* Construit la structure récursive des conteneurs , avec imbrication potentielle
2020-11-12 15:06:25 +01:00
* /
2023-01-28 15:43:31 +01:00
static buildLigneInventaire ( item , options = { } , optionsArbre = { ouvert : false , profondeur : 1 } ) {
RdDUtility . prepareOptionsArbreInventaire ( item , optionsArbre ) ;
const isConteneur = item . type == 'conteneur' ;
const inventaire = {
item : item ,
vide : isConteneur && item . system . contenu . length == 0 ,
ouvert : isConteneur && RdDUtility . getAfficheContenu ( item . _id ) ,
2023-01-01 22:21:30 +01:00
options : options
2023-01-28 15:43:31 +01:00
} ;
optionsArbre . ouvert = inventaire . ouvert
const ligneObjet = Handlebars . partials [ optionsArbre . templateItem ] ( inventaire ) ;
if ( isConteneur ) {
return ligneObjet + RdDUtility . buildContenuConteneur ( item , options , optionsArbre ) ;
}
return ligneObjet ;
}
static buildInventaireConteneur ( actorId , itemId , options ) {
const actor = game . actors . get ( actorId )
const item = actor ? . items . get ( itemId )
if ( item ) {
return RdDUtility . buildContenuConteneur ( item , options , { ouvert : true , profondeur : 1 } ) ;
}
return '' ;
2021-12-05 01:50:09 +01:00
}
2022-06-12 08:17:59 +02:00
/* -------------------------------------------- */
2023-01-28 15:43:31 +01:00
static buildContenuConteneur ( conteneur , options = { } , optionsArbre = { } ) {
RdDUtility . prepareOptionsArbreInventaire ( conteneur , optionsArbre ) ;
const display = optionsArbre . ouvert ? 'item-display-show' : 'item-display-hide' ;
2023-02-11 21:20:12 +01:00
const profondeur = optionsArbre . profondeur ;
2023-01-28 15:43:31 +01:00
optionsArbre . profondeur ++ ;
2023-02-11 21:20:12 +01:00
const lignesContenu = conteneur . subItems . sort ( Misc . ascending ( it => it . name ) )
. map ( contenu => this . buildLigneInventaire ( contenu , options , optionsArbre ) ) ;
return ` <ul class='item-list alterne-list ${ display } list-item-margin ${ Math . min ( profondeur , 6 ) } '> `
+ lignesContenu . reduce ( Misc . joining ( '' ) , '' )
+ "</ul>" ;
2020-11-12 14:43:08 +01:00
}
2020-05-24 20:19:57 +02:00
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
static getCaracArray ( ) {
2020-05-24 20:19:57 +02:00
return carac _array ;
}
2021-01-08 22:23:50 +01:00
static getDifficultesLibres ( ) {
2020-11-15 02:07:41 +01:00
return difficultesLibres ;
}
2021-01-08 22:23:50 +01:00
static getAjustementsConditions ( ) {
2020-11-15 02:07:41 +01:00
return ajustementsConditions ;
2020-05-24 20:19:57 +02:00
}
2021-01-08 22:23:50 +01:00
static getAjustementsEncaissement ( ) {
2020-12-01 00:05:18 +01:00
return ajustementsEncaissement ;
}
2020-05-24 20:19:57 +02:00
2020-11-24 16:41:15 +01:00
/* -------------------------------------------- */
2023-11-03 20:21:17 +01:00
static getSegmentsFatigue ( maxEndurance ) {
return fatigueMatrix [ Math . min ( Math . max ( maxEndurance , 1 ) , fatigueMatrix . length ) ] ;
2020-11-17 13:08:52 +01:00
}
2020-11-24 16:41:15 +01:00
/* -------------------------------------------- */
2023-11-04 03:42:39 +01:00
static calculMalusFatigue ( fatigue , endurance ) {
endurance = Math . min ( Math . max ( endurance , 1 ) , cumulFatigueMatrix . length ) ;
let segments = cumulFatigueMatrix [ endurance ] ;
for ( let i = 0 ; i < segments . length ; i ++ ) {
2020-11-18 20:16:59 +01:00
if ( fatigue <= segments [ i ] ) {
return fatigueMalus [ i ]
}
2020-11-17 13:08:52 +01:00
}
2020-11-18 20:16:59 +01:00
return - 7 ;
2020-11-17 13:08:52 +01:00
}
2021-05-08 20:08:56 +02:00
2021-11-21 12:04:42 +01:00
/* -------------------------------------------- */
2021-05-08 20:08:56 +02:00
static calculFatigueHtml ( fatigue , endurance ) {
2023-06-20 23:43:24 +02:00
return ReglesOptionnelles . isUsing ( "appliquer-fatigue" ) ? {
2021-05-08 20:08:56 +02:00
malus : RdDUtility . calculMalusFatigue ( fatigue , endurance ) ,
html : "<table class='table-fatigue'>" + RdDUtility . makeHTMLfatigueMatrix ( fatigue , endurance ) . html ( ) + "</table>"
2021-05-27 22:40:12 +02:00
} : { malus : 0 , html : '' } ;
2021-05-08 20:08:56 +02:00
}
2020-05-27 23:47:49 +02:00
/* -------------------------------------------- */
2020-05-29 00:43:16 +02:00
// Build the nice (?) html table used to manage fatigue.
2020-11-17 13:08:52 +01:00
// max should be the endurance max value
2021-01-08 22:23:50 +01:00
static makeHTMLfatigueMatrix ( fatigue , maxEndurance ) {
2023-11-03 20:21:17 +01:00
const segments = this . getSegmentsFatigue ( maxEndurance ) ;
2020-11-17 13:08:52 +01:00
return this . makeHTMLfatigueMatrixForSegment ( fatigue , segments ) ;
}
2020-05-29 00:43:16 +02:00
2021-11-21 12:04:42 +01:00
/* -------------------------------------------- */
2020-11-17 13:08:52 +01:00
static makeHTMLfatigueMatrixForSegment ( fatigue , segments ) {
fatigue = Math . max ( fatigue , 0 ) ;
fatigue = Math . min ( fatigue , segments . fatigueMax ) ;
let table = $ ( "<table/>" ) . addClass ( 'table-fatigue' ) ;
2020-05-27 23:47:49 +02:00
let segmentIdx = 0 ;
2020-05-28 23:36:09 +02:00
let fatigueCount = 0 ;
2020-11-17 13:08:52 +01:00
for ( var line = 0 ; line < fatigueLineSize . length ; line ++ ) {
2020-05-27 23:47:49 +02:00
let row = $ ( "<tr/>" ) ;
let segmentsPerLine = fatigueLineSize [ line ] ;
2020-05-28 23:36:09 +02:00
row . append ( "<td class='fatigue-malus'>" + fatigueLineMalus [ line ] + "</td>" ) ;
2020-05-27 23:47:49 +02:00
while ( segmentIdx < segmentsPerLine ) {
2020-11-17 13:08:52 +01:00
let freeSize = segments [ segmentIdx ] ;
for ( let col = 0 ; col < 5 ; col ++ ) {
if ( col < freeSize ) {
if ( fatigueCount < fatigue )
2020-12-11 19:14:24 +01:00
row . append ( "<td class='fatigue-used'>X</td>" ) ;
2020-11-17 13:08:52 +01:00
2020-05-28 23:36:09 +02:00
else
row . append ( "<td class='fatigue-free'/>" ) ;
fatigueCount ++ ;
2020-11-17 13:08:52 +01:00
} else {
2020-05-27 23:47:49 +02:00
row . append ( "<td class='fatigue-none'/>" ) ;
2020-05-28 23:36:09 +02:00
}
2020-05-27 23:47:49 +02:00
}
row . append ( "<td class='fatigue-separator'/>" ) ;
segmentIdx = segmentIdx + 1 ;
}
table . append ( row ) ;
}
return table ;
}
2020-11-17 13:08:52 +01:00
2020-05-31 23:06:25 +02:00
/* -------------------------------------------- */
2021-05-11 21:45:43 +02:00
static async getLocalisation ( type = 'personnage' ) {
let result = await RdDDice . rollTotal ( "1d20" ) ;
2020-06-07 23:16:29 +02:00
let txt = ""
2021-02-12 12:50:17 +01:00
if ( type == 'personnage' ) {
2021-02-08 16:14:43 +01:00
if ( result <= 3 ) txt = "Jambe, genou, pied, jarret" ;
else if ( result <= 7 ) txt = "Hanche, cuisse, fesse" ;
else if ( result <= 9 ) txt = "Ventre, reins" ;
else if ( result <= 12 ) txt = "Poitrine, dos" ;
else if ( result <= 14 ) txt = "Avant-bras, main, coude" ;
else if ( result <= 18 ) txt = "Epaule, bras, omoplate" ;
else if ( result == 19 ) txt = "Tête" ;
else if ( result == 20 ) txt = "Tête (visage)" ;
} else {
if ( result <= 7 ) txt = "Jambes/Pattes" ;
else if ( result <= 18 ) txt = "Corps" ;
2021-02-12 12:50:17 +01:00
else if ( result <= 20 ) txt = "Tête" ;
2021-02-08 16:14:43 +01:00
}
2021-01-08 22:23:50 +01:00
2020-06-07 23:16:29 +02:00
return { result : result , label : txt } ;
2020-05-31 23:06:25 +02:00
}
2020-11-11 04:21:25 +01:00
2020-11-11 10:38:27 +01:00
/* -------------------------------------------- */
2022-10-09 02:19:33 +02:00
static async jetEncaissement ( rollData , armure , options = { showDice : HIDE _DICE } ) {
2024-05-12 21:58:48 +02:00
const diff = Math . abs ( rollData . diffLibre ) ;
let formula = RdDUtility . formuleEncaissement ( diff , options )
const roll = await RdDDice . roll ( formula , options ) ;
2022-10-09 02:19:33 +02:00
2024-05-12 21:58:48 +02:00
RdDUtility . remplaceDeMinParDifficulte ( roll , diff , options ) ;
2022-10-09 02:19:33 +02:00
2024-05-12 21:58:48 +02:00
return await RdDUtility . prepareEncaissement ( rollData , roll , armure ) ;
}
2022-10-09 02:19:33 +02:00
2024-05-12 21:58:48 +02:00
static remplaceDeMinParDifficulte ( roll , diff , options ) {
if ( ! ReglesOptionnelles . isUsing ( 'degat-minimum-malus-libre-simple' ) ) {
return
}
2022-10-09 02:19:33 +02:00
// 1 dé fait au minmum la difficulté libre
2024-05-12 21:58:48 +02:00
const total = options . forceDiceResult ? . total ;
if ( total ) {
const reste = Math . max ( total - diff , 1 )
roll . terms [ 0 ] . number = reste + diff
}
else {
if ( roll . terms [ 0 ] . results [ 0 ] . result < diff ) {
roll . terms [ 0 ] . results [ 0 ] . result = diff ;
} else if ( roll . terms [ 0 ] . results [ 1 ] . result < diff ) {
roll . terms [ 0 ] . results [ 1 ] . result = diff ;
2022-10-09 02:19:33 +02:00
}
2024-05-12 21:58:48 +02:00
roll . _total = roll . terms [ 0 ] . results [ 0 ] . result + roll . terms [ 0 ] . results [ 1 ] . result ;
2022-10-09 02:19:33 +02:00
}
2024-05-12 21:58:48 +02:00
}
2022-10-09 02:19:33 +02:00
2024-05-12 21:58:48 +02:00
static formuleEncaissement ( diff , options ) {
// Chaque dé fait au minimum la difficulté libre
if ( ReglesOptionnelles . isUsing ( 'degat-minimum-malus-libre' ) ) {
return ` 2d10min ${ diff } `
}
return '2d10'
2022-10-09 02:19:33 +02:00
}
2023-01-05 00:55:04 +01:00
2022-10-09 02:19:33 +02:00
/* -------------------------------------------- */
static async prepareEncaissement ( rollData , roll , armure ) {
2024-05-12 21:58:48 +02:00
// La difficulté d'ataque s'ajoute aux dégâts
const bonusDegatsDiffLibre = ReglesOptionnelles . isUsing ( 'degat-ajout-malus-libre' ) ? Math . abs ( rollData . diffLibre ? ? 0 ) : 0
const jetTotal = roll . total + rollData . dmg . total - armure + bonusDegatsDiffLibre
const encaissement = RdDUtility . _selectEncaissement ( jetTotal , rollData . dmg . mortalite ) ;
const over20 = Math . max ( jetTotal - 20 , 0 ) ;
2022-10-09 02:19:33 +02:00
encaissement . dmg = rollData . dmg ;
encaissement . dmg . loc = rollData . dmg . loc ? ? await RdDUtility . getLocalisation ( this . type ) ;
encaissement . dmg . loc . label = encaissement . dmg . loc . label ? ? 'Corps;' ;
2024-05-12 21:58:48 +02:00
encaissement . dmg . bonusDegatsDiffLibre = bonusDegatsDiffLibre
2022-10-09 02:19:33 +02:00
encaissement . roll = roll ;
encaissement . armure = armure ;
2023-03-14 02:38:21 +01:00
encaissement . penetration = rollData . arme ? . system . penetration ? ? 0 ;
2022-10-09 02:19:33 +02:00
encaissement . total = jetTotal ;
encaissement . vie = await RdDUtility . _evaluatePerte ( encaissement . vie , over20 ) ;
encaissement . endurance = await RdDUtility . _evaluatePerte ( encaissement . endurance , over20 ) ;
return encaissement ;
}
/* -------------------------------------------- */
static _selectEncaissement ( degats , mortalite ) {
2020-11-11 04:21:25 +01:00
const table = definitionsEncaissement [ mortalite ] === undefined ? definitionsEncaissement [ "mortel" ] : definitionsEncaissement [ mortalite ] ;
for ( let encaissement of table ) {
if ( ( encaissement . minimum === undefined || encaissement . minimum <= degats )
&& ( encaissement . maximum === undefined || degats <= encaissement . maximum ) ) {
2024-05-02 14:08:02 +02:00
return foundry . utils . duplicate ( encaissement ) ;
2020-11-11 04:21:25 +01:00
}
2020-06-07 23:16:29 +02:00
}
2024-05-02 14:08:02 +02:00
return foundry . utils . duplicate ( table [ 0 ] ) ;
2020-11-11 04:21:25 +01:00
}
2022-10-09 02:19:33 +02:00
/* -------------------------------------------- */
static async _evaluatePerte ( formula , over20 ) {
let perte = new Roll ( formula , { over20 : over20 } ) ;
2024-05-31 21:48:19 +02:00
await perte . evaluate ( ) ;
2022-10-09 02:19:33 +02:00
return perte . total ;
}
2020-06-17 20:31:43 +02:00
/* -------------------------------------------- */
2021-10-30 00:42:18 +02:00
static onSocketMessage ( sockmsg ) {
2021-01-08 22:23:50 +01:00
switch ( sockmsg . msg ) {
2020-11-24 15:20:05 +01:00
case "msg_gm_chat_message" :
return ChatUtility . handleGMChatMessage ( sockmsg . data ) ;
2024-05-12 22:40:06 +02:00
case "msg_app_astrologie_refresh" :
return Hooks . callAll ( APP _ASTROLOGIE _REFRESH ) ;
2020-12-12 23:31:19 +01:00
case "msg_request_nombre_astral" :
2021-01-08 22:23:50 +01:00
return game . system . rdd . calendrier . requestNombreAstral ( sockmsg . data ) ;
2021-02-12 12:50:17 +01:00
case "msg_tmr_move" :
2021-04-28 00:48:39 +02:00
let actor = game . actors . get ( sockmsg . data . actorId ) ;
2021-05-27 22:40:12 +02:00
if ( actor . isOwner || game . user . isGM ) {
2022-06-25 17:49:19 +02:00
actor . refreshTMRView ( ) ;
2021-02-12 12:50:17 +01:00
}
2021-04-28 00:48:39 +02:00
break ;
2020-11-24 15:20:05 +01:00
}
}
2020-06-07 23:16:29 +02:00
/* -------------------------------------------- */
2021-01-08 22:23:50 +01:00
static async chatListeners ( html ) {
2023-11-21 16:03:26 +01:00
RdDCombat . registerChatCallbacks ( html )
RdDEmpoignade . registerChatCallbacks ( html )
2023-11-21 21:07:37 +01:00
RdDCoeur . registerChatCallbacks ( html )
2020-12-15 23:54:05 +01:00
2020-12-30 19:18:07 +01:00
// Gestion spécifique message passeurs
2020-11-17 16:30:03 +01:00
html . on ( "click" , '.tmr-passeur-coord a' , event => {
2021-01-08 22:23:50 +01:00
let coord = event . currentTarget . attributes [ 'data-tmr-coord' ] . value ;
2020-11-17 18:08:19 +01:00
let actorId = event . currentTarget . attributes [ 'data-actor-id' ] . value ;
2021-01-08 22:23:50 +01:00
let actor = game . actors . get ( actorId ) ;
2022-06-25 17:49:19 +02:00
actor . tmrApp . positionnerDemiReve ( coord ) ;
2020-11-17 18:08:19 +01:00
} ) ;
2020-12-31 00:55:02 +01:00
// Gestion spécifique des sorts en réserve multiples (ie têtes)
2022-09-17 16:07:38 +02:00
html . on ( "click" , '.declencher-sort-reserve' , event => {
2021-01-08 22:23:50 +01:00
let coord = event . currentTarget . attributes [ 'data-tmr-coord' ] . value ;
let sortId = event . currentTarget . attributes [ 'data-sort-id' ] . value ;
2020-12-30 19:18:07 +01:00
let actorId = event . currentTarget . attributes [ 'data-actor-id' ] . value ;
2021-01-08 22:23:50 +01:00
let actor = game . actors . get ( actorId ) ;
2020-12-30 19:18:07 +01:00
actor . tmrApp . lancerSortEnReserve ( coord , sortId ) ;
2022-09-17 16:07:38 +02:00
// TODO: supprimer le message?
2021-01-08 22:23:50 +01:00
} ) ;
2021-05-07 17:27:02 +02:00
2022-07-02 01:41:55 +02:00
// gestion bouton tchat Possession
2021-11-21 12:04:42 +01:00
html . on ( "click" , '.defense-possession' , event => {
2022-06-12 08:17:59 +02:00
let attackerId = event . currentTarget . attributes [ 'data-attackerId' ] . value
let defenderId = event . currentTarget . attributes [ 'data-defenderId' ] . value
let possessionId = event . currentTarget . attributes [ 'data-possessionId' ] . value
RdDPossession . onDefensePossession ( attackerId , defenderId , possessionId )
2021-11-21 12:04:42 +01:00
} ) ;
2021-05-07 17:27:02 +02:00
// gestion bouton tchat Acheter
2022-10-07 19:05:56 +02:00
html . on ( "click" , '.button-acheter' , event => {
2022-12-23 00:34:17 +01:00
const venteData = DialogItemAchat . preparerAchat ( event . currentTarget ) ;
2022-10-07 19:05:56 +02:00
if ( venteData ) {
DialogItemAchat . onAcheter ( venteData ) ;
}
} ) ;
2022-07-22 01:31:21 +02:00
html . on ( "click" , '.button-creer-acteur' , event => RdDNameGen . onCreerActeur ( event ) ) ;
2021-05-27 22:40:12 +02:00
2020-12-31 00:55:02 +01:00
// Gestion du bouton payer
2021-03-29 23:41:08 +02:00
html . on ( "click" , '.payer-button' , event => {
2022-11-29 00:01:54 +01:00
let sommeAPayer = Number ( event . currentTarget . attributes [ 'data-somme-a-payer' ] ? . value ? ? 0 ) ;
2021-04-14 22:28:49 +02:00
let actor = RdDUtility . getSelectedActor ( "Pour effectuer le paiement:" ) ;
if ( actor ) {
2022-11-29 00:01:54 +01:00
actor . payerSols ( sommeAPayer ) ;
2021-06-01 00:10:02 +02:00
ChatUtility . removeChatMessageId ( RdDUtility . findChatMessageId ( event . currentTarget ) ) ;
2021-01-01 21:11:56 +01:00
}
2020-12-31 00:55:02 +01:00
} ) ;
2022-12-23 00:34:17 +01:00
html . on ( "click" , '.rdd-world-content-link' , async event => {
2022-12-29 02:25:45 +01:00
const htmlElement = html . find ( event . currentTarget ) ;
const id = htmlElement ? . data ( "id" ) ;
2023-01-05 00:55:04 +01:00
const doctype = htmlElement ? . data ( "doctype" ) ;
2022-12-29 02:25:45 +01:00
switch ( doctype ? ? 'Item' ) {
case 'Actor' :
return game . actors . get ( id ) ? . sheet . render ( true ) ;
case 'Item' :
default :
return game . items . get ( id ) ? . sheet . render ( true ) ;
}
2022-12-23 00:34:17 +01:00
} ) ;
2020-06-07 23:16:29 +02:00
}
2021-04-15 01:14:24 +02:00
static findChatMessageId ( current ) {
2021-05-07 17:27:02 +02:00
return RdDUtility . getChatMessageId ( RdDUtility . findChatMessage ( current ) ) ;
}
static getChatMessageId ( node ) {
return node ? . attributes . getNamedItem ( 'data-message-id' ) ? . value ;
}
static findChatMessage ( current ) {
return RdDUtility . findNodeMatching ( current , it => it . classList . contains ( 'chat-message' ) && it . attributes . getNamedItem ( 'data-message-id' ) ) ;
2021-04-15 01:14:24 +02:00
}
static findNodeMatching ( current , predicate ) {
if ( current ) {
if ( predicate ( current ) ) {
return current ;
}
return RdDUtility . findNodeMatching ( current . parentElement , predicate ) ;
}
return undefined ;
}
2021-05-07 17:27:02 +02:00
static getSelectedActor ( msgPlayer = undefined ) {
2021-04-14 22:28:49 +02:00
if ( canvas . tokens . controlled . length == 1 ) {
let token = canvas . tokens . controlled [ 0 ] ;
2022-09-07 18:47:56 +02:00
if ( token . actor ) {
2021-04-14 22:28:49 +02:00
return token . actor ;
}
2021-05-27 22:40:12 +02:00
if ( msgPlayer != undefined ) {
2021-05-07 17:27:02 +02:00
msgPlayer += "<br>le token sélectionné doit être lié à un personnage" ;
}
2021-04-14 22:28:49 +02:00
}
if ( game . user . character ) {
return game . user . character ;
}
2021-05-27 22:40:12 +02:00
if ( msgPlayer != undefined ) {
2021-05-07 17:27:02 +02:00
msgPlayer += "<br>vous pouvez sélectionner un seul token lié à un personnage" ;
msgPlayer += "<br>vous devez être connecté comme joueur avec un personnage sélectionné" ;
ui . notifications . warn ( msgPlayer ) ;
ChatMessage . create ( { content : msgPlayer , whisper : [ game . user ] } ) ;
}
2021-04-14 22:28:49 +02:00
return undefined ;
}
2020-12-31 10:55:40 +01:00
/* -------------------------------------------- */
2022-11-28 11:31:55 +01:00
static createMonnaie ( name , cout , img = "" , enc = 0.01 ) {
2021-01-08 22:23:50 +01:00
let piece = {
name : name , type : 'monnaie' , img : img , _id : randomID ( 16 ) ,
2022-09-07 18:47:56 +02:00
dasystemta : {
2021-01-08 22:23:50 +01:00
quantite : 0 ,
2022-11-28 11:31:55 +01:00
cout : cout ,
2021-01-08 22:23:50 +01:00
encombrement : enc ,
description : ""
}
}
2020-12-31 10:55:40 +01:00
return piece ;
}
2020-12-31 00:55:02 +01:00
/* -------------------------------------------- */
static afficherDemandePayer ( som1 , som2 ) {
som1 = ( som1 ) ? som1 . toLowerCase ( ) : "0d" ;
som2 = ( som2 ) ? som2 . toLowerCase ( ) : "0d" ;
2022-11-29 00:01:54 +01:00
let regExp1 = /(\d+)(\w+)/g ;
let p1 = regExp1 . exec ( som1 ) ;
let regExp2 = /(\d+)(\w+)/g ;
let p2 = regExp2 . exec ( som2 ) ;
let deniers = 0 ;
let sols = 0 ;
if ( p1 [ 2 ] == 'd' ) deniers += Number ( p1 [ 1 ] ) ;
if ( p1 [ 2 ] == 's' ) sols += Number ( p1 [ 1 ] ) ;
if ( p2 [ 2 ] == 'd' ) deniers += Number ( p2 [ 1 ] ) ;
if ( p2 [ 2 ] == 's' ) sols += Number ( p2 [ 1 ] ) ;
2023-01-05 00:55:04 +01:00
let sommeAPayer = sols + deniers / 100 ;
2022-11-29 00:01:54 +01:00
let msgPayer = ` La somme de ${ sols } Sols et ${ deniers } Deniers est à payer<br>
< a class = 'payer-button chat-card-button' data - somme - a - payer = '${sommeAPayer}' > Payer < / a > `
2021-01-08 22:23:50 +01:00
ChatMessage . create ( { content : msgPayer } ) ;
2020-12-31 00:55:02 +01:00
}
2021-01-01 21:11:56 +01:00
/* -------------------------------------------- */
static chatDataSetup ( content , modeOverride , isRoll = false , forceWhisper ) {
let chatData = {
2021-03-25 03:18:27 +01:00
user : game . user . id ,
2021-01-01 21:11:56 +01:00
rollMode : modeOverride || game . settings . get ( "core" , "rollMode" ) ,
content : content
} ;
if ( [ "gmroll" , "blindroll" ] . includes ( chatData . rollMode ) ) chatData [ "whisper" ] = ChatMessage . getWhisperRecipients ( "GM" ) . map ( u => u . id ) ;
if ( chatData . rollMode === "blindroll" ) chatData [ "blind" ] = true ;
else if ( chatData . rollMode === "selfroll" ) chatData [ "whisper" ] = [ game . user ] ;
if ( forceWhisper ) { // Final force !
chatData [ "speaker" ] = ChatMessage . getSpeaker ( ) ;
chatData [ "whisper" ] = ChatMessage . getWhisperRecipients ( forceWhisper ) ;
}
2021-02-12 12:50:17 +01:00
return chatData ;
2021-01-11 16:29:41 +01:00
}
2021-01-16 18:54:07 +01:00
/* -------------------------------------------- */
2023-11-21 21:07:37 +01:00
static confirmSubActeurDelete ( sheet , subActor , htmlToDelete , onSuppression = ( ) => { } ) {
2022-10-04 23:23:43 +02:00
RdDConfirm . confirmer ( {
settingConfirmer : "confirmation-supprimer-lien-acteur" ,
content : ` <p>Etes vous certain de vouloir supprimer le lien vers ${ subActor . name } ?</p> ` ,
2022-10-04 01:53:18 +02:00
title : 'Confirmer la suppression' ,
buttonLabel : 'Supprimer le lien' ,
2023-05-27 16:34:30 +02:00
onAction : onSuppression
2022-09-17 01:53:13 +02:00
} )
}
2021-06-02 17:39:16 +02:00
2022-09-17 01:53:13 +02:00
/* -------------------------------------------- */
2022-12-21 00:44:10 +01:00
static async confirmActorItemDelete ( sheet , item , htmlToDelete ) {
2022-09-17 01:53:13 +02:00
const itemId = item . id ;
2022-10-04 23:23:43 +02:00
const confirmationSuppression = {
settingConfirmer : "confirmation-supprimer-" + item . getItemGroup ( ) ,
content : ` <p>Etes vous certain de vouloir supprimer: ${ item . name } ?</p> ` ,
title : ` Supprimer ${ item . name } ` ,
buttonLabel : "Supprimer" ,
onAction : ( ) => {
console . log ( 'Delete : ' , itemId ) ;
sheet . actor . deleteEmbeddedDocuments ( 'Item' , [ itemId ] , { renderSheet : false } ) ;
RdDUtility . slideOnDelete ( sheet , htmlToDelete ) ;
2021-01-11 16:29:41 +01:00
}
2022-10-04 23:23:43 +02:00
} ;
if ( item . isConteneurNonVide ( ) ) {
confirmationSuppression . content += ` <p>Ce conteneur n'est pas vide. Que voulez vous supprimer?</p> ` ;
confirmationSuppression . settingConfirmer = undefined ;
RdDConfirm . confirmer ( confirmationSuppression ,
{
'deleteall' : {
icon : '<i class="fas fa-check"></i>' ,
label : "Supprimer conteneur et contenu" ,
callback : ( ) => {
console . log ( "Delete : " , itemId ) ;
sheet . actor . deleteAllConteneur ( itemId , { renderSheet : false } ) ;
RdDUtility . slideOnDelete ( sheet , htmlToDelete ) ;
}
}
} ) ;
2021-02-12 12:50:17 +01:00
}
2022-10-04 23:23:43 +02:00
else {
RdDConfirm . confirmer ( confirmationSuppression )
2021-02-12 12:50:17 +01:00
}
2021-01-16 18:54:07 +01:00
}
2021-02-12 12:50:17 +01:00
2022-09-17 01:53:13 +02:00
static slideOnDelete ( sheet , htmlToDelete ) {
2022-12-05 15:29:00 +01:00
return htmlToDelete ? . slideUp ( 200 , ( ) => sheet . render ( false ) ) ;
2022-09-17 01:53:13 +02:00
}
2021-01-16 18:54:07 +01:00
/* -------------------------------------------- */
2021-02-12 12:50:17 +01:00
static afficherHeuresChanceMalchance ( heureNaissance ) {
2021-12-05 16:48:18 +01:00
if ( game . user . isGM ) {
2023-01-05 00:55:04 +01:00
const heure = RdDTimestamp . findHeure ( heureNaissance - 1 ) ;
2021-06-04 18:30:06 +02:00
if ( heureNaissance && heure ) {
2021-06-01 20:54:27 +02:00
let ajustement = game . system . rdd . calendrier . getAjustementAstrologique ( heureNaissance ) ;
2023-01-05 00:55:04 +01:00
const current = game . system . rdd . calendrier . heureCourante ( ) ;
2021-06-01 20:54:27 +02:00
ChatMessage . create ( {
2021-06-04 18:30:06 +02:00
content : ` A l'heure de <strong> ${ current . label } </strong>, le modificateur de Chance/Malchance est de <strong> ${ Misc . toSignedString ( ajustement ) } </strong> pour l'heure de naissance <strong> ${ heure . label } </strong>. ` ,
2021-06-01 20:54:27 +02:00
whisper : ChatMessage . getWhisperRecipients ( "GM" )
} ) ;
}
2021-06-04 18:30:06 +02:00
else if ( heureNaissance ) {
2021-12-05 16:48:18 +01:00
ui . notifications . warn ( heureNaissance + " ne correspond pas à une heure de naissance" ) ;
2021-06-04 18:30:06 +02:00
}
2021-06-01 20:54:27 +02:00
else {
ui . notifications . warn ( "Pas d'heure de naissance selectionnée" ) ;
}
} else {
ui . notifications . warn ( "Vous n'avez pas accès à cette commande" ) ;
2021-01-26 19:47:18 +01:00
}
2021-01-16 18:54:07 +01:00
}
2021-02-12 12:50:17 +01:00
2021-02-10 11:24:14 +01:00
/*-------------------------------------------- */
2021-02-06 23:51:04 +01:00
static checkThanatosXP ( compName ) {
2021-02-12 12:50:17 +01:00
if ( compName . includes ( 'Thanatos' ) ) {
2021-02-06 23:51:04 +01:00
let message = "Vous avez mis des points d'Expérience dans la Voie de Thanatos !<br>Vous devez réduire manuellement d'un même montant d'XP une autre compétence Draconique." ;
ChatMessage . create ( {
whisper : ChatMessage . getWhisperRecipients ( game . user . name ) ,
content : message
} ) ;
}
}
2021-02-10 11:24:14 +01:00
2020-05-22 22:37:02 +02:00
}