2020-06-07 23:16:50 +02:00
/ * *
* RdD system
* Author : LeRatierBretonnien
* Software License : GNU GPLv3
* /
/* -------------------------------------------- */
/* -------------------------------------------- */
// Import Modules
import { RdDActor } from "./actor.js" ;
import { RdDItemSheet } from "./item-sheet.js" ;
import { RdDActorSheet } from "./actor-sheet.js" ;
2020-09-20 17:38:21 +02:00
import { RdDActorCreatureSheet } from "./actor-creature-sheet.js" ;
2020-11-04 16:29:10 +01:00
import { RdDActorHumanoideSheet } from "./actor-humanoide-sheet.js" ;
2020-11-14 23:24:01 +01:00
import { RdDActorEntiteSheet } from "./actor-entite-sheet.js" ;
2020-06-07 23:16:50 +02:00
import { RdDUtility } from "./rdd-utility.js" ;
2020-11-17 16:30:03 +01:00
import { TMRUtility } from "./tmr-utility.js" ;
2020-09-20 16:36:39 +02:00
import { RdDCalendrier } from "./rdd-calendrier.js" ;
2020-11-11 22:39:36 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js" ;
2020-06-07 23:16:50 +02:00
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
2020-09-02 22:00:35 +02:00
/************************************************************************************/
const _patch _initiative = ( ) => {
Combat . prototype . rollInitiative = async function (
ids ,
formula = null ,
messageOptions = { }
) {
console . log (
` ${ game . data . system . data . title } | Combat.rollInitiative() ` ,
ids ,
formula ,
messageOptions
) ;
// Structure input data
ids = typeof ids === "string" ? [ ids ] : ids ;
const currentId = this . combatant . _id ;
// calculate initiative
for ( let cId = 0 ; cId < ids . length ; cId ++ ) {
const c = this . getCombatant ( ids [ cId ] ) ;
//if (!c) return results;
2020-11-16 21:18:18 +01:00
let armeCombat , rollFormula , competence ;
if ( c . actor . data . type == 'creature' || c . actor . data . type == 'entite' ) {
for ( const competenceItem of c . actor . data . items ) {
if ( competenceItem . data . iscombat ) {
competence = duplicate ( competenceItem ) ;
}
2020-09-02 22:00:35 +02:00
}
2020-11-16 21:18:18 +01:00
rollFormula = "1d6+" + competence . data . niveau + "+" + Math . ceil ( competence . data . carac _value / 2 ) ;
} else {
for ( const item of c . actor . data . items ) {
if ( item . type == "arme" && item . data . equipe ) {
armeCombat = duplicate ( item ) ;
}
}
let compName = ( armeCombat == undefined ) ? "Corps à corps" : armeCombat . data . competence ;
competence = RdDUtility . findCompetence ( c . actor . data . items , compName ) ;
rollFormula = "1d6+" + competence . data . niveau + "+" + Math . ceil ( c . actor . data . data . carac [ competence . data . defaut _carac ] . value / 2 ) ;
2020-09-02 22:00:35 +02:00
}
//console.log("Combatat", c);
const roll = this . _getInitiativeRoll ( c , rollFormula ) ;
//console.log("Compute init for", armeCombat, competence, rollFormula, roll.total);
await this . updateEmbeddedEntity ( "Combatant" , { _id : c . _id , initiative : roll . total } ) ;
// Send a chat message
let rollMode =
messageOptions . rollMode || game . settings . get ( "core" , "rollMode" ) ;
let messageData = mergeObject (
{
speaker : {
scene : canvas . scene . _id ,
actor : c . actor ? c . actor . _id : null ,
token : c . token . _id ,
alias : c . token . name ,
sound : CONFIG . sounds . dice ,
} ,
flavor : ` ${ c . token . name } a fait son jet d'Initiative (Compétence ${ competence . name } ) ` ,
} ,
messageOptions
) ;
roll . toMessage ( messageData , { rollMode , create : true } ) ;
}
return this ;
} ;
}
/************************************************************************************/
2020-06-07 23:16:50 +02:00
Hooks . once ( "init" , async function ( ) {
console . log ( ` Initializing Reve de Dragon System ` ) ;
// preload handlebars templates
RdDUtility . preloadHandlebarsTemplates ( ) ;
2020-11-12 23:50:37 +01:00
// Create useful storage space
game . system . rdd = {
2020-11-17 16:30:03 +01:00
rollDataHandler : { } ,
TMRUtility : TMRUtility
2020-11-12 23:50:37 +01:00
}
2020-08-13 22:28:56 +02:00
// Create specific settings
2020-11-17 11:35:05 +01:00
// game.settings.register("foundryvtt-reve-de-dragon", "configuration", {
// name: "configuration",
// scope: "world",
// config: false,
// type: Object
// });
game . settings . register ( "foundryvtt-reve-de-dragon" , "dice-so-nice" , {
name : "Montrer les dés pour toutes les jets" ,
hint : "Utilise Dice So Nice pour tous les jets de dés possibles. Décocher pour limiter à la table de résolution" ,
scope : "client" ,
config : true ,
default : false ,
type : Boolean
2020-08-13 22:28:56 +02:00
} ) ;
//game.settings.get("<systemName>","<settingName>") to retrieve it and game.settings.set("<systemName>","<settingName>", <newValue>)
2020-06-07 23:16:50 +02:00
/ * *
* Set an initiative formula for the system
* @ type { String }
* /
CONFIG . Combat . initiative = {
formula : "1d20" ,
decimals : 2
} ;
2020-06-17 20:31:43 +02:00
game . socket . on ( "system.foundryvtt-reve-de-dragon" , data => {
RdDUtility . performSocketMesssage ( data ) ;
} ) ;
2020-06-07 23:16:50 +02:00
// Define custom Entity classes
CONFIG . Actor . entityClass = RdDActor ;
2020-11-11 22:39:36 +01:00
CONFIG . RDD = {
2020-11-15 02:07:41 +01:00
resolutionTable : RdDResolutionTable . resolutionTable ,
level _category : RdDUtility . getLevelCategory ( ) ,
carac _array : RdDUtility . getCaracArray ( ) ,
ajustementsConditions : RdDUtility . getAjustementsConditions ( ) ,
difficultesLibres : RdDUtility . getDifficultesLibres ( )
2020-11-11 22:39:36 +01:00
}
2020-06-07 23:16:50 +02:00
// Register sheet application classes
Actors . unregisterSheet ( "core" , ActorSheet ) ;
2020-09-20 17:38:21 +02:00
Actors . registerSheet ( "foundryvtt-reve-de-dragon" , RdDActorSheet , {
types : [ "personnage" ] ,
makeDefault : true }
) ;
2020-11-14 23:24:01 +01:00
Actors . registerSheet ( "foundryvtt-reve-de-dragon" , RdDActorCreatureSheet , {
2020-09-20 17:38:21 +02:00
types : [ "creature" ] ,
makeDefault : true
} ) ;
2020-11-14 23:24:01 +01:00
Actors . registerSheet ( "foundryvtt-reve-de-dragon" , RdDActorHumanoideSheet , {
2020-11-04 16:29:10 +01:00
types : [ "humanoide" ] ,
makeDefault : true
} ) ;
2020-11-14 23:24:01 +01:00
Actors . registerSheet ( "foundryvtt-reve-de-dragon" , RdDActorEntiteSheet , {
types : [ "entite" ] ,
makeDefault : true
} ) ;
2020-06-07 23:16:50 +02:00
Items . unregisterSheet ( "core" , ItemSheet ) ;
Items . registerSheet ( "foundryvtt-reve-de-dragon" , RdDItemSheet , { makeDefault : true } ) ;
2020-09-02 22:00:35 +02:00
2020-11-12 14:43:08 +01:00
// Handlebar function pour container
Handlebars . registerHelper ( 'buildConteneur' , ( objet ) => { return RdDUtility . buildConteneur ( objet ) ; } ) ;
2020-09-02 22:00:35 +02:00
// Patch the initiative formula
_patch _initiative ( ) ;
2020-07-21 23:51:24 +02:00
} ) ;
2020-11-23 19:51:34 +01:00
Hooks . once ( "renderApplication" , ( ) => {
messageDeBienvenue ( ) ;
} ) ;
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 ( ) ;
} ) ;
ChatMessage . create ( {
whisper : [ game . user ] ,
title : "Bienvenue dans le Rêve !" ,
content : "Bienvenue dans le Rêve des Dragons !<br> " +
"Vous trouverez quelques informations pour démarrer dans ce document : @Compendium[foundryvtt-reve-de-dragon.rappel-des-regles.7uGrUHGdPu0EmIu2]{Documentation MJ/Joueurs}" }
) ;
}
2020-07-24 10:51:11 +02:00
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks . once ( "ready" , function ( ) {
2020-09-20 16:36:39 +02:00
/* Affiche le calendrier */
let calendrier = new RdDCalendrier ( ) ;
let templatePath = "systems/foundryvtt-reve-de-dragon/templates/calendar-template.html" ;
let templateData = { } ;
2020-11-03 09:14:14 +01:00
/ * D I S A B L E D r e n d e r T e m p l a t e ( t e m p l a t e P a t h , t e m p l a t e D a t a ) . t h e n ( h t m l = > {
2020-09-20 16:36:39 +02:00
calendrier . render ( true ) ;
2020-11-03 09:14:14 +01:00
} ) ; * /
2020-09-20 16:36:39 +02:00
} ) ;
2020-07-24 10:51:11 +02:00
2020-07-21 23:51:24 +02:00
/* -------------------------------------------- */
/* Foundry VTT Initialization */
/* -------------------------------------------- */
Hooks . on ( "chatMessage" , ( html , content , msg ) => {
2020-09-13 22:46:42 +02:00
let regExp ;
regExp = /(\S+)/g ;
let commands = content . match ( regExp ) ;
2020-06-07 23:16:50 +02:00
2020-09-13 22:46:42 +02:00
return RdDUtility . processChatCommand ( commands , content , msg ) ;
2020-07-21 23:51:24 +02:00
} ) ;