2022-01-09 09:33:47 +01:00
/* -------------------------------------------- */
import { YggdrasillUtility } from "./yggdrasill-utility.js" ;
import { YggdrasillRoll } from "./yggdrasill-roll-dialog.js" ;
/* -------------------------------------------- */
const statusEffects = [
{ yggdrasill : true , id : 'epuise' , label : 'Epuisé' , icon : 'icons/svg/stoned.svg' } ,
{ yggdrasill : true , id : 'blesse' , label : 'Blessé' , icon : 'icons/svg/blood.svg' } ,
{ yggdrasill : true , id : 'meurtri' , label : 'Meurtri' , icon : 'icons/svg/falling.svg' }
]
const armeCategorieToCompetence = { "lutte" : "Lutte" , "improvisee" : "Armes Improvisées" , "courte" : "Armes courtes" , "longue" : "Armes longues" , "deuxmains" : "Armes à deux mains" ,
"hast" : "Armes d'Hast" , "tir" : "Armes de tir" , "jet" : "Lancer" }
const attackMode = {
"classique" : {
"categName" : "corps" ,
"caracName" : "agilite" ,
"malus" : 0 ,
"protection" : 0 ,
"bonusdegats" : 0 ,
"label" : "Attaque Classique" ,
"description" : "Attaque classique"
} ,
"force" : {
"categName" : "corps" ,
"caracName" : "puissance" ,
"malus" : 0 ,
"protection" : 0 ,
"bonusdegats" : "puissance;1" ,
"label" : "Attaque en Force" ,
"description" : "Attaque en Force : Malus: 0, +PUI en dégats"
} ,
"devastatrice" : {
"categName" : "corps" ,
"caracName" : "puissance" ,
"malus" : "puissance;1" ,
"bonusdegats" : "puissance;3" ,
"protection" : 0 ,
"label" : "Attaque Dévastatrice" ,
"description" : "Attaque Dévastratrice : Malus -PUI, +PUI*3 en dégats"
} ,
"precise" : {
"categName" : "esprit" ,
"caracName" : "perception" ,
"malus" : "0" ,
"bonusdegats" : 0 ,
"protection" : "perception;1" ,
"label" : "Attaque Précise" ,
"description" : "Attaque précise : Malus : 0, protection réduite de -PER"
} ,
"visee" : {
"categName" : "esprit" ,
"caracName" : "perception" ,
"malus" : "perception;1" ,
"bonusdegats" : 0 ,
"protection" : "perception;3" ,
"label" : "Attaque Visée" ,
"description" : "Attaque visée : Malus : -PER, protection réduite de -PER"
}
}
const tirMode = {
"pose" : {
"categName" : "corps" ,
"caracName" : "agilite" ,
"malus" : 0 ,
"protection" : 0 ,
"bonusdegats" : 0 ,
"label" : "Tir posé" ,
"description" : "Tir posé"
} ,
"arrettir" : {
"categName" : "ame" ,
"caracName" : "instinct" ,
"malus" : 0 ,
"protection" : 0 ,
"bonusdegats" : "instinct;1" ,
"label" : "Tir d'Arrêt (Tir)" ,
"description" : "Tir d'Arrêt (Tir) : Malus: 0, +INS en dégats"
} ,
"arretjet" : {
"categName" : "corps" ,
"caracName" : "puissance" ,
"malus" : 0 ,
"protection" : 0 ,
"bonusdegats" : "puissance;1" ,
"label" : "Tir d'Arrêt (Jet)" ,
"description" : "Tir d'Arrêt (Jet) : Malus: 0, +PUI en dégats"
} ,
"impacttir" : {
"categName" : "ame" ,
"caracName" : "instinct" ,
"malus" : "instinct;1" ,
"protection" : 0 ,
"bonusdegats" : "instinct;3" ,
"label" : "Tir d'Impact (Tir)" ,
"description" : "Tir d'Impact (Tir) : Malus: -INS, +INS*3 en dégats"
} ,
"impactjet" : {
"categName" : "corps" ,
"caracName" : "puissance" ,
"malus" : "puissance;1" ,
"protection" : 0 ,
"bonusdegats" : "puissance;3" ,
"label" : "Attaque d'Impact (Jet)" ,
"description" : "Attaque d'Impact (Jet) : Malus: -PUI, +PUI*3 en dégats"
} ,
"precision" : {
"categName" : "esprit" ,
"caracName" : "perception" ,
"malus" : "0" ,
"bonusdegats" : 0 ,
"protection" : "perception;1" ,
"label" : "Tir de Précision" ,
"description" : "Tir de Précision : Malus : 0, protection réduite de -PER"
} ,
"vise" : {
"categName" : "esprit" ,
"caracName" : "perception" ,
"malus" : "perception;1" ,
"bonusdegats" : 0 ,
"protection" : "perception;3" ,
"label" : "Tir Visée" ,
"description" : "Tir visée : Malus : -PER, protection réduite de -PER"
}
}
/* -------------------------------------------- */
/* -------------------------------------------- */
/ * *
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system .
* @ extends { Actor }
* /
export class YggdrasillActor 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
if ( data . items ) {
let actor = super . create ( data , options ) ;
return actor ;
}
const competencesGen = await YggdrasillUtility . loadCompendium ( "fvtt-yggdrasill.competences-generales" ) ;
const competencesMar = await YggdrasillUtility . loadCompendium ( "fvtt-yggdrasill.competences-martiales" ) ;
const competencesMag = await YggdrasillUtility . loadCompendium ( "fvtt-yggdrasill.competences-magiques" ) ;
const competences = competencesGen . concat ( competencesMar ) . concat ( competencesMag ) ;
data . items = competences . map ( i => i . toObject ( ) ) ;
return super . create ( data , options ) ;
}
/* -------------------------------------------- */
prepareBaseData ( ) {
if ( this . type == "personnage" ) {
this . computeCaracSecondaire ( ) ;
}
}
/* -------------------------------------------- */
async prepareData ( ) {
if ( this . type == "personnage" ) {
this . computeCaracSecondaire ( ) ;
2022-09-21 11:42:09 +02:00
if ( this . system . furor . value == 0 )
2022-01-09 09:33:47 +01:00
await this . setEpuise ( ) ;
else
await this . cleanEpuise ( ) ;
2022-09-21 11:42:09 +02:00
if ( this . system . caracsecondaire . pv . value < ( this . system . caracsecondaire . pv . max / 4 ) )
2022-01-09 09:33:47 +01:00
await this . setMeurtri ( ) ;
else
await this . cleanMeurtri ( ) ;
2022-09-21 11:42:09 +02:00
if ( this . system . caracsecondaire . pv . value < ( this . system . caracsecondaire . pv . max / 2 ) )
2022-01-09 09:33:47 +01:00
await this . setBlesse ( ) ;
else
await this . cleanBlesse ( ) ;
}
super . prepareData ( ) ;
}
/* -------------------------------------------- */
_preUpdate ( changed , options , user ) {
2022-11-13 10:29:36 +01:00
if ( changed . system ? . caracsecondaire ? . pv ? . value ) {
if ( changed . system . caracsecondaire . pv . value < 0 )
changed . system . caracsecondaire . pv . value = 0 ;
if ( changed . system . caracsecondaire . pv . value > this . system . caracsecondaire . pv . max )
changed . system . caracsecondaire . pv . value = this . system . caracsecondaire . pv . max ;
2022-01-09 09:33:47 +01:00
}
2022-01-11 18:19:13 +01:00
2022-11-13 10:29:36 +01:00
if ( changed . system ? . furor ? . value ) {
if ( changed . system . furor . value < 0 )
changed . system . furor . value = 0 ;
if ( changed . system . furor . value > this . system . furor . max )
changed . system . furor . value = this . system . furor . max ;
2022-01-09 09:33:47 +01:00
}
super . _preUpdate ( changed , options , user ) ;
}
/* -------------------------------------------- */
getCompetences ( ) {
2022-09-21 11:42:09 +02:00
let comp = this . items . filter ( item => item . type == 'competence' ) ;
2022-01-09 09:33:47 +01:00
return comp ;
}
/* -------------------------------------------- */
compareName ( a , b ) {
if ( a . name < b . name ) {
return - 1 ;
}
if ( a . name > b . name ) {
return 1 ;
}
return 0 ;
}
/* -------------------------------------------- */
getInitiativeScore ( ) {
2022-01-12 12:09:36 +01:00
if ( this . type == 'personnage' ) {
2022-09-21 11:42:09 +02:00
return this . system . caracsecondaire . reaction . max ;
2022-01-12 11:58:05 +01:00
} else {
2022-09-21 11:42:09 +02:00
return this . system . attributs . physique . values . defaut . value ;
2022-01-12 11:58:05 +01:00
}
2022-01-09 09:33:47 +01:00
}
2022-01-12 11:58:05 +01:00
2022-01-09 09:33:47 +01:00
/* -------------------------------------------- */
getCompetencesGenerales ( ) {
2022-09-21 11:42:09 +02:00
let comp = this . items . filter ( item => item . type == 'competence' && item . system . categorie == 'generale' ) ;
2022-01-09 09:33:47 +01:00
return comp . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getCompetencesMartiales ( ) {
2022-09-21 11:42:09 +02:00
let comp = this . items . filter ( item => item . type == 'competence' && item . system . categorie == 'martiale' ) ;
2022-01-09 09:33:47 +01:00
return comp . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getCompetencesMagiques ( ) {
2022-09-21 11:42:09 +02:00
let comp = this . items . filter ( item => item . type == 'competence' && item . system . categorie == 'magique' ) ;
2022-01-09 09:33:47 +01:00
return comp . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getDons ( ) {
2022-09-21 11:42:09 +02:00
let dons = this . items . filter ( item => item . type == 'don' ) ;
2022-01-09 09:33:47 +01:00
return dons . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getEffetsMagiques ( ) {
2022-09-21 11:42:09 +02:00
let effets = this . items . filter ( item => item . type == 'effetmagique' ) ;
2022-01-09 09:33:47 +01:00
return effets . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getEffetsDeRunes ( ) {
2022-09-21 11:42:09 +02:00
let effets = this . items . filter ( item => item . type == 'effetderune' ) ;
2022-01-09 09:33:47 +01:00
return effets . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getMonnaies ( ) {
2022-09-21 11:42:09 +02:00
let monnaies = this . items . filter ( item => item . type == 'monnaie' ) ;
2022-01-09 09:33:47 +01:00
return monnaies . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getFaiblesses ( ) {
2022-09-21 11:42:09 +02:00
let faib = this . items . filter ( item => item . type == 'faiblesse' ) ;
2022-01-09 09:33:47 +01:00
return faib . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
getBlessures ( ) {
2022-09-21 11:42:09 +02:00
return this . items . filter ( item => item . type == 'blessure' ) ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
getToutEquipements ( ) {
2022-09-21 11:42:09 +02:00
return this . items . filter ( item => item . type == 'equipement' || item . type == 'armure' || item . type == 'armecc' || item . type == 'armedist' || item . type == 'bouclier' ) ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
getArmes ( ) {
2022-09-21 11:42:09 +02:00
return this . items . filter ( item => ( item . type == 'armecc' || item . type == 'armedist' ) && item . system . equipe ) ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
getArmures ( ) {
2022-09-21 11:42:09 +02:00
return this . items . filter ( item => item . type == 'armure' && item . system . equipe ) ;
2022-02-21 22:51:38 +01:00
}
getBoucliers ( ) {
2022-09-21 11:42:09 +02:00
return this . items . filter ( item => item . type == 'bouclier' && item . system . equipe ) ;
2022-01-09 09:33:47 +01:00
}
getProuessesMartiales ( ) {
2022-09-21 11:42:09 +02:00
let prouesse = this . items . filter ( item => item . type == 'prouesse' ) ;
2022-01-09 09:33:47 +01:00
return prouesse . sort ( this . compareName ) ;
}
getSortsSejdr ( ) {
2022-09-21 11:42:09 +02:00
let sort = this . items . filter ( item => item . type == 'sortsejdr' ) ;
2022-01-09 09:33:47 +01:00
return sort . sort ( this . compareName ) ;
}
getSortsGaldr ( ) {
2022-09-21 11:42:09 +02:00
let sort = this . items . filter ( item => item . type == 'sortgaldr' ) ;
2022-01-09 09:33:47 +01:00
return sort . sort ( this . compareName ) ;
}
getRunes ( ) {
2022-09-21 11:42:09 +02:00
let sort = this . items . filter ( item => item . type == 'rune' ) ;
2022-01-09 09:33:47 +01:00
return sort . sort ( this . compareName ) ;
}
/* -------------------------------------------- */
async setEpuise ( ) {
2022-09-21 11:42:09 +02:00
if ( ! this . system . status . epuise ) {
await this . update ( { 'system.status.epuise' : true } ) ;
this . system . status . epuise = true ;
2022-01-11 18:19:13 +01:00
}
2022-01-09 09:33:47 +01:00
/ * l e t e f f e c t = t h i s . g e t E f f e c t B y L a b e l ( ' E p u i s é ' ) ;
if ( ! effect ) {
let effect = statusEffects . find ( ef => ef . id == 'epuise' ) ;
await this . createEmbeddedDocuments ( "ActiveEffect" , [ effect ] ) ;
} * /
}
/* -------------------------------------------- */
async cleanEpuise ( ) {
2022-09-21 11:42:09 +02:00
if ( this . system . status . epuise ) {
await this . update ( { 'system.status.epuise' : false } ) ;
this . system . status . epuise = false ;
2022-01-11 18:19:13 +01:00
}
2022-01-09 09:33:47 +01:00
/ * l e t e f f e c t = t h i s . g e t E f f e c t B y L a b e l ( ' E p u i s é ' ) ;
if ( effect ) {
await this . deleteEmbeddedDocuments ( "ActiveEffect" , [ effect . id ] ) ;
} * /
}
/* -------------------------------------------- */
async toggleEpuise ( ) {
2022-09-21 11:42:09 +02:00
if ( this . system . status . epuise ) {
2022-01-09 09:33:47 +01:00
await this . cleanEpuise ( ) ;
} else {
await this . setEpuise ( ) ;
}
}
/* -------------------------------------------- */
isEpuise ( ) {
2022-09-21 11:42:09 +02:00
return this . system . status . epuise ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
async setBlesse ( ) {
2022-09-21 11:42:09 +02:00
if ( ! this . system . status . blesse ) {
await this . update ( { 'system.status.blesse' : true } ) ;
this . system . status . blesse = true ;
2022-01-11 18:19:13 +01:00
}
2022-01-09 09:33:47 +01:00
/ * l e t e f f e c t = t h i s . g e t E f f e c t B y L a b e l ( ' B l e s s é ' ) ;
if ( ! effect ) {
let effect = statusEffects . find ( ef => ef . id == 'blesse' ) ;
await this . createEmbeddedDocuments ( "ActiveEffect" , [ effect ] ) ;
} * /
}
/* -------------------------------------------- */
async cleanBlesse ( ) {
2022-09-21 11:42:09 +02:00
if ( this . system . status . blesse ) {
await this . update ( { 'system.status.blesse' : false } ) ;
this . system . status . blesse = false ;
2022-01-11 18:19:13 +01:00
}
2022-01-09 09:33:47 +01:00
/ * l e t e f f e c t = t h i s . g e t E f f e c t B y L a b e l ( ' B l e s s é ' ) ;
if ( effect ) {
await this . deleteEmbeddedDocuments ( "ActiveEffect" , [ effect . id ] ) ;
} * /
}
/* -------------------------------------------- */
isBlesse ( ) {
2022-09-21 11:42:09 +02:00
return this . system . status . blesse ;
2022-01-09 09:33:47 +01:00
//return this.getEffectByLabel('Blessé');
}
/* -------------------------------------------- */
async setMeurtri ( ) {
await this . setBlesse ( ) ;
2022-09-21 11:42:09 +02:00
if ( ! this . system . status . meurtri ) {
await this . update ( { 'system.status.meurtri' : true } ) ;
this . system . status . meurtri = true ;
2022-01-11 18:19:13 +01:00
}
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
async cleanMeurtri ( ) {
2022-09-21 11:42:09 +02:00
if ( this . system . status . meurtri ) {
await this . update ( { 'system.status.meurtri' : false } ) ;
this . system . status . meurtri = false ;
2022-01-11 18:19:13 +01:00
}
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
isMeurtri ( ) {
2022-09-21 11:42:09 +02:00
return this . system . status . meurtri ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
async decrementFuror ( nbFuror ) {
2022-09-21 11:42:09 +02:00
await this . update ( { 'system.furor.value' : this . system . furor . value - nbFuror } ) ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
getCurrentFuror ( ) {
2022-09-21 11:42:09 +02:00
return this . system . furor . value ;
2022-01-09 09:33:47 +01:00
}
/* -------------------------------------------- */
getActiveEffects ( matching = it => true ) {
let array = Array . from ( this . getEmbeddedCollection ( "ActiveEffect" ) . values ( ) ) ;
return Array . from ( this . getEmbeddedCollection ( "ActiveEffect" ) . values ( ) ) . filter ( it => matching ( it ) ) ;
}
/* -------------------------------------------- */
getEffectByLabel ( label ) {
return this . getActiveEffects ( ) . find ( it => it . data . label == label ) ;
}
/* -------------------------------------------- */
getEffectById ( id ) {
return this . getActiveEffects ( ) . find ( it => it . id == id ) ;
}
/* -------------------------------------------- */
getCarac ( caracName ) {
2022-09-21 11:42:09 +02:00
for ( let key in this . system . carac ) {
let categ = this . system . carac [ key ] ;
2022-01-09 09:33:47 +01:00
for ( let carac in categ . carac ) {
if ( carac . toLowerCase ( ) == caracName . toLowerCase ( ) ) {
return deepClone ( categ . carac [ carac ] ) ;
}
}
}
}
/* -------------------------------------------- */
computeCaracSecondaire ( ) {
if ( this . type == "personnage" ) {
2022-09-21 11:42:09 +02:00
let basecorps = this . system . carac . corps . carac ;
2022-01-09 09:33:47 +01:00
let sumcorps = basecorps . puissance . value + basecorps . agilite . value + basecorps . vigueur . value
2022-09-21 11:42:09 +02:00
let baseesprit = this . system . carac . esprit . carac ;
2022-01-09 09:33:47 +01:00
let sumesprit = baseesprit . intellect . value + baseesprit . perception . value + baseesprit . tenacite . value
2022-09-21 11:42:09 +02:00
let baseame = this . system . carac . ame . carac ;
2022-01-09 09:33:47 +01:00
let sumame = baseame . charisme . value + baseame . communication . value + baseame . instinct . value
let newPV = ( sumcorps * 3 ) + ( sumesprit * 2 ) + sumame ;
2022-09-21 11:42:09 +02:00
if ( newPV != this . system . caracsecondaire . pv . max ) {
this . system . caracsecondaire . pv . max = newPV ;
this . update ( { 'system.caracsecondaire.pv.max' : newPV } ) ;
2022-01-09 09:33:47 +01:00
}
2022-09-21 11:42:09 +02:00
this . system . caracsecondaire . reaction . value = baseesprit . intellect . value + baseesprit . perception . value + baseame . instinct . value ;
2022-11-13 10:29:36 +01:00
let newReac = baseesprit . intellect . value + baseesprit . perception . value + baseame . instinct . value ;
if ( newReac != this . system . caracsecondaire . reaction . max ) {
this . system . caracsecondaire . reaction . max = newReac
this . update ( { 'system.caracsecondaire.reaction.max' : newReac } ) ;
}
2022-01-09 09:33:47 +01:00
2022-09-21 11:42:09 +02:00
this . system . caracsecondaire . defensephy . value = basecorps . agilite . value + basecorps . vigueur . value + baseame . instinct . value ;
2022-11-13 10:29:36 +01:00
let newDef = basecorps . agilite . value + basecorps . vigueur . value + baseame . instinct . value ;
if ( newDef != this . system . caracsecondaire . defensephy . max ) {
this . system . caracsecondaire . defensephy . max = newDef
this . update ( { 'system.caracsecondaire.defensephy.max' : newDef } ) ;
}
2022-01-09 09:33:47 +01:00
2022-09-21 11:42:09 +02:00
this . system . caracsecondaire . defensemen . value = baseesprit . tenacite . value + baseame . instinct . value + baseesprit . intellect . value ;
2022-11-13 10:29:36 +01:00
newDef = baseesprit . tenacite . value + baseame . instinct . value + baseesprit . intellect . value ;
if ( newDef != this . system . caracsecondaire . defensemen . max ) {
this . system . caracsecondaire . defensemen . max = newDef
this . update ( { 'system.caracsecondaire.defensemen.max' : newDef } ) ;
}
2022-01-09 09:33:47 +01:00
2022-09-21 11:42:09 +02:00
this . system . caracsecondaire . deplacement . value = basecorps . agilite . value + basecorps . vigueur . value ;
2022-11-13 10:29:36 +01:00
let depl = basecorps . agilite . value + basecorps . vigueur . value ;
if ( depl != this . system . caracsecondaire . deplacement . max ) {
this . system . caracsecondaire . deplacement . max = depl
this . update ( { 'system.caracsecondaire.deplacement.max' : depl } ) ;
}
2022-01-09 09:33:47 +01:00
2022-09-21 11:42:09 +02:00
this . system . caracsecondaire . capaenc . value = ( basecorps . puissance . value * 2 ) + basecorps . vigueur . value ;
2022-11-13 10:29:36 +01:00
let enc = ( basecorps . puissance . value * 2 ) + basecorps . vigueur . value ;
if ( enc != this . system . caracsecondaire . capaenc . max ) {
this . system . caracsecondaire . capaenc . max = enc
this . update ( { 'system.caracsecondaire.capaenc.max' : enc } ) ;
}
//console.log("CARAC SEC", this.system.caracsecondaire)
2022-01-09 09:33:47 +01:00
}
}
/* -------------------------------------------- */
async equiperObject ( equipementId ) {
2022-09-21 11:42:09 +02:00
let item = this . items . find ( item => item . id == equipementId ) ;
if ( item && item . system ) {
let update = { _id : item . id , "data.equipe" : ! item . system . equipe } ;
2022-01-09 09:33:47 +01:00
await this . updateEmbeddedDocuments ( 'Item' , [ update ] ) ; // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
async updateCompetence ( compId , niveau ) {
2022-09-21 11:42:09 +02:00
let comp = this . items . find ( item => item . type == 'competence' && item . id == compId ) ;
2022-01-09 09:33:47 +01:00
console . log ( "Comp updated!!!!" , compId , niveau ) ;
if ( comp ) {
2022-09-21 11:42:09 +02:00
const update = { _id : comp . id , 'system.niveau' : niveau } ;
2022-01-09 09:33:47 +01:00
await this . updateEmbeddedDocuments ( 'Item' , [ update ] ) ; // Updates one EmbeddedEntity
} else {
ui . notifications . warn ( "Compétence inconnue" , compId )
}
}
/* -------------------------------------------- */
buildListeActionsCombat ( ) {
let armes = [ ] ;
}
/* -------------------------------------------- */
async rollAttribute ( attrkey , subAttrKey = 'defaut' ) {
2022-09-21 11:42:09 +02:00
let attr = duplicate ( this . system . attributs [ attrkey ] ) ;
2022-01-12 11:32:08 +01:00
console . log ( "ATTR : " , attr , attrkey , subAttrKey ) ;
2022-09-21 11:42:09 +02:00
let subAttr = duplicate ( this . system . attributs [ attrkey ] . values [ subAttrKey ] ) ;
2022-01-09 09:33:47 +01:00
if ( attr ) {
subAttr . label = subAttr . label || "" ;
let title = ` Attribut : ${ attr . label } ${ subAttr . label } : ${ subAttr . value } ` ;
let rollData = {
mode : "attribut" ,
alias : this . name ,
actorImg : this . img ,
actorId : this . id ,
attr : attr ,
2022-09-21 11:42:09 +02:00
valuePhysique : this . system . attributs [ "physique" ] . values [ "defaut" ] . value ,
2022-01-09 09:33:47 +01:00
subAttr : subAttr ,
rollMode : game . settings . get ( "core" , "rollMode" ) ,
title : title ,
2022-09-21 11:42:09 +02:00
isBlesse : this . system . etat . etat == "blesse" ,
2022-01-23 00:07:47 +01:00
optionsBonusMalus : YggdrasillUtility . buildListOptions ( - 15 , + 15 ) ,
2022-01-09 09:33:47 +01:00
bonusMalus : 0 ,
2022-01-23 00:07:47 +01:00
bonusdefense : 0 ,
optionsBD : YggdrasillUtility . buildListOptions ( 0 , + 15 ) ,
2022-01-09 09:33:47 +01:00
optionsSR : YggdrasillUtility . buildSROptions ( ) ,
sr : 0
}
let rollDialog = await YggdrasillRoll . create ( this , rollData ) ;
console . log ( rollDialog ) ;
rollDialog . render ( true ) ;
} else {
ui . notifications . warn ( "Attribut non trouvée" ) ;
}
}
/* -------------------------------------------- */
async rollCarac ( categName , caracName ) {
2022-09-21 11:42:09 +02:00
let carac = duplicate ( this . system . carac [ categName ] . carac [ caracName ] ) ;
console . log ( "CARAC : " , carac , this . system . carac ) ;
2022-01-09 09:33:47 +01:00
if ( carac ) {
let rollData = {
mode : "carac" ,
alias : this . name ,
actorImg : this . img ,
actorId : this . id ,
img : ` systems/fvtt-yggdrasill/images/icons/icon_carac_ ${ categName } .png ` ,
rollMode : game . settings . get ( "core" , "rollMode" ) ,
title : ` Caractéristique ${ carac . label } : ${ carac . value } ` ,
selectedCarac : carac ,
isEpuise : this . isEpuise ( ) ,
isBlesse : this . isBlesse ( ) ,
isMeurtri : this . isMeurtri ( ) ,
2022-01-23 00:07:47 +01:00
optionsBonusMalus : YggdrasillUtility . buildListOptions ( - 15 , + 15 ) ,
2022-01-09 09:33:47 +01:00
bonusMalus : 0 ,
optionsFuror : YggdrasillUtility . buildListOptions ( 0 , this . getCurrentFuror ( ) ) ,
furorUsage : 0 ,
optionsSR : YggdrasillUtility . buildSROptions ( ) ,
2022-01-23 00:07:47 +01:00
optionsBD : YggdrasillUtility . buildListOptions ( 0 , + 15 ) ,
2022-01-09 09:33:47 +01:00
sr : 0
}
let rollDialog = await YggdrasillRoll . create ( this , rollData ) ;
console . log ( rollDialog ) ;
rollDialog . render ( true ) ;
} else {
ui . notifications . warn ( "Caractéristique non trouvée" ) ;
}
}
/* -------------------------------------------- */
async rollCompetence ( competenceId ) {
2022-09-21 11:42:09 +02:00
let competence = this . items . find ( item => item . type == 'competence' && item . id == competenceId ) ;
2022-01-09 09:33:47 +01:00
if ( competence ) {
let rollData = {
mode : "competence" ,
alias : this . name ,
actorImg : this . img ,
actorId : this . id ,
img : competence . img ,
rollMode : game . settings . get ( "core" , "rollMode" ) ,
2022-09-21 11:42:09 +02:00
title : ` Compétence ${ competence . name } : ${ competence . system . niveau } ` ,
2022-01-09 09:33:47 +01:00
competence : duplicate ( competence ) ,
isEpuise : this . isEpuise ( ) ,
isBlesse : this . isBlesse ( ) ,
isMeurtri : this . isMeurtri ( ) ,
2022-01-23 00:07:47 +01:00
optionsBonusMalus : YggdrasillUtility . buildListOptions ( - 15 , + 15 ) ,
2022-01-09 09:33:47 +01:00
bonusMalus : 0 ,
optionsFuror : YggdrasillUtility . buildListOptions ( 0 , this . getCurrentFuror ( ) ) ,
furorUsage : 0 ,
optionsSR : YggdrasillUtility . buildSROptions ( ) ,
sr : 0
}
let rollDialog = await YggdrasillRoll . create ( this , rollData ) ;
console . log ( rollDialog ) ;
rollDialog . render ( true ) ;
} else {
ui . notifications . warn ( "Compétence non trouvée" ) ;
}
}
/* -------------------------------------------- */
getAttaqueData ( mode ) {
let attackData = duplicate ( attackMode [ mode ] ) ;
if ( attackData ) {
attackData . mode = mode ;
2022-09-21 11:42:09 +02:00
attackData . carac = duplicate ( this . system . carac [ attackData . categName ] . carac [ attackData . caracName ] ) ;
2022-01-09 09:33:47 +01:00
if ( attackData . malus != 0 ) {
let malusTab = attackData . malus . split ( ';' ) ;
2022-09-21 11:42:09 +02:00
attackData . malus = this . system . carac [ attackData . categName ] . carac [ malusTab [ 0 ] ] . value * Number ( malusTab [ 1 ] )
2022-01-09 09:33:47 +01:00
}
if ( attackData . protection != 0 ) {
let malusTab = attackData . protection . split ( ';' ) ;
2022-09-21 11:42:09 +02:00
attackData . protection = this . system . carac [ attackData . categName ] . carac [ malusTab [ 0 ] ] . value * Number ( malusTab [ 1 ] )
2022-01-09 09:33:47 +01:00
}
if ( attackData . bonusdegats != 0 ) {
let malusTab = attackData . bonusdegats . split ( ';' ) ;
2022-09-21 11:42:09 +02:00
attackData . bonusdegats = this . system . carac [ attackData . categName ] . carac [ malusTab [ 0 ] ] . value * Number ( malusTab [ 1 ] )
2022-01-09 09:33:47 +01:00
}
}
return attackData ;
}
/* -------------------------------------------- */
getTirData ( mode ) {
let attackData = duplicate ( tirMode [ mode ] ) ;
if ( attackData ) {
attackData . mode = mode ;
2022-09-21 11:42:09 +02:00
attackData . carac = duplicate ( this . system . carac [ attackData . categName ] . carac [ attackData . caracName ] ) ;
2022-01-09 09:33:47 +01:00
if ( attackData . malus != 0 ) {
let malusTab = attackData . malus . split ( ';' ) ;
2022-09-21 11:42:09 +02:00
attackData . malus = this . system . carac [ attackData . categName ] . carac [ malusTab [ 0 ] ] . value * Number ( malusTab [ 1 ] )
2022-01-09 09:33:47 +01:00
}
if ( attackData . protection != 0 ) {
let malusTab = attackData . protection . split ( ';' ) ;
2022-09-21 11:42:09 +02:00
attackData . protection = this . system . carac [ attackData . categName ] . carac [ malusTab [ 0 ] ] . value * Number ( malusTab [ 1 ] )
2022-01-09 09:33:47 +01:00
}
if ( attackData . bonusdegats != 0 ) {
let malusTab = attackData . bonusdegats . split ( ';' ) ;
2022-09-21 11:42:09 +02:00
attackData . bonusdegats = this . system . carac [ attackData . categName ] . carac [ malusTab [ 0 ] ] . value * Number ( malusTab [ 1 ] )
2022-01-09 09:33:47 +01:00
}
}
return attackData ;
}
/* -------------------------------------------- */
async rollSort ( sortId , magie ) {
2022-09-21 11:42:09 +02:00
let sort = this . items . find ( item => item . id == sortId ) ;
let competence = this . items . find ( item => item . type == 'competence' && item . name . toLowerCase ( ) . includes ( magie ) ) ;
2022-01-09 09:33:47 +01:00
console . log ( "SORT :" , sortId , sort , competence ) ;
let carac ;
if ( magie == "sejdr" ) {
2022-09-21 11:42:09 +02:00
carac = duplicate ( this . system . carac . ame . carac . instinct ) ;
2022-01-09 09:33:47 +01:00
} else if ( magie == "rune" ) {
2022-09-21 11:42:09 +02:00
carac = duplicate ( this . system . carac . ame . carac . communication ) ;
2022-01-09 09:33:47 +01:00
} else {
2022-09-21 11:42:09 +02:00
carac = duplicate ( this . system . carac . ame . carac . charisme ) ;
2022-01-09 09:33:47 +01:00
}
if ( sort && competence ) {
let rollData = {
mode : magie ,
2022-01-23 00:07:47 +01:00
isMagie : true ,
2022-01-09 09:33:47 +01:00
alias : this . name ,
actorImg : this . img ,
actorId : this . id ,
img : sort . img ,
rollMode : game . settings . get ( "core" , "rollMode" ) ,
title : magie + " - " + sort . name ,
selectedCarac : carac ,
2022-09-21 11:42:09 +02:00
agiliteCarac : duplicate ( this . system . carac . corps . carac . agilite ) ,
instinctCarac : duplicate ( this . system . carac . ame . carac . instinct ) ,
2022-01-09 09:33:47 +01:00
sort : duplicate ( sort ) ,
competence : duplicate ( competence ) ,
dureeGaldr : "1d5a" ,
nbCibles : "1" ,
zoneGaldr : "INS10cm3" ,
bonusdefense : 0 ,
isEpuise : this . isEpuise ( ) ,
isBlesse : this . isBlesse ( ) ,
isMeurtri : this . isMeurtri ( ) ,
2022-01-23 00:07:47 +01:00
optionsBonusMalus : YggdrasillUtility . buildListOptions ( - 15 , + 15 ) ,
optionsBD : YggdrasillUtility . buildListOptions ( 0 , + 15 ) ,
2022-01-09 09:33:47 +01:00
bonusMalus : 0 ,
optionsFuror : YggdrasillUtility . buildListOptions ( 0 , this . getCurrentFuror ( ) ) ,
furorUsage : 0 ,
optionsSR : YggdrasillUtility . buildSROptions ( ) ,
sr : 14 ,
puissanceRune : 1 ,
optionsPuissanceRune : YggdrasillUtility . buildListOptions ( 1 , 15 ) ,
supportRune : "peau" ,
}
let rollDialog = await YggdrasillRoll . create ( this , rollData ) ;
console . log ( rollDialog ) ;
rollDialog . render ( true ) ;
} else {
ui . notifications . warn ( "Sortilège ou Compétence non trouvée !" , sort , compName ) ;
}
}
/* -------------------------------------------- */
async rollArme ( armeId ) {
2022-09-21 11:42:09 +02:00
let arme = this . items . find ( item => item . id == armeId ) ;
let compName = armeCategorieToCompetence [ arme . system . categorie ] ;
let competence = this . items . find ( item => item . type == 'competence' && item . name == compName ) ;
2022-01-09 09:33:47 +01:00
console . log ( "ARME :" , armeId , arme , competence ) ;
if ( arme && competence ) {
let attackDef
if ( arme . type == 'armecc' ) {
attackDef = this . getAttaqueData ( "classique" ) ;
} else {
attackDef = this . getTirData ( "pose" ) ;
}
let rollData = {
mode : arme . type ,
attackDef : attackDef ,
alias : this . name ,
actorImg : this . img ,
actorId : this . id ,
img : competence . img ,
rollMode : game . settings . get ( "core" , "rollMode" ) ,
title : "Attaque !" ,
2022-09-21 11:42:09 +02:00
selectedCarac : duplicate ( this . system . carac . corps . carac . agilite ) ,
2022-01-09 09:33:47 +01:00
arme : duplicate ( arme ) ,
competence : duplicate ( competence ) ,
bonusdefense : 0 ,
isEpuise : this . isEpuise ( ) ,
isBlesse : this . isBlesse ( ) ,
isMeurtri : this . isMeurtri ( ) ,
2022-01-23 00:07:47 +01:00
optionsBonusMalus : YggdrasillUtility . buildListOptions ( - 15 , + 15 ) ,
optionsBD : YggdrasillUtility . buildListOptions ( 0 , + 15 ) ,
2022-01-09 09:33:47 +01:00
bonusMalus : 0 ,
optionsFuror : YggdrasillUtility . buildListOptions ( 0 , this . getCurrentFuror ( ) ) ,
furorUsage : 0 ,
optionsSR : YggdrasillUtility . buildSROptions ( ) ,
sr : 14
}
let rollDialog = await YggdrasillRoll . create ( this , rollData ) ;
console . log ( rollDialog ) ;
rollDialog . render ( true ) ;
} else {
ui . notifications . warn ( "Arme ou Compétence Martiale non trouvée !" , arme , compName ) ;
}
}
/* -------------------------------------------- */
getEncTotal ( ) {
let encTotal = 0 ;
2022-09-21 11:42:09 +02:00
for ( let item of this . items ) {
2022-02-21 22:51:38 +01:00
if ( item . type == "equipement" || item . type == "armecc"
|| item . type == "armedist" || item . type == "armure" || item . type == "monnaie" || item . type == "bouclier" ) {
2022-09-21 11:42:09 +02:00
encTotal += ( item . system . enc * item . system . quantite ) ;
2022-02-21 22:51:38 +01:00
}
}
2022-09-21 11:42:09 +02:00
for ( let item of this . items ) {
if ( item . type == "bouclier" && item . system . equipe ) {
encTotal -= ( item . system . enc * item . system . quantite ) ;
encTotal += ( item . system . enccomb * item . system . quantite ) ;
2022-01-09 09:33:47 +01:00
}
}
return encTotal ;
2022-02-21 22:51:38 +01:00
}
2022-01-09 09:33:47 +01:00
/* -------------------------------------------- */
getProtectionTotal ( ) {
let protectionTotal = 0 ;
2022-09-21 11:42:09 +02:00
for ( let item of this . items ) {
if ( item . type == "armure" && item . system . equipe ) {
protectionTotal += Number ( item . system . protection ) ;
2022-01-09 09:33:47 +01:00
}
}
return protectionTotal ;
}
2022-02-21 22:51:38 +01:00
/* -------------------------------------------- */
getDpBouclier ( ) {
let dpBouclier = 0 ;
2022-09-21 11:42:09 +02:00
for ( let item of this . items ) {
if ( item . type == "bouclier" && item . system . equipe ) {
dpBouclier += Number ( item . system . defensebonus ) ;
2022-02-21 22:51:38 +01:00
}
}
return dpBouclier ;
}
2022-01-09 09:33:47 +01:00
/* -------------------------------------------- */
async incrementeQuantite ( objetId ) {
2022-09-21 11:42:09 +02:00
let objetQ = this . items . find ( item => item . id == objetId ) ;
2022-01-09 09:33:47 +01:00
if ( objetQ ) {
2022-09-21 11:42:09 +02:00
let newQ = objetQ . system . quantite + 1 ;
const updated = await this . updateEmbeddedDocuments ( 'Item' , [ { _id : objetQ . id , 'system.quantite' : newQ } ] ) ; // pdates one EmbeddedEntity
2022-01-09 09:33:47 +01:00
}
}
/* -------------------------------------------- */
async decrementeQuantite ( objetId ) {
2022-09-21 11:42:09 +02:00
let objetQ = this . items . find ( item => item . id == objetId ) ;
2022-01-09 09:33:47 +01:00
if ( objetQ ) {
2022-09-21 11:42:09 +02:00
let newQ = objetQ . system . quantite - 1 ;
2022-01-09 09:33:47 +01:00
newQ = ( newQ <= 0 ) ? 0 : newQ ;
2022-09-21 11:42:09 +02:00
const updated = await this . updateEmbeddedDocuments ( 'Item' , [ { _id : objetQ . id , 'system.quantite' : newQ } ] ) ; // pdates one EmbeddedEntity
2022-01-09 09:33:47 +01:00
}
}
}