2021-04-08 13:58:51 +02:00
/* -------------------------------------------- */
2021-04-01 21:18:36 +02:00
import { VadentisUtility } from "./vadentis-utility.js" ;
2021-04-08 13:58:51 +02:00
/* -------------------------------------------- */
const MIN _PV = - 50 ;
const MIN _PE = - 50 ;
2021-04-01 21:18:36 +02:00
/* -------------------------------------------- */
/ * *
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system .
* @ extends { Actor }
* /
export class VadentisActor extends Actor {
/* -------------------------------------------- */
/ * *
* Override the create ( ) function to provide additional SoS 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 .
*
* /
static async create ( data , options ) {
// Case of compendium global import
if ( data instanceof Array ) {
return super . create ( data , options ) ;
}
// If the created actor has items (only applicable to duplicated actors) bypass the new actor creation logic
2024-04-29 08:56:44 +02:00
if ( data . items ) {
2021-04-01 21:18:36 +02:00
let actor = super . create ( data , options ) ;
return actor ;
}
return super . create ( data , options ) ;
}
/* -------------------------------------------- */
async prepareData ( ) {
super . prepareData ( ) ;
2021-04-02 14:59:58 +02:00
}
/* -------------------------------------------- */
getCompetences ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'competence' ) || [ ] ) ;
2021-04-02 14:59:58 +02:00
}
2021-04-01 21:18:36 +02:00
2021-04-02 14:59:58 +02:00
/* -------------------------------------------- */
getDonnees ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'donnee' ) || [ ] ) ;
2021-04-01 21:18:36 +02:00
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
getEglises ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'eglise' ) || [ ] ) ;
2021-04-03 22:48:02 +02:00
}
2021-04-02 16:47:38 +02:00
/* -------------------------------------------- */
getSorts ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'sort' ) || [ ] ) ;
2021-04-02 16:47:38 +02:00
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
getAttributs ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'attribut' ) || [ ] ) ;
2021-04-03 22:48:02 +02:00
}
/* -------------------------------------------- */
getTechniques ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'technique' ) || [ ] ) ;
2021-04-03 22:48:02 +02:00
}
2021-04-02 16:47:38 +02:00
/* -------------------------------------------- */
getDevotions ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'devotion' ) || [ ] ) ;
2021-04-02 16:47:38 +02:00
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
getEquipements ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'equipement' ) || [ ] ) ;
2021-04-03 22:48:02 +02:00
}
/* -------------------------------------------- */
getArmes ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'armecc' || item . type == 'tir' ) || [ ] ) ;
2021-04-03 22:48:02 +02:00
}
/* -------------------------------------------- */
getArmures ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'armurebouclier' ) || [ ] ) ;
2021-04-03 22:48:02 +02:00
}
2021-04-23 12:51:52 +02:00
/* -------------------------------------------- */
getMonnaies ( ) {
2024-04-27 23:28:28 +02:00
return duplicate ( this . items . filter ( item => item . type == 'monnaie' ) || [ ] ) ;
2021-04-23 12:51:52 +02:00
}
2021-04-02 16:47:38 +02:00
2021-04-02 14:59:58 +02:00
/* -------------------------------------------- */
async updateCompetence ( name , field , value ) {
2024-04-27 23:28:28 +02:00
let competence = this . items . find ( item => item . type == 'competence' && item . name == name ) ;
2021-04-02 14:59:58 +02:00
if ( competence ) {
2024-04-27 23:28:28 +02:00
let dataPath = 'system.' + field ;
2022-01-20 13:09:16 +01:00
await this . updateEmbeddedDocuments ( "Item" , [ { _id : competence . id , [ dataPath ] : value } ] ) ;
2021-04-02 14:59:58 +02:00
}
}
2021-04-02 16:47:38 +02:00
/* -------------------------------------------- */
2021-04-03 22:48:02 +02:00
async equiperObject ( equipementId ) {
2022-01-20 13:09:16 +01:00
let item = this . items . get ( equipementId )
if ( item ) {
2024-04-27 23:28:28 +02:00
let update = { _id : item . id , "system.equipee" : ! item . system . equipee } ;
2022-01-20 13:09:16 +01:00
await this . updateEmbeddedDocuments ( "Item" , [ update ] ) ;
2021-04-03 22:48:02 +02:00
}
}
2021-04-02 16:47:38 +02:00
2021-04-24 21:30:17 +02:00
/* -------------------------------------------- */
buildListeActionsCombat ( ) {
let armes = [ ] ;
}
2021-04-13 14:01:22 +02:00
/* -------------------------------------------- */
calculerSommeStats ( ) {
2024-04-27 23:28:28 +02:00
for ( const key in this . system . combat ) {
let combatData = this . system . combat [ key ] ;
2021-04-13 14:01:22 +02:00
combatData . total = combatData . base + combatData . malus + combatData . bonus ;
}
2024-04-27 23:28:28 +02:00
for ( const key in this . system . magie ) {
let magieData = this . system . magie [ key ] ;
2021-04-13 14:01:22 +02:00
magieData . total = magieData . base + magieData . malus + magieData . bonus ;
}
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
async processSortDevotion ( name , devotionSort ) {
2024-04-27 23:28:28 +02:00
if ( this . system . stats . pointsenergie . value == 0 ) { // Vérification du ~ de points d'énergie
2021-04-03 22:48:02 +02:00
ChatMessage . create ( { content : ` ${ this . name } n'a pas assez de Points d'Energie pour lancer ${ name } ${ devotionSort . name } ` } ) ;
return ;
}
2024-04-27 23:28:28 +02:00
let scores = this . system . magie [ ( name == "devotion" ) ? 'devotion' : 'matriseelementaire' ] ;
2021-04-03 22:48:02 +02:00
let statValue = scores . base + scores . malus + scores . bonus ;
2021-04-13 14:01:22 +02:00
let formulaFull = this . buildTexteFormula ( scores ) ;
let myRoll = await VadentisUtility . processRoll ( "1d20+" + statValue ) ;
let msgData = {
alias : this . name ,
title : ` Sort ${ devotionSort . name } ` ,
isSort : true
}
2024-04-27 23:28:28 +02:00
if ( myRoll . dice [ 0 ] . results [ 0 ] . result > 1 && myRoll . total >= devotionSort . system . difficulty ) {
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_sort_réussi.webp' ;
2024-04-27 23:28:28 +02:00
msgData . msg = ` ${ this . name } a réussi son ${ name } et perd ${ devotionSort . system . pe } Points d'Energie (lancer : ${ formulaFull } => <strong> ${ myRoll . total } / ${ devotionSort . system . difficulty } </strong>). ` ;
2021-04-14 20:47:57 +02:00
2024-04-27 23:28:28 +02:00
let maintain = ( devotionSort . system . ismaintain ) ? "Oui" : "Non" ;
let complex = ( devotionSort . system . complexactions ) ? "Oui" : "Non" ;
2021-04-14 20:47:57 +02:00
msgData . msg += ` <br>Peut être maintenu: ${ maintain } <br>Actions complexes : ${ complex } ` ;
2024-04-27 23:28:28 +02:00
if ( ! devotionSort . system . notes ) devotionSort . system . notes = "" ;
msgData . msg += ` <br><strong>Description : </strong> ${ devotionSort . system . notes . replace ( /<\/?[^>]+(>|$)/g , "" ) } ` ;
2021-04-24 21:30:17 +02:00
2024-04-27 23:28:28 +02:00
let newEnergie = this . system . stats . pointsenergie . value - devotionSort . system . pe ;
await this . update ( { 'system.stats.pointsenergie.value' : newEnergie } ) ;
if ( myRoll . dice [ 0 ] . results [ 0 ] . result >= devotionSort . system . valuecritical ) { // Critique ?
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_réussite_critique.webp' ;
2021-04-14 20:47:57 +02:00
msgData . msg += "<br>C'est une <strong>réussite critique</strong> !" ;
2024-04-27 23:28:28 +02:00
msgData . msg += ` <br><strong>Effet critique : </strong> ${ devotionSort . system . criticaleffect . replace ( /<\/?[^>]+(>|$)/g , "" ) } ` ;
2021-04-14 20:47:57 +02:00
} else {
2024-04-27 23:28:28 +02:00
msgData . msg += ` <br><strong>Effet : </strong> ${ devotionSort . system . effect . replace ( /<\/?[^>]+(>|$)/g , "" ) } ` ;
2021-04-13 14:01:22 +02:00
}
2021-04-03 22:48:02 +02:00
2024-04-27 23:28:28 +02:00
if ( devotionSort . system . damage != "" ) {
let formula = devotionSort . system . damage ;
if ( myRoll . dice [ 0 ] . results [ 0 ] . result >= devotionSort . system . valuecritical ) { // Critique ?
msgData . msg += ` <br>Et provoque les dégats critiques suivants : [[/roll ${ devotionSort . system . damagecritical } ]] ` ;
formula = devotionSort . system . damagecritical ;
2021-04-13 14:01:22 +02:00
} else {
2024-04-27 23:28:28 +02:00
msgData . msg += ` <br>Et provoque les dégats suivants : [[/roll ${ devotionSort . system . damage } ]] ` ;
2021-04-02 16:47:38 +02:00
}
}
2021-04-03 22:48:02 +02:00
if ( newEnergie < 0 ) {
2021-04-13 14:01:22 +02:00
msgData . msg += ` <br><strong>Attention</strong> : Les Points d'Energie de ${ this . name } sont négatifs ! Il convient d'éditer ses Points de Vie en conséquence. ` ;
2021-04-03 22:48:02 +02:00
}
} else {
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_sort_échoué.webp' ;
2022-01-21 10:57:09 +01:00
if ( myRoll . dice [ 0 ] . results [ 0 ] . result == 1 ) { // Critique ?
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_échec_critique.webp' ;
msgData . msg = ` ${ this . name } a fait un <strong>échec critique</strong> à son lancer de ${ name } ` ;
2021-04-08 13:58:51 +02:00
} else {
2021-04-13 14:01:22 +02:00
msgData . msg = ` ${ this . name } a échoué son lancer de ${ name } ` ;
2021-04-08 13:58:51 +02:00
}
2021-04-03 22:48:02 +02:00
}
2024-04-27 23:28:28 +02:00
console . log ( devotionSort . system . description , msgData ) ;
2021-04-13 14:01:22 +02:00
ChatMessage . create ( {
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
}
2021-04-03 22:48:02 +02:00
2021-04-08 13:58:51 +02:00
/* -------------------------------------------- */
async rollDamage ( weapon , damageType ) {
2024-04-29 08:56:44 +02:00
let formula = VadentisUtility . processDamageString ( weapon . system [ damageType ] , this ) ;
2021-04-08 13:58:51 +02:00
let degatsRoll = await VadentisUtility . processRoll ( formula ) ;
2021-04-13 14:01:22 +02:00
let msgData = {
alias : this . name ,
img : "systems/foundryvtt-vadentis/images/icons/tchat_dégâts_infligés.webp" ,
title : ` Dégâts de ${ weapon . name } ` ,
msg : ` ${ this . name } frappe avec ${ weapon . name } et produit <strong> ${ degatsRoll . total } Points de Dégâts</strong> ( ${ formula } ). `
}
ChatMessage . create ( {
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
2021-04-08 13:58:51 +02:00
}
2021-04-24 21:30:17 +02:00
/* -------------------------------------------- */
async rollSortDevotionDamage ( sort , damageType ) {
2024-04-29 08:56:44 +02:00
let formula = VadentisUtility . processDamageString ( sort . system [ damageType ] , this ) ;
2021-04-24 21:30:17 +02:00
let degatsRoll = await VadentisUtility . processRoll ( formula ) ;
let msgData = {
alias : this . name ,
img : "systems/foundryvtt-vadentis/images/icons/tchat_dégâts_infligés.webp" ,
title : ` Dégâts de ${ sort . name } ` ,
msg : ` Le sort ${ sort . name } produit <strong> ${ degatsRoll . total } Points de Dégâts</strong> ( ${ formula } ). `
}
ChatMessage . create ( {
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
}
2021-04-08 13:58:51 +02:00
/* -------------------------------------------- */
async applyDamage ( damageValue ) {
2024-04-27 23:28:28 +02:00
let pvData = this . system . stats . pointsvie ;
2021-04-08 13:58:51 +02:00
let newValue = Math . max ( pvData . value - damageValue , MIN _PV ) ;
2024-04-27 23:28:28 +02:00
await this . update ( { 'system.stats.pointsvie.value' : newValue } ) ;
2021-04-13 14:01:22 +02:00
let msgData = {
alias : this . name ,
img : "systems/foundryvtt-vadentis/images/icons/tchat_dégâts_infligés.webp" ,
title : ` ${ this . name } encaisse des dégâts ! ` ,
2021-04-22 16:03:51 +02:00
msg : ` ${ this . name } encaisse ${ damageValue } dégâts ! `
2021-04-13 14:01:22 +02:00
}
2021-04-22 16:03:51 +02:00
2021-04-13 14:01:22 +02:00
ChatMessage . create ( {
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
2021-04-23 20:40:59 +02:00
if ( game . user . isGM ) {
msgData . msg = ` <br>Ses Points de Vie actuels sont désormais de ${ newValue } . ` ;
ChatMessage . create ( {
whisper : ChatMessage . getWhisperRecipients ( 'GM' ) ,
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
}
2021-04-08 13:58:51 +02:00
}
/* -------------------------------------------- */
_getCombatValue ( mydata ) {
2021-04-13 14:01:22 +02:00
if ( typeof mydata . base == 'number' ) {
2021-04-08 13:58:51 +02:00
return mydata . base + mydata . malus + mydata . bonus ;
2021-04-13 20:19:32 +02:00
} else {
2021-04-08 13:58:51 +02:00
return Number ( mydata . base [ 0 ] ) + Number ( mydata . malus [ 0 ] ) + Number ( mydata . bonus [ 0 ] ) ;
}
}
/* -------------------------------------------- */
getInitiativeScore ( ) {
2024-04-27 23:28:28 +02:00
let initData = this . system . combat . initiative ;
2021-04-08 13:58:51 +02:00
return this . _getCombatValue ( initData ) ;
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
getDefenseScore ( ) {
2024-04-27 23:28:28 +02:00
let defenseData = this . system . combat . defense ;
2021-04-08 13:58:51 +02:00
return this . _getCombatValue ( defenseData ) ;
}
/* -------------------------------------------- */
getForceScore ( ) {
2024-04-27 23:28:28 +02:00
let forceData = this . system . combat . force ;
2021-04-08 13:58:51 +02:00
return this . _getCombatValue ( forceData ) ;
2021-04-03 22:48:02 +02:00
}
/* -------------------------------------------- */
getAttaqueScore ( ) {
2024-04-27 23:28:28 +02:00
let attaqueData = this . system . combat . attaque ;
2021-04-08 13:58:51 +02:00
return this . _getCombatValue ( attaqueData ) ;
2021-04-03 22:48:02 +02:00
}
2021-04-13 14:01:22 +02:00
/* -------------------------------------------- */
buildTexteFormula ( stat ) {
let signMalus = ( stat . malus < 0 ) ? "" : "+" ;
return ` 1d20+ ${ stat . base } ${ signMalus } ${ stat . malus } + ${ stat . bonus } ` ;
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
async rollSort ( sortId ) {
2024-04-27 23:28:28 +02:00
let sort = this . items . get ( sortId ) ;
2021-04-03 22:48:02 +02:00
if ( sort ) {
2022-01-20 13:09:16 +01:00
sort = duplicate ( sort )
2021-04-03 22:48:02 +02:00
this . processSortDevotion ( "sort" , sort ) ;
2021-04-02 16:47:38 +02:00
}
}
/* -------------------------------------------- */
2021-04-03 22:48:02 +02:00
async rollDevotion ( devotionId ) {
2024-04-27 23:28:28 +02:00
let devotion = this . items . get ( devotionId ) ;
2021-04-02 16:47:38 +02:00
if ( devotion ) {
2022-01-20 13:09:16 +01:00
devotion = duplicate ( devotion )
2021-04-03 22:48:02 +02:00
this . processSortDevotion ( "devotion" , devotion ) ;
}
}
2021-04-02 16:47:38 +02:00
2021-04-24 21:30:17 +02:00
/* -------------------------------------------- */
rollSortOuDevotion ( sortId ) {
2024-04-27 23:28:28 +02:00
let sort = this . items . get ( sortId ) ;
2021-04-24 21:30:17 +02:00
this . processSortDevotion ( sort . type , sort ) ;
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
async rollTechnique ( techniqueId ) {
2024-04-27 23:28:28 +02:00
let technique = this . items . get ( techniqueId )
2021-04-03 22:48:02 +02:00
if ( technique ) {
2022-01-20 13:09:16 +01:00
technique = duplicate ( technique )
2021-04-13 14:01:22 +02:00
let msgData = {
alias : this . name ,
img : technique . img ,
title : ` Technique ${ technique . name } `
}
2024-04-27 23:28:28 +02:00
if ( this . system . stats . pointsadrenaline . value < technique . system . pacost ) { // Vérification du ~ de points d'adrénaline
2021-04-13 14:01:22 +02:00
msgData . msg = ` ${ this . name } n'a pas assez de Points d'Adrénaline pour éxecuter sa technique ${ technique . name } ` ;
} else {
2024-04-27 23:28:28 +02:00
let newAdrenaline = this . system . stats . pointsadrenaline . value - technique . system . pacost ;
await this . update ( { 'system.stats.pointsadrenaline.value' : newAdrenaline } ) ;
msgData . msg = ` ${ this . name } execute sa technique ${ technique . name } , pour un côut de ${ technique . system . pacost } Points d'Adrénaline<br>
Les effets sont : $ { technique . system . effect } ` ;
2021-04-02 16:47:38 +02:00
}
2021-04-13 14:01:22 +02:00
ChatMessage . create ( {
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
} else {
ui . notifications . warn ( "Technique non trouvée" ) ;
2021-04-02 16:47:38 +02:00
}
}
2021-04-02 14:59:58 +02:00
/* -------------------------------------------- */
2021-04-13 14:01:22 +02:00
async rollCompetence ( competenceId ) {
2022-01-20 13:09:16 +01:00
console . log ( competenceId )
2024-04-27 23:28:28 +02:00
let competence = this . items . get ( competenceId ) ;
2021-04-02 14:59:58 +02:00
if ( competence ) {
2022-01-20 13:09:16 +01:00
competence = duplicate ( competence )
2021-04-13 14:01:22 +02:00
let msgData = {
alias : this . name ,
img : competence . img ,
2021-04-22 16:03:51 +02:00
rollMode : game . settings . get ( "core" , "rollMode" ) ,
2021-04-13 14:01:22 +02:00
title : ` Compétence ${ competence . name } `
}
2024-04-27 23:28:28 +02:00
let statValue = competence . system . base + competence . system . malus + competence . system . bonus ;
2024-04-29 08:56:44 +02:00
let formulaFull = this . buildTexteFormula ( competence . system ) ;
2021-04-22 16:03:51 +02:00
let myRoll = await VadentisUtility . processRoll ( "1d20+" + statValue , msgData . rollMode ) ;
2021-04-13 14:01:22 +02:00
msgData . msg = ` ${ formulaFull } => <strong> ${ myRoll . total } </strong> ` ;
2022-01-20 13:09:16 +01:00
console . log ( formulaFull , myRoll )
if ( myRoll . dice [ 0 ] . results [ 0 ] . result == 1 ) { // Critique ?
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_échec_critique.webp' ;
msgData . msg += ` <br>C'est un <strong>échec critique</strong> ! ` ;
}
2022-01-20 13:09:16 +01:00
if ( myRoll . dice [ 0 ] . results [ 0 ] . result == 20 ) { // Critique ?
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_réussite_critique.webp' ;
msgData . msg += ` <br>C'est une <strong>réussite critique</strong> ! ` ;
}
2021-04-22 16:03:51 +02:00
if ( [ "gmroll" , "blindroll" ] . includes ( msgData . rollMode ) ) msgData [ "whisper" ] = ChatMessage . getWhisperRecipients ( "GM" ) . map ( u => u . id ) ;
if ( msgData . rollMode === "blindroll" ) msgData [ "blind" ] = true ;
else if ( msgData . rollMode === "selfroll" ) msgData [ "whisper" ] = [ game . user ] ;
2021-04-13 14:01:22 +02:00
ChatMessage . create ( {
2021-04-22 16:03:51 +02:00
whisper : msgData [ "whisper" ] ,
2021-04-13 14:01:22 +02:00
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
} else {
ui . notifications . warn ( "Compétence non trouvée" ) ;
2021-04-02 14:59:58 +02:00
}
}
/* -------------------------------------------- */
2021-04-14 20:47:57 +02:00
async genericRoll ( stat , key ) {
2021-04-08 13:58:51 +02:00
let statValue = this . _getCombatValue ( stat ) ;
2021-04-13 14:01:22 +02:00
let formulaFull = this . buildTexteFormula ( stat ) ;
2022-01-20 13:09:16 +01:00
2021-04-13 14:01:22 +02:00
let myRoll = await VadentisUtility . processRoll ( "1d20+" + statValue ) ;
let msgData = {
alias : this . name ,
2021-04-14 20:47:57 +02:00
img : ` systems/foundryvtt-vadentis/images/icons/feuille_perso_ ${ key } .webp ` ,
2021-04-13 20:19:32 +02:00
title : VadentisUtility . buildJetText ( stat ) ,
2021-04-13 14:01:22 +02:00
msg : ` ${ formulaFull } => <strong> ${ myRoll . total } </strong> `
}
2022-01-21 10:57:09 +01:00
if ( myRoll . dice [ 0 ] . results [ 0 ] . result == 1 ) { // Critique ?
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_échec_critique.webp' ;
msgData . msg += ` <br>C'est un <strong>échec critique</strong> ! ` ;
}
2022-01-21 10:57:09 +01:00
if ( myRoll . dice [ 0 ] . results [ 0 ] . result == 20 ) { // Critique ?
2021-04-13 14:01:22 +02:00
msgData . img = 'systems/foundryvtt-vadentis/images/icons/tchat_réussite_critique.webp' ;
msgData . msg += ` <br>C'est une <strong>réussite critique</strong> ! ` ;
}
ChatMessage . create ( {
//whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content : await renderTemplate ( ` systems/foundryvtt-vadentis/templates/chat-generic-result.html ` , msgData )
} ) ;
}
/* -------------------------------------------- */
async rollCombat ( combatName ) {
2024-04-27 23:28:28 +02:00
let stat = this . system . combat [ combatName ] ;
2021-04-14 20:47:57 +02:00
this . genericRoll ( stat , combatName ) ;
2021-04-13 14:01:22 +02:00
}
/* -------------------------------------------- */
rollMagie ( magieName ) {
2024-04-27 23:28:28 +02:00
let stat = this . system . magie [ magieName ] ;
2021-04-14 20:47:57 +02:00
this . genericRoll ( stat , magieName ) ;
2021-04-03 22:48:02 +02:00
}
2021-04-24 21:30:17 +02:00
/* -------------------------------------------- */
async incrementeArgent ( arme ) {
2024-04-27 23:28:28 +02:00
let monnaie = this . items . find ( item => item . type == 'monnaie' && item . name == arme . name ) ;
2021-04-24 21:30:17 +02:00
if ( monnaie ) {
2022-01-20 13:09:16 +01:00
monnaie = duplicate ( monnaie )
2024-04-27 23:28:28 +02:00
let newValeur = monnaie . system . nombre + 1 ;
await this . updateEmbeddedDocuments ( 'Item' , [ { _id : monnaie . _id , 'system.nombre' : newValeur } ] ) ;
2021-04-24 21:30:17 +02:00
}
}
/* -------------------------------------------- */
async decrementeArgent ( arme ) {
2024-04-27 23:28:28 +02:00
let monnaie = this . items . find ( item => item . type == 'monnaie' && item . name == arme . name ) ;
2021-04-24 21:30:17 +02:00
if ( monnaie ) {
2022-01-20 13:09:16 +01:00
monnaie = duplicate ( monnaie )
2024-04-27 23:28:28 +02:00
let newValeur = monnaie . system . nombre - 1 ;
2021-04-24 21:30:17 +02:00
newValeur = ( newValeur <= 0 ) ? 0 : newValeur ;
2024-04-27 23:28:28 +02:00
await this . updateEmbeddedDocuments ( "Item" , [ { _id : monnaie . _id , 'system.nombre' : newValeur } ] ) ;
2021-04-24 21:30:17 +02:00
}
}
2021-04-03 22:48:02 +02:00
2021-04-24 21:30:17 +02:00
/* -------------------------------------------- */
async incrementeMunition ( arme ) {
2024-04-27 23:28:28 +02:00
let armeTir = this . items . find ( item => item . type == 'tir' && item . name == arme . name ) ;
2021-04-24 21:30:17 +02:00
if ( armeTir ) {
2022-01-20 13:09:16 +01:00
armeTir = duplicate ( armeTir )
2024-04-27 23:28:28 +02:00
let newMunition = armeTir . system . munition + 1 ;
await this . updateEmbeddedDocuments ( "Item" , [ { _id : armeTir . _id , 'system.munition' : newMunition } ] ) ;
2021-04-24 21:30:17 +02:00
}
}
2021-04-22 16:03:51 +02:00
/* -------------------------------------------- */
async decrementeMunition ( arme ) {
2024-04-27 23:28:28 +02:00
let armeTir = this . items . find ( item => item . type == 'tir' && item . name == arme . name ) ;
2021-04-22 16:03:51 +02:00
if ( armeTir ) {
2022-01-20 13:09:16 +01:00
armeTir = duplicate ( armeTir )
2024-04-27 23:28:28 +02:00
let newMunition = armeTir . system . munition - 1 ;
2021-04-24 21:30:17 +02:00
newMunition = ( newMunition <= 0 ) ? 0 : newMunition ;
2024-04-27 23:28:28 +02:00
await this . updateEmbeddedDocuments ( "Item" , [ { _id : armeTir . _id , 'system.munition' : newMunition } ] ) ;
2021-04-22 16:03:51 +02:00
}
}
2021-04-28 17:37:20 +02:00
/* -------------------------------------------- */
async incrementeQuantite ( objet ) {
2024-04-27 23:28:28 +02:00
let objetQ = this . items . find ( item => item . _id == objet . _id ) ;
2021-04-28 17:37:20 +02:00
if ( objetQ ) {
2022-01-20 13:09:16 +01:00
objetQ = duplicate ( objetQ )
2024-04-27 23:28:28 +02:00
let newQ = objetQ . system . quantite + 1 ;
await this . updateEmbeddedDocuments ( "Item" , [ { _id : objetQ . _id , 'system.quantite' : newQ } ] ) ;
2021-04-28 17:37:20 +02:00
}
}
/* -------------------------------------------- */
async decrementeQuantite ( objet ) {
2024-04-27 23:28:28 +02:00
let objetQ = this . items . find ( item => item . _id == objet . _id ) ;
2021-04-28 17:37:20 +02:00
if ( objetQ ) {
2022-01-20 13:09:16 +01:00
objetQ = duplicate ( objetQ )
2024-04-27 23:28:28 +02:00
let newQ = objetQ . system . quantite - 1 ;
2021-04-28 17:37:20 +02:00
newQ = ( newQ <= 0 ) ? 0 : newQ ;
2024-04-27 23:28:28 +02:00
await this . updateEmbeddedDocuments ( "Item" , [ { _id : objetQ . _id , 'system.quantite' : newQ } ] ) ;
2021-04-28 17:37:20 +02:00
}
}
2021-04-03 22:48:02 +02:00
/* -------------------------------------------- */
rollArme ( armeId ) {
let target = VadentisUtility . getTarget ( ) ;
if ( target ) {
2024-04-27 23:28:28 +02:00
let arme = this . items . find ( item => ( item . type == 'armecc' || item . type == 'tir' ) && item . id == armeId ) ;
2021-04-03 22:48:02 +02:00
if ( arme ) {
2022-01-20 13:09:16 +01:00
arme = duplicate ( arme )
2024-04-27 23:28:28 +02:00
if ( arme . type == 'tir' && arme . system . munition <= 0 ) {
2021-04-22 16:03:51 +02:00
ui . notifications . warn ( "Vous n'avez plus de munitions avec cette arme." ) ;
return ;
}
2021-04-03 22:48:02 +02:00
let combatData = {
2022-01-21 10:57:09 +01:00
attackerActorId : this . id ,
targetActorId : target . actor . id ,
2021-04-03 22:48:02 +02:00
arme : duplicate ( arme )
}
if ( game . user . isGM ) {
VadentisUtility . performAttack ( combatData ) ;
} else {
2021-04-18 18:14:31 +02:00
game . socket . emit ( "system.foundryvtt-vadentis" , { name : "msg_attack" , data : combatData } ) ;
2021-04-03 22:48:02 +02:00
}
}
} else {
ui . notifications . warn ( "Vous devez désigner une cible pour attaquer avec une arme." )
}
2021-04-02 14:59:58 +02:00
}
2021-04-01 21:18:36 +02:00
}