2020-05-21 21:48:20 +02:00
/ * *
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system .
* @ extends { Actor }
* /
2020-05-22 22:37:02 +02:00
import { RdDUtility } from "./rdd-utility.js" ;
2020-07-25 10:29:28 +02:00
import { TMRUtility } from "./tmr-utility.js" ;
2020-06-03 21:35:18 +02:00
import { RdDRollDialog } from "./rdd-roll-dialog.js" ;
2020-07-05 21:45:25 +02:00
import { RdDTMRDialog } from "./rdd-tmr-dialog.js" ;
2020-11-14 03:16:03 +01:00
import { Misc } from "./misc.js" ;
2020-11-12 16:35:51 +01:00
import { RdDResolutionTable } from "./rdd-resolution-table.js" ;
2020-11-16 04:32:42 +01:00
import { RdDDice } from "./rdd-dice.js" ;
import { RdDRollTables } from "./rdd-rolltables.js" ;
2020-05-22 22:37:02 +02:00
2020-05-22 00:48:43 +02:00
export class RdDActor extends Actor {
2020-05-22 22:37:02 +02:00
2020-05-24 20:19:57 +02:00
/* -------------------------------------------- */
/ * *
* Override the create ( ) function to provide additional RdD functionality .
*
* This overrided create ( ) function adds initial items
* Namely : Basic skills , money ,
*
* @ param { Object } data Barebones actor data which this function adds onto .
* @ param { Object } options ( Unused ) Additional options which customize the creation workflow .
*
* /
2020-06-10 08:23:58 +02:00
2020-05-24 20:19:57 +02:00
static async create ( data , options ) {
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
if ( data . items ) {
return super . create ( data , options ) ;
}
2020-09-20 17:38:21 +02:00
2020-06-22 10:18:03 +02:00
data . items = [ ] ;
2020-09-20 17:38:21 +02:00
let compendiumName = "" ;
2020-11-14 23:24:01 +01:00
if ( data . type == "personnage" ) {
2020-09-20 17:38:21 +02:00
compendiumName = "foundryvtt-reve-de-dragon.competences" ;
2020-11-14 23:24:01 +01:00
} else if ( data . type == "humanoide" ) {
2020-11-04 16:29:10 +01:00
compendiumName = "foundryvtt-reve-de-dragon.competences-humanoides" ;
2020-11-14 23:24:01 +01:00
} else if ( data . type == "creature" ) {
2020-09-20 17:38:21 +02:00
compendiumName = "foundryvtt-reve-de-dragon.competences-creatures" ;
2020-11-14 23:24:01 +01:00
} else if ( data . type == "entite" ) {
compendiumName = "foundryvtt-reve-de-dragon.competences-entites" ;
2020-06-22 10:18:03 +02:00
}
2020-09-20 16:36:39 +02:00
let competences = [ ] ;
const pack = game . packs . get ( compendiumName ) ;
await pack . getIndex ( ) . then ( index => competences = index ) ;
for ( let comp of competences )
{
let compItem = undefined ;
await pack . getEntity ( comp . _id ) . then ( skill => compItem = skill ) ;
data . items . push ( compItem ) ;
}
2020-09-20 17:38:21 +02:00
2020-09-27 22:33:02 +02:00
return super . create ( data , options ) ;
2020-09-20 16:36:39 +02:00
}
2020-09-20 17:38:21 +02:00
/* -------------------------------------------- */
2020-09-20 16:36:39 +02:00
/* -------------------------------------------- */
2020-05-22 00:48:43 +02:00
prepareData ( ) {
super . prepareData ( ) ;
2020-05-21 21:48:20 +02:00
2020-05-22 00:48:43 +02:00
const actorData = this . data ;
const data = actorData . data ;
const flags = actorData . flags ;
2020-05-22 19:28:01 +02:00
2020-11-11 14:42:11 +01:00
// Dynamic computing fields
this . encombrementTotal = 0 ;
2020-05-22 00:48:43 +02:00
// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
if ( actorData . type === 'personnage' ) this . _prepareCharacterData ( actorData ) ;
2020-09-20 21:52:46 +02:00
if ( actorData . type === 'creature' ) this . computeEtatGeneral ( actorData ) ;
2020-11-04 16:29:10 +01:00
if ( actorData . type === 'humanoide' ) this . computeEtatGeneral ( actorData ) ;
2020-05-22 00:48:43 +02:00
}
2020-06-03 21:35:18 +02:00
/* -------------------------------------------- */
2020-05-22 00:48:43 +02:00
/ * *
* Prepare Character type specific data
* /
_prepareCharacterData ( actorData ) {
2020-05-24 20:19:57 +02:00
// Initialize empty items
RdDUtility . computeCarac ( actorData . data ) ;
2020-11-11 14:42:11 +01:00
this . computeEncombrementTotal ( ) ;
2020-06-07 23:16:29 +02:00
this . computeEtatGeneral ( ) ;
2020-05-22 00:48:43 +02:00
}
2020-05-24 20:19:57 +02:00
2020-07-14 22:19:29 +02:00
/* -------------------------------------------- */
2020-11-16 04:01:36 +01:00
getReveActuel ( ) {
2020-07-14 22:19:29 +02:00
return this . data . data . reve . reve . value ;
}
2020-11-12 14:20:10 +01:00
2020-07-14 22:19:29 +02:00
/* -------------------------------------------- */
getBestDraconic ( ) {
2020-11-12 14:20:10 +01:00
const list = this . getDraconicList ( ) . sort ( ( a , b ) => b . data . niveau - a . data . niveau ) ;
if ( list . length == 0 )
{
return { name : "none" , niveau : - 11 } ;
2020-07-14 22:19:29 +02:00
}
2020-11-12 14:20:10 +01:00
return duplicate ( list [ 0 ] ) ;
2020-07-14 22:19:29 +02:00
}
2020-11-12 14:20:10 +01:00
2020-07-26 18:44:03 +02:00
/* -------------------------------------------- */
async deleteSortReserve ( coordTMR ) {
let reserve = duplicate ( this . data . data . reve . reserve ) ;
let len = reserve . list . length ;
let i = 0 ;
let newTable = [ ] ;
for ( i = 0 ; i < len ; i ++ ) {
if ( reserve . list [ i ] . coord != coordTMR )
newTable . push ( reserve . list [ i ] ) ;
}
if ( newTable . length != len ) {
reserve . list = newTable ;
await this . update ( { "data.reve.reserve" : reserve } ) ;
}
}
2020-05-22 22:37:02 +02:00
/* -------------------------------------------- */
2020-11-12 16:35:51 +01:00
async performRoll ( rollData ) {
2020-11-17 11:35:05 +01:00
let rolled = RdDResolutionTable . roll ( rollData . carac , rollData . finalLevel ) ;
2020-11-14 21:22:29 +01:00
//rolled.isPart = true; // Pour tester le particulières
rollData . rolled = rolled ; // garder le résultat
2020-11-16 04:32:42 +01:00
console . log ( "performRoll" , rollData , rolled )
2020-11-17 09:58:46 +01:00
if ( ! rollData . attackerRoll ) // Store in the registry if not a defense roll
game . system . rdd . rollDataHandler [ this . data . _id ] = rollData ;
2020-11-14 21:22:29 +01:00
if ( rolled . isPart && rollData . arme && ! rollData . attackerRoll ) { // Réussite particulière avec attaque -> choix !
2020-11-14 21:38:28 +01:00
let message = "<strong>Réussite particulière en attaque</strong>" ;
2020-11-14 21:22:29 +01:00
message = message + "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='force' data-attackerid='" + this . data . _id + "'>Attaquer en Force</a>" ;
2020-11-14 21:34:34 +01:00
// Finesse et Rapidité seulement en mêlée et si la difficulté libre est de -1 minimum
2020-11-15 09:35:05 +01:00
if ( rollData . selectedCarac . label == "Mêlée" && rollData . diffLibre < 0 ) {
2020-11-14 21:34:34 +01:00
message = message + "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='rapidite' data-attackerid='" + this . data . _id + "'>Attaquer en Rapidité</a>" ;
message = message + "<br><a class='chat-card-button' id='particuliere-attaque' data-mode='finesse' data-attackerid='" + this . data . _id + "'>Attaquer en Finesse</a>" ;
}
2020-11-14 21:22:29 +01:00
ChatMessage . create ( { content : message , whisper : ChatMessage . getWhisperRecipients ( this . name ) } ) ;
} else {
this . continueRoll ( rollData ) ;
}
}
/* -------------------------------------------- */
async continueRoll ( rollData ) {
let rolled = rollData . rolled ;
let result = rolled . roll ;
let quality = rolled . quality
2020-06-12 11:47:41 +02:00
// Manage weapon categories when parrying (cf. page 115 )
2020-11-12 16:35:51 +01:00
let need _resist = false ; // Do we need to make resistance roll for defender ?
if ( rollData . arme && rollData . attackerRoll ) { // Manage parade depeding on weapon type, and change roll results
let attCategory = RdDUtility . getArmeCategory ( rollData . attackerRoll . arme ) ;
let defCategory = RdDUtility . getArmeCategory ( rollData . arme ) ;
if ( defCategory == "bouclier" )
2020-11-15 00:59:23 +01:00
rollData . needSignificative = false ;
2020-11-12 16:35:51 +01:00
else if ( attCategory != defCategory )
rollData . needSignificative = true ;
if ( attCategory . match ( "epee" ) && ( defCategory == "hache" || defCategory == "lance" ) )
2020-06-12 11:47:41 +02:00
need _resist = true ;
}
2020-11-15 11:17:38 +01:00
if ( this . data . type != 'entite' && ( this . data . data . sante . sonne . value || rollData . particuliereAttaque == "finesse" ) ) {
2020-11-12 16:35:51 +01:00
rollData . needSignificative = true ;
2020-06-12 11:47:41 +02:00
}
2020-11-12 16:35:51 +01:00
console . log ( ">>> ROLL" , rollData , rolled ) ;
let xpmsg = RdDResolutionTable . buildXpMessage ( rolled , rollData . finalLevel ) ;
2020-11-15 02:07:41 +01:00
let resumeCompetence = ( rollData . competence ) ? rollData . competence . name : ( rollData . diffLibre + rollData . diffConditions ) ;
let explications = "<br>Points de taches : " + rolled . ptTache + ", ajustement qualité: " + rolled . ptQualite ;
2020-11-12 16:35:51 +01:00
2020-06-10 08:23:58 +02:00
// Fight management !
2020-06-07 23:16:29 +02:00
let defenseMsg ;
2020-06-11 00:29:32 +02:00
let encaisser = false ;
2020-11-13 11:24:56 +01:00
if ( rollData . arme || ( rollData . competence && rollData . competence . name . toLowerCase ( ) == 'esquive' ) ) {
2020-11-14 03:16:03 +01:00
explications = ""
2020-11-12 16:35:51 +01:00
// In case of fight, replace the message per dommages + localization. it indicates if result is OK or not
if ( rollData . attackerRoll ) { // Defense case !
2020-11-14 21:22:29 +01:00
if ( rollData . needSignificative && rolled . isSign ) {
2020-11-14 03:16:03 +01:00
explications += "<br><strong>Attaque parée/esquivée !</strong>" ;
2020-11-14 21:22:29 +01:00
} else if ( ! rollData . needSignificative && rolled . isSuccess ) {
explications += "<br><strong>Attaque parée/esquivée !</strong>" ;
} else {
2020-11-14 03:16:03 +01:00
explications += "<br><strong>Esquive/Parade échouée, encaissement !</strong>" ;
2020-11-12 16:35:51 +01:00
encaisser = true ;
}
2020-06-17 20:31:43 +02:00
} else { // This is the attack roll!
2020-11-13 11:24:56 +01:00
if ( rolled . isSuccess ) {
2020-11-14 21:53:46 +01:00
// Message spécial pour la rapidité, qui reste difficile à gérer automatiquement
if ( rollData . particuliereAttaque == 'rapidite' ) {
ChatMessage . create ( { contet : "Vous avez attaqué en Rapidité. Ce cas n'est pas géré autmatiquement, donc suivez les directives de votre MJ pour gérer ce cas." ,
whisper : ChatMessage . getWhisperRecipients ( this . name ) } ) ;
}
rollData . domArmePlusDom = this . _calculBonusDommages ( rollData . selectedCarac , rollData . arme , rollData . particuliereAttaque == 'force' ) ;
2020-11-14 03:16:03 +01:00
rollData . degats = new Roll ( "2d10" ) . roll ( ) . total + rollData . domArmePlusDom ;
2020-06-11 00:29:32 +02:00
rollData . loc = RdDUtility . getLocalisation ( ) ;
for ( let target of game . user . targets ) {
2020-11-15 11:15:36 +01:00
rollData . mortalite = ( rollData . mortalite ) ? rollData . mortalite : "mortel" ; // Force default
rollData . mortalite = ( target . actor . data . type == 'entite' ) ? "cauchemar" : rollData . mortalite ;
console . log ( "Mortalité : " , rollData . mortalite , target . actor . data . type ) ;
2020-11-12 16:35:51 +01:00
defenseMsg = RdDUtility . buildDefenseChatCard ( this , target , rollData ) ;
2020-11-14 03:16:03 +01:00
explications += "<br><strong>Cible</strong> : " + target . actor . data . name ;
2020-06-11 00:29:32 +02:00
}
2020-11-14 03:16:03 +01:00
explications += "<br>Dommages : " + rollData . degats + "<br>Localisation : " + rollData . loc . label ;
2020-06-11 00:29:32 +02:00
} else {
2020-11-14 03:16:03 +01:00
explications = "<br>Echec ! Pas de dommages" ;
2020-06-07 23:16:29 +02:00
}
}
}
2020-11-12 16:35:51 +01:00
2020-07-25 10:29:28 +02:00
// Sort management
2020-11-12 16:35:51 +01:00
if ( rollData . selectedSort ) { // Lancement de sort !
2020-11-14 03:16:03 +01:00
resumeCompetence = rollData . selectedDraconic . name + "/" + sort . name ;
explications = await this . _rollLancementDeSort ( rollData , rolled ) ;
2020-07-23 22:09:40 +02:00
}
2020-07-27 18:58:10 +02:00
// Save it for fight in the flags area
2020-11-12 23:50:37 +01:00
game . system . rdd . rollDataHandler [ this . data . _id ] = duplicate ( rollData ) ;
2020-11-12 16:35:51 +01:00
2020-07-25 10:29:28 +02:00
// Final chat message
2020-11-12 16:35:51 +01:00
let chatOptions = {
2020-11-14 03:16:03 +01:00
content : "<strong>Test : " + rollData . selectedCarac . label + " / " + resumeCompetence + "</strong>"
2020-11-15 02:07:41 +01:00
+ "<br>Difficultés <strong>libre : " + rollData . diffLibre + "</strong> / conditions : " + Misc . toSignedString ( rollData . diffConditions ) + " / état : " + rollData . etat
2020-11-16 04:32:42 +01:00
+ RdDResolutionTable . explain ( rolled )
2020-11-14 03:16:03 +01:00
+ "<br><strong>" + quality + "</strong>"
+ explications + xpmsg ,
2020-11-12 16:35:51 +01:00
user : game . user . _id ,
title : "Résultat du test"
}
ChatMessage . create ( chatOptions ) ;
2020-06-11 00:29:32 +02:00
// This an attack, generate the defense message
2020-11-12 16:35:51 +01:00
if ( defenseMsg ) {
2020-11-12 23:50:37 +01:00
defenseMsg . rollData = duplicate ( rollData ) ;
2020-11-12 16:35:51 +01:00
if ( defenseMsg . toSocket ) {
2020-07-28 09:20:01 +02:00
game . socket . emit ( "system.foundryvtt-reve-de-dragon" , {
msg : "msg_defense" ,
2020-11-12 16:35:51 +01:00
data : defenseMsg
} ) ;
2020-11-17 09:58:46 +01:00
if ( game . user . isGM ) { // Always push the message to the MJ
ChatMessage . create ( defenseMsg ) ;
}
2020-11-12 16:35:51 +01:00
} else {
defenseMsg . whisper = [ game . user ] ;
ChatMessage . create ( defenseMsg ) ;
2020-07-28 09:20:01 +02:00
}
2020-06-11 00:29:32 +02:00
}
2020-07-28 09:20:01 +02:00
2020-06-11 00:29:32 +02:00
// Get damages!
2020-11-12 16:35:51 +01:00
if ( encaisser ) {
this . encaisserDommages ( rollData . attackerRoll ) ;
2020-06-11 00:29:32 +02:00
}
2020-11-12 16:35:51 +01:00
}
2020-11-15 11:15:36 +01:00
/* -------------------------------------------- */
2020-11-14 21:22:29 +01:00
_calculBonusDommages ( carac , arme , isForce = false ) {
const dmgArme = parseInt ( arme . data . dommages ) + ( isForce ) ? 5 : 0 ;
2020-11-14 03:16:03 +01:00
const dmgPerso = parseInt ( this . data . data . attributs . plusdom . value ) ;
if ( carac . label == "Tir" ) {
return dmgArme ;
}
if ( carac . label == "Lancer" ) {
return dmgArme + Math . min ( dmgArme , dmgPerso ) ;
}
return dmgArme + dmgPerso ;
}
2020-11-15 11:15:36 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
async _rollLancementDeSort ( rollData , rolled ) {
let sort = duplicate ( rollData . selectedSort ) ;
let closeTMR = true ;
let coutReve = sort . data . ptreve _reel || sort . data . ptreve ; // cas de sort à ptreve variables
2020-11-15 02:07:41 +01:00
let explications = "<br>Lancement du sort <strong>" + sort . name + "</strong> : " + Misc . upperFirst ( sort . data . draconic )
2020-11-14 03:16:03 +01:00
+ " pour " + coutReve + " points de Rêve"
+ "<br>Depuis la case " + rollData . coord + " (" + TMRUtility . getTMRDescription ( rollData . coord ) . label + ")" ;
let myReve = duplicate ( this . data . data . reve . reve ) ;
if ( rolled . isSuccess ) { // Réussite du sort !
sort . ptreve _reel = coutReve ;
if ( rolled . isPart ) {
coutReve = Math . max ( Math . ceil ( coutReve / 2 ) , 1 ) ;
}
if ( myReve . value > coutReve ) {
explications += "<br>Réussite du sort: " + coutReve + " points de Rêve sont dépensés" ;
if ( rollData . isSortReserve ) {
// Mise en réserve
myReve . value -- ;
await this . sortMisEnReserve ( rollData , sort ) ;
closeTMR = false ;
}
}
else {
// Todo 0 pts de reve !!!!
explications += "<br>Pas assez de rêve" ;
mergeObject ( rollData , RdDResolutionTable . getResultat ( "echec" ) ) ;
}
} else {
if ( rolled . isETotal ) { // Echec total !
coutReve *= 2 ;
myReve . value = myReve . value - coutReve ;
explications += "<br><strong>Echec TOTAL</strong> du sort : " + coutReve + " Points de Rêve" ;
} else {
coutReve = 0
explications += "<br>Echec du sort !" ;
}
}
myReve . value = Math . max ( myReve . value - coutReve , 0 ) ;
await this . update ( { "data.reve.reve" : myReve } ) ;
if ( myReve . value == 0 ) { // 0 points de reve
ChatMessage . create ( { title : "Zero Points de Reve !" , content : this . name + " est réduit à 0 Points de Rêve, et tombe endormi !" } ) ;
closeTMR = true ;
}
if ( closeTMR ) {
this . currentTMR . close ( ) ; // Close TMR !
}
return explications
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-16 04:32:42 +01:00
async dormir ( heures = 1 ) {
2020-11-17 13:08:52 +01:00
let message = { title : "Récupération" , content : "Vous dormez " + heures + " heure" + ( heures > 1 ? "s" : "" ) } ;
this . recupereEndurance ( message ) ;
2020-11-16 04:32:42 +01:00
for ( let i = 0 ; i < heures ; i ++ ) {
2020-11-17 13:08:52 +01:00
await this . recupererFatigueUneHeure ( message ) ;
this . recuperationReve ( message ) ;
2020-11-16 04:32:42 +01:00
}
2020-11-17 13:08:52 +01:00
ChatMessage . create ( message ) ;
2020-11-16 04:32:42 +01:00
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-17 13:08:52 +01:00
recupereEndurance ( message ) {
const avant = this . data . data . sante . endurance . value ;
this . santeIncDec ( "endurance" , this . data . data . sante . endurance . max - avant ) ;
const recupere = this . data . data . sante . endurance . value - avant ;
if ( recupere > 0 ) {
message . content += "<br>Vous récuperez " + recupere + " points d'endurance" ;
}
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-17 13:08:52 +01:00
async recupererFatigueUneHeure ( message ) {
let fatigue = duplicate ( this . data . data . sante . fatigue )
if ( fatigue . value == 0 ) {
message . content += "<br>Vous êtes déjà reposé" ;
return ;
}
const segments = RdDUtility . getSegmentsFatigue ( this . data . data . sante . endurance . max ) ;
let cumul = 0 ;
console . log ( "recupererFatigue" , segments ) ;
let i ;
for ( i = 0 ; i < 11 ; i ++ ) {
cumul += segments [ i ] ;
let diff = cumul - fatigue . value ;
if ( diff >= 0 )
{
const limit2Segments = Math . floor ( segments [ i ] / 2 ) ;
if ( diff > limit2Segments && i > 0 ) {
cumul -= segments [ i - 1 ] ; // le segment est à moins de la moitié, il est récupéré
2020-11-16 04:32:42 +01:00
}
2020-11-17 13:08:52 +01:00
cumul -= segments [ i ] ;
break ;
}
}
fatigue . value = cumul ;
await this . update ( { "data.sante.fatigue" : fatigue } ) ;
if ( fatigue . value == 0 )
{
message . content += "<br>Vous êtes bien reposé" ;
}
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-17 13:08:52 +01:00
recuperationReve ( message ) {
const seuil = this . data . data . reve . seuil . value ;
const reve = this . getReveActuel ( ) ;
if ( reve >= seuil ) {
message . content += "<br>Vous avez suffisament rêvé (seuil " + seuil + ", rêve actuel " + reve + ")" ;
}
else {
let deRecuperation = RdDDice . deDraconique ( ) ;
console . log ( "recuperationReve" , deRecuperation ) ;
if ( deRecuperation >= 7 )
{
// Rêve de Dragon !
message . content += "<br>Vous faites un <strong>Rêve de Dragon</strong> de " + deRecuperation + " Points de rêve" ;
message . content += this . combattreReveDeDragon ( deRecuperation ) ;
2020-11-16 04:32:42 +01:00
}
2020-11-17 13:08:52 +01:00
else {
message . content += "<br>Vous récupérez " + deRecuperation + " Points de rêve" ;
this . updatePointsDeReve ( deRecuperation ) ;
}
}
2020-11-16 04:32:42 +01:00
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-17 11:35:05 +01:00
combattreReveDeDragon ( force ) {
2020-11-16 04:32:42 +01:00
let draconic = this . getBestDraconic ( ) ;
let niveau = Math . max ( 0 , draconic . data . niveau ) ;
let etat = this . data . data . compteurs . etat . value ;
let difficulte = niveau - etat - force ;
let reveActuel = this . getReveActuel ( ) ;
2020-11-17 11:35:05 +01:00
let rolled = RdDResolutionTable . roll ( reveActuel , difficulte ) ;
2020-11-17 13:08:52 +01:00
// TODO: xp particulière
2020-11-17 14:48:04 +01:00
console . log ( "combattreReveDeDragon" , rolled ) ;
2020-11-17 11:35:05 +01:00
return this . appliquerReveDeDragon ( rolled , force ) ;
2020-11-16 04:32:42 +01:00
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-17 11:35:05 +01:00
appliquerReveDeDragon ( roll , force ) {
2020-11-16 04:32:42 +01:00
let message = "" ;
if ( roll . isSuccess ) {
message += "<br>Vous gagnez " + force + " points de Rêve" ;
this . updatePointDeSeuil ( ) ;
2020-11-17 11:35:05 +01:00
this . updatePointsDeReve ( force ) ;
2020-11-16 04:32:42 +01:00
}
if ( roll . isPart ) {
// TODO: Dialog pour choix entre HR opu général?
let tete = "à déterminer" ;
message += "<br>Vous gagnez une Tête de dragon: " + tete ;
}
if ( roll . isEchec ) {
message += "<br>Vous subissez une Queue de Dragon" ;
this . ajouterQueue ( ) ;
}
if ( roll . isETotal ) {
message += "<br>A cause de votre échec total, vous subissez une deuxième Queue de Dragon !"
this . ajouterQueue ( ) ;
}
return message ;
}
2020-11-15 11:15:36 +01:00
/* -------------------------------------------- */
2020-11-14 03:16:03 +01:00
async sortMisEnReserve ( rollData , sort ) {
let reserve = duplicate ( this . data . data . reve . reserve ) ;
reserve . list . push ( { coord : rollData . coord , sort : sort , draconic : duplicate ( rollData . selectedDraconic ) } ) ;
await this . update ( { "data.reve.reserve" : reserve } ) ;
this . currentTMR . updateSortReserve ( ) ;
}
2020-05-24 20:19:57 +02:00
/* -------------------------------------------- */
updateCarac ( caracName , caracValue )
{
2020-06-07 23:16:29 +02:00
let caracpath = "data.carac." + caracName + ".value"
2020-11-16 04:32:42 +01:00
if ( caracName == reve ) {
if ( caracValue > Misc . toInt ( this . data . data . reve . seuil . value ) ) {
this . setPointDeSeuil ( caracValue ) ;
}
}
2020-06-07 23:16:29 +02:00
this . update ( { caracpath : caracValue } ) ;
2020-05-24 20:19:57 +02:00
}
2020-05-28 23:36:09 +02:00
2020-09-20 17:38:21 +02:00
/* -------------------------------------------- */
async updateCreatureCompetence ( compName , fieldName , compValue )
{
let comp = RdDUtility . findCompetence ( this . data . items , compName ) ;
2020-09-20 19:17:31 +02:00
console . log ( comp ) ;
2020-09-20 17:38:21 +02:00
if ( comp ) {
const update = { _id : comp . _id }
if ( fieldName == "niveau" )
2020-09-20 19:17:31 +02:00
update [ 'data.niveau' ] = compValue ;
2020-09-20 17:38:21 +02:00
else if ( fieldName == "dommages" )
2020-09-20 19:17:31 +02:00
update [ 'data.dommages' ] = compValue ;
2020-09-20 17:38:21 +02:00
else
2020-09-20 19:17:31 +02:00
update [ 'data.carac_value' ] = compValue ;
console . log ( update ) ;
2020-09-20 17:38:21 +02:00
const updated = await this . updateEmbeddedEntity ( "OwnedItem" , update ) ; // Updates one EmbeddedEntity
}
}
2020-06-01 23:50:10 +02:00
/* -------------------------------------------- */
async updateCompetence ( compName , compValue )
{
let comp = RdDUtility . findCompetence ( this . data . items , compName ) ;
if ( comp ) {
2020-08-13 22:28:56 +02:00
let troncList = RdDUtility . isTronc ( compName ) ;
let maxNiveau = compValue ;
if ( troncList ) {
2020-09-05 22:56:33 +02:00
let message = "Vous avez modifié une compétence 'tronc'. Vérifiez que les compétences suivantes évoluent ensemble jusqu'au niveau 0 : " ;
2020-08-13 22:28:56 +02:00
for ( let troncName of troncList ) {
2020-09-05 22:56:33 +02:00
message += "<br>" + troncName ;
2020-08-13 22:28:56 +02:00
}
2020-11-16 04:01:36 +01:00
ChatMessage . create ( { title : "Compétence Tronc" ,
2020-09-05 22:56:33 +02:00
content : message } ) ;
2020-08-13 22:28:56 +02:00
}
const update = { _id : comp . _id , 'data.niveau' : maxNiveau } ;
2020-06-01 23:50:10 +02:00
const updated = await this . updateEmbeddedEntity ( "OwnedItem" , update ) ; // Updates one EmbeddedEntity
2020-06-12 22:46:04 +02:00
} else {
console . log ( "Competence not found" , compName ) ;
}
}
/* -------------------------------------------- */
async updateCompetenceXP ( compName , compValue )
{
let comp = RdDUtility . findCompetence ( this . data . items , compName ) ;
if ( comp ) {
const update = { _id : comp . _id , 'data.xp' : compValue } ;
const updated = await this . updateEmbeddedEntity ( "OwnedItem" , update ) ; // Updates one EmbeddedEntity
2020-06-01 23:50:10 +02:00
} else {
console . log ( "Competence not found" , compName ) ;
}
}
2020-08-29 22:52:41 +02:00
/* -------------------------------------------- */
async updateCompteurValue ( fieldName , fieldValue )
{
//console.log("Update", fieldName, fieldValue);
let content ;
let compteurs = duplicate ( this . data . data . compteurs ) ;
compteurs [ fieldName ] . value = fieldValue ;
await this . update ( { "data.compteurs" : compteurs } ) ;
}
2020-11-12 14:43:08 +01:00
/* -------------------------------------------- */
2020-11-15 09:35:05 +01:00
/ * * T e s t e s i l e c o n t e n e u r d e d e s t i n a t i o n a s u f f i s a m e n t d e c a p a c i t é
* pour recevoir le nouvel objet
* /
testConteneurCapacite ( itemId , conteneurId ) {
if ( ! conteneurId ) return true ; // pas de conteneur (porté sur soi), donc toujours OK.
let conteneur = this . items . find ( conteneur => conteneurId == conteneur . _id ) ; // recup conteneur
//console.log("Conteneur trouvé : ", conteneur);
if ( conteneur && conteneur . type == "conteneur" ) {
let currentEnc = 0 ; // Calculer le total actuel des contenus
for ( let id of conteneur . data . data . contenu ) {
let objet = this . items . find ( objet => ( id == objet . _id ) ) ;
currentEnc += ( objet ) ? objet . data . data . encombrement : 0 ;
}
// Et gérer le nouvel objet
let nouvelObjet = this . items . find ( objet => ( itemId == objet . _id ) ) ;
if ( currentEnc + nouvelObjet . data . data . encombrement > Number ( conteneur . data . data . capacite ) )
return false ;
}
return true ;
}
/* -------------------------------------------- */
2020-11-12 14:43:08 +01:00
/ * * S u p p r i m e u n i t e m d ' u n c o n t e n e u r , s u r l a b a s e
* de leurs ID * /
async enleverDeConteneur ( itemId , conteneurId ) {
if ( ! conteneurId ) return ; // pas de conteneur (porté sur soi)
let conteneur = this . items . find ( conteneur => conteneurId == conteneur . _id ) ; // recup conteneur
if ( conteneur ) { // Si présent
//console.log("Suppression du conteneur1", conteneurId, itemId, conteneur.data.data.contenu);
2020-11-14 20:18:06 +01:00
let contenu = conteneur . data . data . contenu ;
contenu . splice ( contenu . indexOf ( 'itemId' ) , 1 ) ;
//let newContenu = conteneur.data.data.contenu.filter( function(value, index, arr) { return value != itemId } );
2020-11-12 14:43:08 +01:00
//console.log("Suppression du conteneur2", conteneurId, itemId, newContenu);
2020-11-14 20:18:06 +01:00
//let update = {_id: conteneurId, "data.contenu": newContenu };
await this . updateEmbeddedEntity ( "OwnedItem" , conteneur . data ) ;
2020-11-12 14:43:08 +01:00
}
}
/* -------------------------------------------- */
/ * * A j o u t e u n i t e m d a n s u n c o n t e n e u r , s u r l a b a s e
* de leurs ID * /
async ajouterAConteneur ( itemId , conteneurId ) {
if ( ! conteneurId ) return ; // pas de conteneur (porté sur soi)
let conteneur = this . items . find ( conteneur => conteneurId == conteneur . _id ) ;
if ( conteneur && conteneur . type == 'conteneur' ) {
conteneur . data . data . contenu . push ( itemId ) ;
await this . updateEmbeddedEntity ( "OwnedItem" , conteneur . data ) ;
}
}
2020-11-11 14:42:11 +01:00
/* -------------------------------------------- */
detectSurEncombrement ( ) {
let diffEnc = Number ( this . encombrementTotal ) - Number ( this . data . data . attributs . encombrement . value ) ;
if ( diffEnc > 0 ) { // Sur-encombrement
let malus = Math . round ( diffEnc ) ;
malus = ( malus == 0 ) ? 1 : malus ; // Always 1 at least
2020-11-12 14:43:08 +01:00
//console.log("Sur enc malus", malus);
2020-11-11 14:42:11 +01:00
return malus ;
}
return 0 ;
}
2020-11-11 11:43:13 +01:00
/* -------------------------------------------- */
computeEncombrementTotal ( ) {
let totalEnc = 0 ;
for ( const item of this . data . items ) {
if ( item . data && item . data . encombrement ) { // Enc value filtering
2020-11-18 08:13:48 +01:00
totalEnc += Number ( item . data . encombrement ) * Number ( ( ( item . data . quantite ) ? item . data . quantite : 1 ) ) ;
2020-11-11 11:43:13 +01:00
}
}
2020-11-11 14:42:11 +01:00
this . encombrementTotal = totalEnc ;
this . detectSurEncombrement ( ) ;
2020-11-11 11:43:13 +01:00
}
2020-05-29 00:43:16 +02:00
/* -------------------------------------------- */
computeEtatGeneral ( )
{
let data = this . data . data ;
2020-11-15 11:15:36 +01:00
// Pas d'état général pour les entités forçage à 0
if ( this . data . type == 'entite' ) {
data . compteurs . etat . value = 0 ;
return ;
}
// Pour les autres
2020-05-29 00:43:16 +02:00
let state = 0 ;
state = state - ( data . sante . vie . max - data . sante . vie . value ) ;
2020-09-20 21:52:46 +02:00
if ( data . sante . fatigue ) // Creatures n'ont pas de fatigue
state = state + RdDUtility . currentFatigueMalus ( data . sante . fatigue . value , data . sante . endurance . max ) ;
2020-11-11 14:42:11 +01:00
state = state - this . detectSurEncombrement ( ) ;
2020-05-29 00:43:16 +02:00
data . compteurs . etat . value = state ;
}
2020-07-17 22:04:35 +02:00
/* -------------------------------------------- */
async ajouterRefoulement ( value = 1 ) {
let ret = "none" ;
let refoulement = duplicate ( this . data . data . reve . refoulement ) ;
refoulement . value = refoulement . value + value ;
2020-11-14 03:16:03 +01:00
2020-07-25 10:29:28 +02:00
let total = new Roll ( "d20" ) . roll ( ) . total ;
if ( total <= refoulement . value ) {
2020-07-17 22:04:35 +02:00
refoulement . value = 0 ;
2020-11-16 04:32:42 +01:00
this . ajouterSouffle ( ) ;
2020-07-17 22:04:35 +02:00
ret = "souffle" ;
}
2020-11-14 03:16:03 +01:00
2020-07-17 22:04:35 +02:00
await this . update ( { "data.reve.refoulement" : refoulement } ) ;
return ret ;
}
2020-11-16 04:32:42 +01:00
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-16 04:32:42 +01:00
ajouterSouffle ( ) {
let souffle = RdDRollTables . getSouffle ( ) ;
// ChatMessage.create({
// title: "Souffle de Dragon",
// content: this.name + " subit un Souffle de Dragon : " + souffle.name
// });
// this.actor.createOwnedItem(souffle);
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-16 04:32:42 +01:00
async ajouterQueue ( ) {
// TODO: Déterminer si Thanatos a été utilisé? => laisser le joueur ne pas choisir Thanatos => choisir sa voie?
let utiliseThanatos = false ;
let queue ;
if ( utiliseThanatos ) {
queue = await RdDRollTables . getOmbre ( ) ;
// mettre à jour: plus d'ombre en vue
}
else {
queue = await RdDRollTables . getQueue ( ) ;
}
/ *
// TODO: convertir la queue obtenue en nouvel item ...
// ou bien l'ajouter à la liste spécifique => this.data.data.reve.queues
this . createOwnedItem ( queue ) ;
ChatMessage . create ( {
title : "Queue de Dragon" ,
content : this . name + " subit un Queue de Dragon : " + queue . name
} ) ;
return queue . name ;
* /
}
2020-07-21 23:51:24 +02:00
/* -------------------------------------------- */
async deleteTMRRencontreAtPosition ( ) {
let rencontres = duplicate ( this . data . data . reve . rencontre ) ;
let len = rencontres . list . length ;
let i = 0 ;
//console.log("List", rencontres, len);
let newTable = [ ] ;
for ( i = 0 ; i < len ; i ++ ) {
if ( rencontres . list [ i ] . coord != this . data . data . reve . tmrpos . coord )
newTable . push ( rencontres . list [ i ] ) ;
}
if ( newTable . length != len ) {
rencontres . list = newTable ;
//console.log("Result: ", rencontres);
await this . update ( { "data.reve.rencontre" : rencontres } ) ;
}
}
/* -------------------------------------------- */
async addTMRRencontre ( currentRencontre ) {
let rencontres = duplicate ( this . data . data . reve . rencontre ) ;
let len = rencontres . list . length ;
let i = 0 ;
let already = false ;
for ( i = 0 ; i < len ; i ++ ) {
if ( rencontres . list [ i ] . coord == this . data . data . reve . tmrpos . coord )
already = true ;
}
if ( ! already ) {
rencontres . list . push ( { coord : this . data . data . reve . tmrpos . coord , rencontre : currentRencontre } ) ;
await this . update ( { "data.reve.rencontre" : rencontres } ) ;
}
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
async updateCoordTMR ( coord ) {
let tmrPos = duplicate ( this . data . data . reve . tmrpos ) ;
tmrPos . coord = coord ;
await this . update ( { "data.reve.tmrpos" : tmrPos } ) ;
}
2020-07-21 23:51:24 +02:00
2020-07-17 22:04:35 +02:00
/* -------------------------------------------- */
async updatePointsDeReve ( value ) {
let reve = duplicate ( this . data . data . reve . reve ) ;
2020-11-14 03:16:03 +01:00
reve . value = Math . max ( reve . value + value , 0 ) ;
2020-07-17 22:04:35 +02:00
await this . update ( { "data.reve.reve" : reve } ) ;
}
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-16 03:52:34 +01:00
async updatePointDeSeuil ( value = 1 ) {
const seuil = Misc . toInt ( this . data . data . reve . seuil . value ) ;
const reve = Misc . toInt ( this . data . data . carac . reve . value ) ;
if ( seuil < reve ) {
await this . setPointsDeSeuil ( Math . min ( seuil + value , reve ) ) ;
}
}
2020-07-17 22:04:35 +02:00
2020-11-17 16:30:03 +01:00
/* -------------------------------------------- */
2020-11-16 03:52:34 +01:00
async setPointsDeSeuil ( value ) {
let seuil = duplicate ( this . data . data . reve . seuil ) ;
seuil . value = value ;
await this . update ( { "data.reve.seuil" : seuil } ) ;
}
2020-05-31 23:06:25 +02:00
/* -------------------------------------------- */
2020-06-07 23:16:29 +02:00
testSiSonne ( sante , endurance )
2020-05-31 23:06:25 +02:00
{
2020-07-25 10:29:28 +02:00
let result = new Roll ( "d20" ) . roll ( ) . total ;
2020-05-31 23:06:25 +02:00
if ( result <= endurance . value )
2020-06-07 23:16:29 +02:00
sante . sonne . value = false ;
2020-05-31 23:06:25 +02:00
if ( result > endurance . value || result == 20 ) // 20 is always a failure
2020-06-07 23:16:29 +02:00
sante . sonne . value = true ;
2020-05-31 23:06:25 +02:00
if ( result == 1 ) {
2020-06-07 23:16:29 +02:00
sante . sonne . value = false ;
2020-11-16 04:01:36 +01:00
let xp = Misc . toInt ( this . data . data . carac . constitution . xp ) + 1 ;
2020-06-07 23:16:29 +02:00
this . update ( { "data.carac.constitution.xp" : xp } ) ; // +1 XP !
// TODO : Output to chat
2020-05-31 23:06:25 +02:00
}
}
2020-07-27 16:27:41 +02:00
/* -------------------------------------------- */
GetNumberBlessures ( blessuresListe )
{
let nbB = 0 ;
for ( let b of blessuresListe ) {
nbB += ( b . active ) ? 1 : 0 ;
}
return nbB ;
}
2020-08-29 22:52:41 +02:00
2020-05-28 23:36:09 +02:00
/* -------------------------------------------- */
2020-06-07 23:16:29 +02:00
async santeIncDec ( name , inc ) {
const sante = duplicate ( this . data . data . sante ) ;
let data = sante [ name ] ;
2020-05-31 23:06:25 +02:00
let lastValue = data . value ; // Useful for Endurance and Sonné
2020-05-28 23:36:09 +02:00
data . value = data . value + inc ;
if ( data . value > data . max ) data . value = data . max ;
if ( data . value < 0 ) data . value = 0 ;
2020-05-31 23:06:25 +02:00
2020-11-15 11:15:36 +01:00
if ( name == "endurance" && this . data . type != 'entite' ) {
2020-11-17 11:35:05 +01:00
if ( sante . fatigue && inc < 0 ) { // Each endurance lost -> fatigue lost
2020-06-07 23:16:29 +02:00
sante . fatigue . value = sante . fatigue . value - inc
2020-11-17 11:35:05 +01:00
}
2020-05-31 23:06:25 +02:00
// If endurance is 0 -> -1 vie
2020-06-12 11:47:41 +02:00
if ( data . value == 0 && sante . vie . value > 0 ) {
2020-06-07 23:16:29 +02:00
sante . vie . value = sante . vie . value - 1 ;
2020-05-31 23:06:25 +02:00
}
2020-06-07 23:16:29 +02:00
let diffVie = sante . vie . max - sante . vie . value ;
2020-06-01 23:50:10 +02:00
if ( data . value > data . max - ( diffVie * 2 ) ) {
data . value = data . max - ( diffVie * 2 ) ;
2020-05-31 23:06:25 +02:00
}
2020-06-12 11:47:41 +02:00
if ( data . value < 0 ) data . value = 0 ; // Security
2020-05-31 23:06:25 +02:00
2020-07-27 16:27:41 +02:00
let blessures = this . data . data . blessures ;
let nbGraves = this . GetNumberBlessures ( blessures . graves . liste ) ;
let nbCritiques = this . GetNumberBlessures ( blessures . critiques . liste ) ;
2020-11-17 11:36:53 +01:00
let maxEnd = Math . floor ( data . max / ( 2 * nbGraves ) ) ;
2020-05-31 23:06:25 +02:00
if ( data . value > maxEnd ) data . value = maxEnd ;
2020-07-27 16:27:41 +02:00
if ( nbCritiques > 0 && data . value > 1 ) data . value = 1 ;
2020-05-31 23:06:25 +02:00
2020-06-07 23:16:29 +02:00
if ( lastValue - data . value > 1 ) this . testSiSonne ( sante , data ) ; // Peut-être sonné si 2 points d'endurance perdus d'un coup
2020-05-31 23:06:25 +02:00
}
2020-07-25 10:29:28 +02:00
//console.log(name, inc, data.value);
2020-06-01 23:50:10 +02:00
2020-06-07 23:16:29 +02:00
let diffEndurance = sante . endurance . max - this . data . data . sante . endurance . value ;
2020-09-20 21:14:05 +02:00
if ( sante . fatigue && sante . fatigue . value < diffEndurance ) // If endurance lost, then the same amount of fatigue cannot be recovered
2020-06-07 23:16:29 +02:00
sante . fatigue . value = diffEndurance ;
2020-07-25 10:29:28 +02:00
//console.log("SANTE::::", sante);
2020-06-07 23:16:29 +02:00
await this . update ( { "data.sante" : sante } ) ;
}
2020-08-29 22:52:41 +02:00
2020-07-20 12:02:07 +02:00
/* -------------------------------------------- */
2020-07-27 16:27:41 +02:00
async manageBlessureFromSheet ( bType , index , active ) {
let bList = duplicate ( this . data . data . blessures ) ;
let blessure = bList [ bType + "s" ] . liste [ index ] ;
2020-07-20 12:02:07 +02:00
blessure . active = ! blessure . active ;
2020-07-27 16:27:41 +02:00
if ( ! blessure . active ) {
blessure . premiers _soins = 0 ;
blessure . soins _complets = 0 ;
blessure . jours = 0 ;
blessure . localisation = "" ;
}
//console.log("Blessure update", bType, index, blessure, bList );
await this . update ( { 'data.blessures' : bList } ) ;
2020-07-20 12:02:07 +02:00
}
2020-07-27 16:27:41 +02:00
/* -------------------------------------------- */
async setDataBlessureFromSheet ( bType , index , psoins , pcomplets , jours , loc ) {
let bList = duplicate ( this . data . data . blessures ) ;
let blessure = bList [ bType + "s" ] . liste [ index ] ;
blessure . premiers _soins = psoins ;
blessure . soins _complets = pcomplets ;
blessure . jours = jours ;
blessure . localisation = loc ;
await this . update ( { 'data.blessures' : bList } ) ;
}
2020-06-07 23:16:29 +02:00
/* -------------------------------------------- */
manageBlessures ( blessuresData )
{
2020-11-07 21:06:37 +01:00
// Fast exit
2020-11-15 11:15:36 +01:00
if ( this . data . type == 'entite' ) return ; // Une entité n'a pas de blessures
2020-11-07 21:06:37 +01:00
if ( blessuresData . legeres + blessuresData . graves + blessuresData . critiques == 0 ) return ;
2020-11-15 11:15:36 +01:00
let workData = duplicate ( blessuresData ) ;
2020-11-07 21:06:37 +01:00
let blessures = duplicate ( this . data . data . blessures ) ;
// Manage blessures
if ( workData . legeres > 0 ) {
for ( let k = 0 ; k < blessures . legeres . liste . length ; k ++ ) {
let bless = blessures . legeres . liste [ k ] ;
if ( ! bless . active ) {
bless . active = true ;
bless . loc = workData . locName ;
workData . legeres -- ;
2020-06-22 10:18:03 +02:00
}
2020-11-07 21:06:37 +01:00
if ( workData . legeres == 0 ) break ;
2020-06-22 10:18:03 +02:00
}
2020-11-07 21:06:37 +01:00
}
if ( workData . legeres > 0 ) {
workData . graves += 1 ;
blessuresData . graves += 1 ;
}
2020-06-22 10:18:03 +02:00
2020-11-07 21:06:37 +01:00
if ( workData . graves > 0 ) {
for ( let k = 0 ; k < blessures . graves . liste . length ; k ++ ) {
let bless = blessures . graves . liste [ k ] ;
if ( ! bless . active ) {
bless . active = true ;
bless . loc = workData . locName ;
workData . graves -- ;
2020-06-22 10:18:03 +02:00
}
2020-11-07 21:06:37 +01:00
if ( workData . graves == 0 ) break ;
2020-06-22 10:18:03 +02:00
}
2020-11-07 21:06:37 +01:00
}
2020-06-22 10:18:03 +02:00
2020-11-07 21:06:37 +01:00
if ( workData . graves > 0 ) {
workData . critiques = 1 ;
blessuresData . critiques = 1 ;
}
2020-06-22 10:18:03 +02:00
2020-11-07 21:06:37 +01:00
if ( workData . critiques > 0 ) {
workData . endurance = this . data . data . sante . endurance . value ; // Patch with real endurance current value (ie end -> 0 when critique)
blessures . critiques . liste [ 0 ] . active = true ;
blessures . critiques . liste [ 0 ] . loc = workData . locName ;
2020-06-22 10:18:03 +02:00
}
2020-11-07 21:06:37 +01:00
this . update ( { "data.blessures" : blessures } ) ;
2020-05-28 23:36:09 +02:00
}
2020-08-29 22:52:41 +02:00
2020-11-12 16:35:51 +01:00
/* -------------------------------------------- */
async stressTest ( ) {
2020-11-17 11:35:05 +01:00
let stressRoll = this . _stressRoll ( ) ;
2020-11-12 16:35:51 +01:00
let compteurs = duplicate ( this . data . data . compteurs ) ;
let convertion = Math . floor ( compteurs . stress . value * stressRoll . factor ) ;
compteurs . experience . value += convertion ;
compteurs . stress . value = Math . max ( compteurs . stress . value - convertion - 1 , 0 ) ;
ChatMessage . create ( {
2020-11-17 11:35:05 +01:00
title : "Jet de Stress" , content : "Vous avez transformé " + convertion + " points de Stress en Expérience" + stressRoll . comment ,
2020-11-12 16:35:51 +01:00
whisper : ChatMessage . getWhisperRecipients ( game . user . name )
} ) ;
await this . update ( { "data.compteurs" : compteurs } ) ;
2020-08-29 22:52:41 +02:00
}
2020-11-14 21:34:34 +01:00
/* -------------------------------------------- */
2020-11-17 16:30:03 +01:00
_stressRoll ( ) {
let result = RdDResolutionTable . roll ( this . data . data . carac . reve . value , 0 ) ;
console . log ( "_stressRoll" , result ) ;
switch ( result . code ) {
case "sign" : return { factor : 0.75 , comment : " (75%): " + result . quality + " - " + result . roll + " sur " + result . score + "%" }
case "norm" : return { factor : 0.5 , comment : " (50%): " + result . quality + " - " + result . roll + " sur " + result . score + "%" }
case "echec" : return { factor : 0.2 , comment : " (20%): " + result . quality + " - " + result . roll + " sur " + result . score + "%" }
case "epart" : return { factor : 0.1 , comment : " (10%): " + result . quality + " - " + result . roll + " sur " + result . score + "%" }
case "etotal" : return { factor : 0 , comment : " (0%): " + result . quality + " - " + result . roll + " sur " + result . score + "%" }
case "part" :
{
let second = RdDResolutionTable . roll ( this . data . data . carac . reve . value , 0 ) ;
console . log ( "_stressRoll" , second ) ;
switch ( second . code ) {
case "part" : case "sign" :
return { factor : 1.5 , comment : " (150%): Double Particulière - " + result . roll + " puis " + second . roll + " sur " + result . score + "%" }
default :
return { factor : 1 , comment : " (150%): " + result . quality + " - " + result . roll + " puis " + second . roll + " sur " + result . score + "%" }
}
2020-11-17 11:35:05 +01:00
}
2020-11-17 16:30:03 +01:00
}
2020-11-12 16:35:51 +01:00
}
2020-11-17 11:35:05 +01:00
2020-11-12 16:35:51 +01:00
/* -------------------------------------------- */
async rollUnSort ( coord ) {
2020-07-23 22:09:40 +02:00
let draconicList = this . getDraconicList ( ) ;
2020-11-13 11:24:56 +01:00
let sortList = duplicate ( this . getSortList ( ) ) ; // Duplication car les pts de reve sont modifiés dans le sort
2020-07-23 22:09:40 +02:00
let rollData = {
2020-07-26 17:26:17 +02:00
selectedCarac : this . data . data . carac . reve ,
etat : this . data . data . compteurs . etat . value ,
draconicList : draconicList ,
sortList : sortList ,
2020-11-14 03:16:03 +01:00
selectedDraconic : this . getBestDraconic ( ) ,
2020-07-26 17:26:17 +02:00
selectedSort : sortList [ 0 ] ,
coord : coord ,
finalLevel : 0 ,
2020-11-15 02:07:41 +01:00
diffConditions : 0 ,
diffLibre : sortList [ 0 ] . data . difficulte , // Per default at startup
2020-11-13 11:24:56 +01:00
coutreve : Array ( 20 ) . fill ( ) . map ( ( item , index ) => 1 + index ) ,
2020-11-15 02:07:41 +01:00
ajustementsConditions : CONFIG . RDD . ajustementsConditions ,
difficultesLibres : CONFIG . RDD . difficultesLibres
2020-07-23 22:09:40 +02:00
}
let html = await renderTemplate ( 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-sort.html' , rollData ) ;
new RdDRollDialog ( "sort" , html , rollData , this ) . render ( true ) ;
}
2020-06-12 22:46:04 +02:00
/* -------------------------------------------- */
async rollCarac ( caracName )
{
2020-11-15 12:26:19 +01:00
let carac ;
if ( caracName == "reveActuel" ) { // Fake carac for Reve Actuel
carac = { type : "number" ,
2020-11-16 04:01:36 +01:00
value : this . getReveActuel ( ) ,
2020-11-15 12:26:19 +01:00
label : "Rêve Actuel"
}
} else {
carac = this . data . data . carac [ caracName ] ; // Per default
}
2020-06-12 22:46:04 +02:00
let rollData = {
2020-11-15 12:26:19 +01:00
selectedCarac : carac ,
2020-11-15 02:07:41 +01:00
ajustementsConditions : CONFIG . RDD . ajustementsConditions ,
difficultesLibres : CONFIG . RDD . difficultesLibres ,
2020-11-13 11:24:56 +01:00
etat : this . data . data . compteurs . etat . value ,
finalLevel : 0 ,
2020-11-15 02:07:41 +01:00
diffConditions : 0 ,
diffLibre : 0
2020-06-12 22:46:04 +02:00
}
2020-11-15 02:07:41 +01:00
console . log ( caracName , rollData ) ;
let html = await renderTemplate ( 'systems/foundryvtt-reve-de-dragon/templates/dialog-roll-carac.html' , rollData ) ;
new RdDRollDialog ( "carac" , html , rollData , this ) . render ( true ) ;
}
/* -------------------------------------------- */
getSortList ( ) {
return this . data . items . filter ( item => item . type == "sort" ) ;
}
/* -------------------------------------------- */
getDraconicList ( ) {
return this . data . items . filter ( item => item . data . categorie == 'draconic' )
2020-11-14 20:46:39 +01:00
}
2020-07-21 23:55:24 +02:00
2020-11-15 02:07:41 +01:00
/* -------------------------------------------- */
async displayTMR ( mode = "normal" )
{
let isRapide = mode == "rapide"
if ( mode != "visu" )
{
let minReveValue = ( isRapide ) ? 3 : 2 ;
2020-11-16 04:01:36 +01:00
if ( this . getReveActuel ( ) < minReveValue ) {
2020-11-15 02:07:41 +01:00
ChatMessage . create ( { title : "Montée impossible !" , content : "Vous n'avez plus assez de Points de Reve pour monter dans les Terres Médianes" ,
whisper : ChatMessage . getWhisperRecipients ( game . user . name ) } ) ;
return ;
}
}
let data = {
2020-07-17 22:04:35 +02:00
fatigueHTML : "<table class='table-fatigue'>" + RdDUtility . makeHTMLfatigueMatrix ( this . data . data . sante . fatigue . value , this . data . data . sante . endurance . max ) . html ( ) + "</table>" ,
2020-07-21 23:51:24 +02:00
draconic : this . getDraconicList ( ) ,
2020-07-17 22:04:35 +02:00
sort : this . getSortList ( ) ,
2020-07-22 00:12:13 +02:00
caracReve : this . data . data . carac . reve . value ,
2020-11-16 04:01:36 +01:00
pointsReve : this . getReveActuel ( ) ,
2020-07-25 10:29:28 +02:00
isRapide : isRapide
2020-07-17 22:04:35 +02:00
}
2020-11-15 02:07:41 +01:00
let html = await renderTemplate ( 'systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html' , data ) ;
this . currentTMR = new RdDTMRDialog ( html , this , data , mode == "visu" ) ;
this . currentTMR . render ( true ) ;
}
/* -------------------------------------------- */
rollArme ( armeName )
{
let armeItem = this . data . items . find ( item => item . type === "arme" && ( item . name === armeName ) ) ;
if ( armeItem && armeItem . data . competence )
2020-06-10 08:23:58 +02:00
this . rollCompetence ( armeItem . data . competence , armeItem ) ;
2020-11-15 02:07:41 +01:00
else
2020-06-10 08:23:58 +02:00
this . rollCompetence ( armeName ) ; //Bypass mode!
2020-09-20 19:17:31 +02:00
}
2020-11-15 02:07:41 +01:00
2020-11-15 11:15:36 +01:00
/* -------------------------------------------- */
async rollCompetence ( name , armeItem = undefined , attackerRoll = undefined ) {
let competence = RdDUtility . findCompetence ( this . data . items , name ) ;
console . log ( "rollCompetence !!!" , competence , armeItem , attackerRoll ) ;
// Common rollData values
let rollData = {
ajustementsConditions : CONFIG . RDD . ajustementsConditions ,
difficultesLibres : CONFIG . RDD . difficultesLibres ,
etat : this . data . data . compteurs . etat . value ,
diffConditions : 0 ,
diffLibre : ( attackerRoll ) ? attackerRoll . diffLibre : 0 ,
attackerRoll : attackerRoll ,
finalLevel : 0 ,
coupsNonMortels : false
}
2020-11-15 02:07:41 +01:00
2020-11-15 11:15:36 +01:00
if ( competence . type == 'competencecreature' ) { // Specific case for Creatures
2020-11-14 03:16:03 +01:00
if ( competence . data . iscombat ) {
armeItem = { name : name , data : { dommages : competence . data . dommages } } ;
2020-05-24 20:19:57 +02:00
}
2020-11-14 03:16:03 +01:00
competence . data . defaut _carac = "carac_creature" ; // Fake default competence
competence . data . categorie = "creature" ; // Fake default competence
rollData . competence = competence ;
2020-11-12 23:50:37 +01:00
rollData . arme = armeItem ;
2020-11-14 03:16:03 +01:00
rollData . carac = { carac _creature : { label : name , value : competence . data . carac _value } } ;
2020-11-12 23:50:37 +01:00
} else { // Usual competence
2020-11-14 03:16:03 +01:00
rollData . competence = competence ;
2020-11-12 23:50:37 +01:00
rollData . arme = armeItem ;
rollData . carac = this . data . data . carac ;
}
2020-06-03 21:35:18 +02:00
let html = await renderTemplate ( 'systems/foundryvtt-reve-de-dragon/templates/dialog-competence.html' , rollData ) ;
2020-11-14 03:16:03 +01:00
if ( rollData . arme ) {
2020-06-07 23:16:29 +02:00
new RdDRollDialog ( "arme" , html , rollData , this ) . render ( true ) ;
} else {
new RdDRollDialog ( "competence" , html , rollData , this ) . render ( true ) ;
}
2020-05-22 22:37:02 +02:00
}
2020-06-07 23:16:29 +02:00
2020-06-23 23:34:12 +02:00
/* -------------------------------------------- */
2020-11-11 10:38:27 +01:00
async equiperObjet ( itemID )
2020-06-23 23:34:12 +02:00
{
let item = this . getOwnedItem ( itemID ) ;
2020-06-24 00:22:40 +02:00
if ( item && item . data . data ) {
2020-11-11 10:38:27 +01:00
let update = { _id : item . _id , "data.equipe" : ! item . data . data . equipe } ;
await this . updateEmbeddedEntity ( "OwnedItem" , update ) ;
2020-11-11 11:43:13 +01:00
this . computeEncombrementTotal ( ) ; // Mise à jour encombrement
2020-06-24 00:22:40 +02:00
}
2020-06-23 23:34:12 +02:00
}
2020-06-07 23:16:29 +02:00
/* -------------------------------------------- */
2020-06-24 00:22:40 +02:00
computeArmure ( locData , domArmePlusDom )
2020-06-07 23:16:29 +02:00
{
2020-06-23 23:34:12 +02:00
let protection = 0 ;
for ( const item of this . data . items ) {
if ( item . type == "armure" && item . data . equipe ) {
2020-06-24 00:22:40 +02:00
let update = duplicate ( item ) ;
2020-08-29 22:52:41 +02:00
protection += new Roll ( update . data . protection . toString ( ) ) . roll ( ) . total ;
2020-06-24 00:22:40 +02:00
update . data . deterioration += domArmePlusDom ;
domArmePlusDom = 0 ; // Reset it
if ( update . data . deterioration >= 10 ) {
update . data . deterioration = 0 ;
if ( update . data . protection . toString ( ) . length == 1 )
update . data . protection = "d" + update . data . protection + "-0" ;
else {
let regex = /d\(d+)\-(\d+)/g ;
let res = regex . exec ( update . data . protection ) ;
update . data . protection = "d" + res [ 1 ] + "-" + ( parseInt ( res [ 2 ] ) + 1 ) ;
}
/* TODO - POST chat message */
}
this . updateEmbeddedEntity ( "OwnedItem" , update ) ;
2020-06-23 23:34:12 +02:00
}
}
console . log ( "Final protect" , protection ) ;
return protection ;
2020-06-07 23:16:29 +02:00
}
2020-11-11 04:21:25 +01:00
/* -------------------------------------------- */
encaisserDommages ( attackerRoll ) {
console . log ( "encaisserDommages" , attackerRoll )
const armure = this . computeArmure ( attackerRoll . loc , attackerRoll . domArmePlusDom ) ;
let degatsReel = attackerRoll . degats - armure ;
let result = RdDUtility . computeBlessuresSante ( degatsReel , attackerRoll . mortalite ) ;
2020-11-15 11:15:36 +01:00
if ( this . data . type != 'entite' ) // Pas de PV chez les entités
this . santeIncDec ( "vie" , result . vie ) ;
2020-06-22 10:18:03 +02:00
this . santeIncDec ( "endurance" , result . endurance ) ;
2020-11-16 23:32:22 +01:00
result . locName = ( attackerRoll . loc ) ? attackerRoll . loc . label : "Corps" ;
2020-11-11 04:21:25 +01:00
this . manageBlessures ( result ) ; // Will upate the result table
const blessureLegere = ( result . legeres > 0 ? "une blessure légère" : "" ) ;
const blessureGrave = ( result . graves > 0 ? "une blessure grave" : "" ) ;
const blessureCritique = ( result . critiques > 0 ? "une blessure critique" : "" ) ;
ChatMessage . create ( {
title : "Blessures !" , content : this . data . name + " a encaissé : " +
"<br>Encaissement final : " + degatsReel +
"<br>" + blessureLegere + blessureGrave + blessureCritique +
"<br>Et a perdu : " +
"<br>" + result . endurance + " Endurance et " + result . vie + " Points de Vie"
} ) ;
2020-06-07 23:16:29 +02:00
this . computeEtatGeneral ( ) ;
this . sheet . render ( true ) ;
}
2020-11-07 21:06:37 +01:00
2020-06-07 23:16:29 +02:00
2020-06-10 08:23:58 +02:00
/* -------------------------------------------- */
2020-06-11 00:29:32 +02:00
parerAttaque ( attackerRoll , armeId )
2020-06-10 08:23:58 +02:00
{
2020-06-11 00:29:32 +02:00
let armeItem = this . getOwnedItem ( armeId ) ; // Item.data.data !
2020-11-15 02:07:41 +01:00
console . log ( "Going to PARY !!!!!!!!!" , armeItem , attackerRoll . diffLibre ) ;
2020-06-11 00:29:32 +02:00
this . rollCompetence ( armeItem . data . data . competence , armeItem . data , attackerRoll ) ;
2020-06-10 08:23:58 +02:00
}
2020-07-27 18:58:10 +02:00
/* -------------------------------------------- */
esquiverAttaque ( attackerRoll )
{
this . rollCompetence ( "esquive" , undefined , attackerRoll ) ;
}
2020-05-24 20:19:57 +02:00
/* -------------------------------------------- */
2020-05-21 21:48:20 +02:00
/** @override */
getRollData ( ) {
const data = super . getRollData ( ) ;
return data ;
}
2020-11-14 03:16:03 +01:00
2020-05-21 21:48:20 +02:00
}
2020-11-14 03:16:03 +01:00