2021-01-05 18:43:13 +01:00
import { RdDItemArme } from "./item-arme.js" ;
import { RdDItemCompetence } from "./item-competence.js" ;
import { RdDItemMeditation } from "./item-meditation.js" ;
import { RdDItemSort } from "./item-sort.js" ;
import { Misc } from "./misc.js" ;
import { RdDBonus } from "./rdd-bonus.js" ;
import { RdDCarac } from "./rdd-carac.js" ;
2023-06-14 01:48:32 +02:00
import { RdDPossession } from "./rdd-possession.js" ;
2021-05-18 01:04:27 +02:00
import { RdDUtility } from "./rdd-utility.js" ;
2023-06-20 23:43:24 +02:00
import { ReglesOptionnelles } from "./settings/regles-optionnelles.js" ;
2021-01-05 18:43:13 +01:00
/ * *
* tous les ajustements pouvant s ' appliquer .
* un ajustement se compose de ` function(rollData, actor) ` :
* - isVisible : indique si l ' ajustement sera visible ( pour les cas où il peut être sélectionné )
* - isUsed : évalue si l 'ajustement indique s' il est actif ou non
* - getLabel : un libellé texte pour l 'affichage de l' ajustement
* - getValue : une valeur numérique correspondant à un modificateur entier
* - getDescr : une valeur textuelle pour les informations non numériques ( demi - surprise , bonus de case , ... )
* /
export const referenceAjustements = {
competence : {
2022-06-12 09:46:58 +02:00
isUsed : ( rollData , actor ) => rollData . competence ,
getLabel : ( rollData , actor ) => rollData . competence ? . name ,
getValue : ( rollData , actor ) => rollData . competence ? . system ? . niveau ,
2021-01-05 18:43:13 +01:00
} ,
meditation : {
isUsed : ( rollData , actor ) => rollData . meditation ,
getLabel : ( rollData , actor ) => 'Méditation' ,
getValue : ( rollData , actor ) => RdDItemMeditation . calculDifficulte ( rollData )
} ,
diffLibre : {
isUsed : ( rollData , actor ) => rollData . diffLibre != undefined ,
2023-06-14 01:48:32 +02:00
getLabel : ( rollData , actor ) => rollData . selectedSort ? . name ? ? rollData . attackerRoll ? ? RdDPossession . isDefensePossession ( rollData ) ? 'Imposée' : 'Libre' ,
2021-01-05 18:43:13 +01:00
getValue : ( rollData , actor ) => rollData . selectedSort
? RdDItemSort . getDifficulte ( rollData . selectedSort , rollData . diffLibre )
2022-09-07 09:01:23 +02:00
: rollData . diffLibre ? ? rollData . competence ? . system . default _diffLibre ? ? 0
2021-01-05 18:43:13 +01:00
} ,
diffConditions : {
isUsed : ( rollData , actor ) => rollData . diffConditions != undefined ,
getLabel : ( rollData , actor ) => 'Conditions' ,
getValue : ( rollData , actor ) => rollData . diffConditions
} ,
tactique : {
isUsed : ( rollData , actor ) => rollData . tactique ,
getLabel : ( rollData , actor ) => RdDBonus . find ( rollData . tactique ) . descr ,
getValue : ( rollData , actor ) => RdDBonus . find ( rollData . tactique ) . attaque ,
} ,
attaqueDefenseurSurpris : {
isUsed : ( rollData , actor ) => rollData . surpriseDefenseur ,
2021-01-13 04:01:39 +01:00
getLabel : ( rollData , actor ) => RdDBonus . find ( rollData . surpriseDefenseur ) . descr + ( rollData . attackerRoll ? '' : ' défenseur' ) ,
2021-01-05 18:43:13 +01:00
getValue : ( rollData , actor ) => RdDBonus . find ( rollData . surpriseDefenseur ) . attaque ,
} ,
etat : {
2023-06-05 20:18:05 +02:00
isUsed : ( rollData , actor ) => ! RollDataAjustements . isIgnoreEtatGeneral ( rollData ) ,
2021-01-05 18:43:13 +01:00
getLabel : ( rollData , actor ) => 'Etat général' ,
2021-05-18 01:04:27 +02:00
getValue : ( rollData , actor ) => actor . getEtatGeneral ( { ethylisme : rollData . forceAlcool != undefined } )
2021-01-05 18:43:13 +01:00
} ,
malusArmure : {
2023-01-13 01:48:00 +01:00
isVisible : ( rollData , actor ) => RdDCarac . isAgiliteOuDerobee ( rollData . selectedCarac ) ,
isUsed : ( rollData , actor ) => RdDCarac . isAgiliteOuDerobee ( rollData . selectedCarac ) ,
2021-01-05 18:43:13 +01:00
getLabel : ( rollData , actor ) => 'Malus armure' ,
getValue : ( rollData , actor ) => actor . getMalusArmure ( )
} ,
encTotal : {
2023-01-13 01:48:00 +01:00
isVisible : ( rollData , actor ) => RdDCarac . isAgiliteOuDerobee ( rollData . selectedCarac ) && RdDItemCompetence . isMalusEncombrementTotal ( rollData . competence ) ,
2023-12-08 02:37:47 +01:00
isUsed : ( rollData , actor ) => ! rollData . oeuvre && RdDCarac . isAgiliteOuDerobee ( rollData . selectedCarac ) && RdDItemCompetence . isMalusEncombrementTotal ( rollData . competence ) && rollData . use ? . encTotal ,
2021-01-05 18:43:13 +01:00
getLabel : ( rollData , actor ) => 'Encombrement total' ,
getValue : ( rollData , actor ) => - actor . getEncTotal ( )
} ,
surenc : {
2023-10-24 22:32:49 +02:00
isVisible : ( rollData , actor ) => RdDCarac . isActionPhysique ( rollData . selectedCarac ) && actor . isSurenc ( ) ,
2023-12-08 02:37:47 +01:00
isUsed : ( rollData , actor ) => rollData . use . surenc && RdDCarac . isActionPhysique ( rollData . selectedCarac ) ,
2021-01-05 18:43:13 +01:00
getLabel : ( rollData , actor ) => 'Sur-encombrement' ,
2021-12-05 21:18:00 +01:00
getValue : ( rollData , actor ) => actor . computeMalusSurEncombrement ( )
2021-01-05 18:43:13 +01:00
} ,
2023-12-08 22:26:29 +01:00
rituel : {
isUsed : ( rollData , actor ) => actor . isPersonnage ( ) && ReglesOptionnelles . isUsing ( "astrologie" ) && rollData . selectedSort ? . system . isrituel ,
getLabel : ( rollData , actor ) => 'Astrologique' ,
getValue : ( rollData , actor ) => actor . ajustementAstrologique ( )
} ,
astrologique : {
isVisible : ( rollData , actor ) => actor . isPersonnage ( ) && ReglesOptionnelles . isUsing ( "astrologie" ) && RdDCarac . isChance ( rollData . selectedCarac ) ,
isUsed : ( rollData , actor ) => RdDCarac . isChance ( rollData . selectedCarac ) && rollData . use . astrologique ,
getLabel : ( rollData , actor ) => 'Astrologique' ,
getValue : ( rollData , actor ) => actor . ajustementAstrologique ( )
} ,
2021-01-05 18:43:13 +01:00
moral : {
2022-11-26 03:13:45 +01:00
isVisible : ( rollData , actor ) => actor . isPersonnage ( ) && RdDCarac . isActionPhysique ( rollData . selectedCarac ) && rollData . use ? . moral ,
2023-12-08 02:37:47 +01:00
isUsed : ( rollData , actor ) => rollData . use . moral ,
2021-02-09 23:23:40 +01:00
getLabel : ( rollData , actor ) => 'Appel au moral' ,
2021-01-05 18:43:13 +01:00
getValue : ( rollData , actor ) => 1
} ,
2023-11-21 21:07:37 +01:00
coeur : {
isVisible : ( rollData , actor ) => actor . isPersonnage ( ) && RdDCarac . isVolonte ( rollData . selectedCarac ) ,
isUsed : ( rollData , actor ) => rollData . use . coeur != undefined ,
2023-11-27 23:45:33 +01:00
getLabel : ( rollData , actor ) => 'Ajustement de cœur' ,
2023-12-08 22:26:29 +01:00
getValue : ( rollData , actor ) => - 2 * ( rollData . use . coeur ? . coeur ? ? 0 )
2023-11-21 21:07:37 +01:00
} ,
2021-01-05 18:43:13 +01:00
moralTotal : {
isUsed : ( rollData , actor ) => RdDCarac . isVolonte ( rollData . selectedCarac ) ,
getLabel : ( rollData , actor ) => 'Moral' ,
getValue : ( rollData , actor ) => actor . getMoralTotal ( )
} ,
facteurSign : {
2021-01-13 03:42:13 +01:00
isUsed : ( rollData , actor ) => rollData . diviseurSignificative > 1 ,
getLabel : ( rollData , actor ) => Misc . getFractionHtml ( rollData . diviseurSignificative ) ,
getDescr : ( rollData , actor ) => rollData . diviseurSignificative > 1 ? ` Facteur significative <span class="rdd-diviseur">× ${ Misc . getFractionHtml ( rollData . diviseurSignificative ) } </span> ` : ''
2021-01-05 18:43:13 +01:00
} ,
2021-01-29 20:10:43 +01:00
isEcaille : {
2022-06-12 09:46:58 +02:00
isVisible : ( rollData , actor ) => rollData . arme ? . system . magique && Number ( rollData . arme ? . system . ecaille _efficacite ) > 0 ,
isUsed : ( rollData , actor ) => rollData . arme ? . system . magique && Number ( rollData . arme ? . system . ecaille _efficacite ) > 0 ,
2021-01-29 20:10:43 +01:00
getLabel : ( rollData , actor ) => "Ecaille d'Efficacité: " ,
2024-09-06 00:45:49 +02:00
getValue : ( rollData , actor ) => rollData . arme ? . system . magique ? Math . max ( Number ( rollData . arme ? . system . ecaille _efficacite ) , 0 ) : 0 ,
2021-01-29 20:10:43 +01:00
} ,
2021-01-05 18:43:13 +01:00
finesse : {
isUsed : ( rollData , actor ) => RdDBonus . isDefenseAttaqueFinesse ( rollData ) ,
getDescr : ( rollData , actor ) => 'Attaque particulière en finesse' ,
} ,
armeParade : {
isUsed : ( rollData , actor ) => RdDItemArme . needParadeSignificative ( rollData . attackerRoll ? . arme , rollData . arme ) ,
2021-01-13 04:01:39 +01:00
getDescr : ( rollData , actor ) => rollData . attackerRoll && rollData . arme ? ` ${ RdDItemArme . getNomCategorieParade ( rollData . attackerRoll ? . arme ) } vs ${ RdDItemArme . getNomCategorieParade ( rollData . arme ) } ` : ''
2021-01-05 18:43:13 +01:00
} ,
surprise : {
2021-01-13 03:42:13 +01:00
isUsed : ( rollData , actor ) => actor . getSurprise ( rollData . passeArme ) ,
2021-01-05 18:43:13 +01:00
getDescr : ( rollData , actor ) => RdDBonus . find ( actor . getSurprise ( ) ) . descr
} ,
bonusCase : {
2021-02-11 02:48:27 +01:00
isUsed : ( rollData , actor ) => rollData . selectedSort && rollData . tmr . coord ,
getDescr : ( rollData , actor ) => rollData . selectedSort && rollData . tmr . coord ? ` Bonus de case: ${ RdDItemSort . getCaseBonus ( rollData . selectedSort , rollData . tmr . coord ) } % ` : ''
2021-01-29 15:13:59 +01:00
} ,
rencontreTMR : {
2021-02-06 02:29:58 +01:00
isVisible : ( rollData , actor ) => rollData . tmr && rollData . rencontre ? . name ,
isUsed : ( rollData , actor ) => rollData . tmr && rollData . rencontre ? . name ,
2021-01-29 15:13:59 +01:00
getLabel : ( rollData , actor ) => rollData . rencontre ? . name ,
2022-11-07 00:04:43 +01:00
getValue : ( rollData , actor ) => - ( rollData . rencontre ? . system . force ? ? 0 )
2021-05-18 01:04:27 +02:00
} ,
ethylismeAlcool : {
isVisible : ( rollData , actor ) => rollData . nbDoses != undefined ,
isUsed : ( rollData , actor ) => rollData . nbDoses != undefined ,
getLabel : ( rollData , actor ) => "Doses déjà bues: " ,
getValue : ( rollData , actor ) => - rollData . nbDoses ,
} ,
ethylismeDoses : {
isVisible : ( rollData , actor ) => rollData . nbDoses != undefined ,
isUsed : ( rollData , actor ) => rollData . nbDoses != undefined ,
getLabel : ( rollData , actor ) => "Force de l'alcool: " ,
getValue : ( rollData , actor ) => rollData . forceAlcool ,
} ,
2023-12-08 02:37:47 +01:00
ethylisme : {
2021-05-18 01:04:27 +02:00
isVisible : ( rollData , actor ) => rollData . ethylisme != undefined ,
isUsed : ( rollData , actor ) => rollData . ethylisme != undefined ,
getLabel : ( rollData , actor ) => "Ethylisme - " + RdDUtility . getNomEthylisme ( rollData . ethylisme ) ,
getValue : ( rollData , actor ) => rollData . ethylisme ,
2023-04-21 18:18:20 +02:00
} ,
tailleempoignade : {
isVisible : ( rollData , actor ) => rollData . isEmpoignade ,
isUsed : ( rollData , actor ) => rollData . isEmpoignade ,
getLabel : ( rollData , actor ) => "Malus de taille" ,
getValue : ( rollData , actor ) => rollData . malusTaille ,
2021-01-05 18:43:13 +01:00
}
}
export class RollDataAjustements {
/* -------------------------------------------- */
static calcul ( rollData , actor ) {
2023-12-08 02:37:47 +01:00
// s'assurer de la correction des infos rollData
2024-05-01 09:13:21 +02:00
foundry . utils . mergeObject ( rollData , { ajustements : { } , use : { } } , { overwrite : false } )
2023-12-08 02:37:47 +01:00
2021-01-05 18:43:13 +01:00
for ( var key in referenceAjustements ) {
const reference = referenceAjustements [ key ] ;
rollData . ajustements [ key ] = {
2021-04-20 00:50:16 +02:00
visible : reference . isVisible && reference . isVisible ( rollData , actor ) ,
2021-01-05 18:43:13 +01:00
used : reference . isUsed ( rollData , actor ) ,
label : reference . getLabel && reference . getLabel ( rollData , actor ) ,
value : reference . getValue && reference . getValue ( rollData , actor ) ,
descr : reference . getDescr && reference . getDescr ( rollData , actor )
}
}
2023-07-11 02:34:05 +02:00
rollData . finalLevel = RollDataAjustements . sum ( rollData . ajustements )
2021-01-05 18:43:13 +01:00
}
/* -------------------------------------------- */
static sum ( ajustements ) {
let sum = 0 ;
for ( var key in ajustements ) {
if ( ajustements [ key ] . used && ! ajustements [ key ] . descr ) {
2021-10-28 02:06:57 +02:00
sum += parseInt ( ajustements [ key ] . value ) ;
2021-01-05 18:43:13 +01:00
}
}
return sum ;
}
2023-06-05 20:18:05 +02:00
static isIgnoreEtatGeneral ( rollData ) {
const selectedCarac = rollData . selectedCarac ;
return ! selectedCarac ||
rollData . ethylisme ||
RdDCarac . isChance ( selectedCarac ) ||
( RdDCarac . isReve ( selectedCarac ) && ! rollData . competence ) ;
}
2023-12-08 22:26:29 +01:00
2021-01-05 18:43:13 +01:00
}