2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
import { HawkmoonUtility } from "./hawkmoon-utility.js" ;
import { HawkmoonRollDialog } from "./hawkmoon-roll-dialog.js" ;
/* -------------------------------------------- */
const _ _degatsBonus = [ - 2 , - 2 , - 1 , - 1 , 0 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 6 , 6 , 8 , 8 , 9 , 9 , 10 , 10 ]
const _ _vitesseBonus = [ - 2 , - 2 , - 1 , - 1 , 0 , 0 , 0 , 1 , 1 , 2 , 2 , 3 , 3 , 4 , 4 , 5 , 5 , 6 , 6 , 7 , 7 , 8 ]
/* -------------------------------------------- */
/ * *
* Extend the base Actor entity by defining a custom roll data structure which is ideal for the Simple system .
* @ extends { Actor }
* /
export class HawkmoonActor 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 ;
}
if ( data . type == 'personnage' ) {
const skills = await HawkmoonUtility . loadCompendium ( "fvtt-hawkmoon-cyd.skills" )
data . items = skills . map ( i => i . toObject ( ) )
}
2022-12-21 19:15:03 +01:00
if ( data . type == 'creature' ) {
const skills = await HawkmoonUtility . loadCompendium ( "fvtt-hawkmoon-cyd.skills-creatures" )
data . items = skills . map ( i => i . toObject ( ) )
2023-03-19 18:58:28 +01:00
data . items . push ( { name : "Arme naturelle 1" , type : 'arme' , img : "systems/fvtt-hawkmoon-cyd/assets/icons/melee.webp" , system : { typearme : "contact" , bonusmaniementoff : 0 , seuildefense : 0 , degats : "0" } } )
data . items . push ( { name : "Arme naturelle 2" , type : 'arme' , img : "systems/fvtt-hawkmoon-cyd/assets/icons/melee.webp" , system : { typearme : "contact" , bonusmaniementoff : 0 , seuildefense : 0 , degats : "0" } } )
2022-10-22 11:09:48 +02:00
}
return super . create ( data , options ) ;
}
2022-11-29 10:54:56 +01:00
/* -------------------------------------------- */
getBonusDefenseFromTalents ( ) {
let talents = this . items . filter ( item => item . type == "talent" && item . system . isautomated )
let bonus = 0
for ( let talent of talents ) {
for ( let auto of talent . system . automations ) {
if ( auto . eventtype == "bonus-permanent" && auto . bonusname == "bonus-defensif" ) {
bonus += Number ( auto . bonus || 0 )
}
}
}
return bonus
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
prepareArme ( arme ) {
2024-05-02 09:27:16 +02:00
arme = foundry . utils . duplicate ( arme )
2022-10-22 11:09:48 +02:00
let combat = this . getCombatValues ( )
if ( arme . system . typearme == "contact" || arme . system . typearme == "contactjet" ) {
2022-11-29 10:54:56 +01:00
let bonusDefense = this . getBonusDefenseFromTalents ( )
2024-05-02 09:27:16 +02:00
arme . system . competence = foundry . utils . duplicate ( this . items . find ( item => item . type == "competence" && item . name . toLowerCase ( ) == "mêlée" ) )
2022-10-22 11:09:48 +02:00
arme . system . attrKey = "pui"
arme . system . totalDegats = arme . system . degats + "+" + combat . bonusDegatsTotal
2024-05-02 09:27:16 +02:00
arme . system . totalOffensif = this . system . attributs . pui . value + arme . system . competence . system . niveau + arme . system . bonusmaniementoff + ( this . system . combat . monte ? 3 : 0 )
arme . system . totalDefensif = combat . defenseTotal + arme . system . competence . system . niveau + arme . system . seuildefense + bonusDefense + ( this . system . combat . monte ? 3 : 0 )
2024-02-15 11:47:15 +01:00
console . log ( "Arme" , arme . system . totalDefensif , combat , arme . system . competence . system . niveau , arme . system . seuildefense , bonusDefense )
2022-11-10 11:04:05 +01:00
arme . system . isdefense = true
2023-04-24 22:20:47 +02:00
arme . system . isMelee = true
arme . system . isDistance = false
2022-10-22 11:09:48 +02:00
}
if ( arme . system . typearme == "jet" || arme . system . typearme == "tir" ) {
2024-05-02 09:27:16 +02:00
arme . system . competence = foundry . utils . duplicate ( this . items . find ( item => item . type == "competence" && item . name . toLowerCase ( ) == "armes à distance" ) )
2022-10-22 11:09:48 +02:00
arme . system . attrKey = "adr"
arme . system . totalOffensif = this . system . attributs . adr . value + arme . system . competence . system . niveau + arme . system . bonusmaniementoff
arme . system . totalDegats = arme . system . degats
2023-04-24 22:20:47 +02:00
arme . system . isMelee = false
arme . system . isDistance = true
2022-10-22 11:09:48 +02:00
if ( arme . system . isdefense ) {
2022-11-10 11:04:05 +01:00
arme . system . totalDefensif = combat . defenseTotal + arme . system . competence . system . niveau + arme . system . seuildefense
2022-10-22 11:09:48 +02:00
}
}
return arme
}
2022-10-25 17:54:13 +02:00
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
2023-03-19 18:58:28 +01:00
getItemSorted ( types ) {
let items = this . items . filter ( item => types . includes ( item . type ) ) || [ ]
HawkmoonUtility . sortArrayObjectsByName ( items )
return items
}
2022-10-22 11:09:48 +02:00
getWeapons ( ) {
let armes = [ ]
for ( let arme of this . items ) {
if ( arme . type == "arme" ) {
armes . push ( this . prepareArme ( arme ) )
}
}
2023-03-19 18:58:28 +01:00
HawkmoonUtility . sortArrayObjectsByName ( armes )
2022-10-22 11:09:48 +02:00
return armes
}
2022-11-14 15:27:19 +01:00
getMonnaies ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "monnaie" ] )
2022-11-10 23:43:51 +01:00
}
2022-10-22 11:09:48 +02:00
getEquipments ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "equipement" ] )
2022-10-22 11:09:48 +02:00
}
2022-12-06 07:27:51 +01:00
getArtefacts ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "artefact" ] )
2023-12-28 18:40:46 +01:00
}
2022-10-22 11:09:48 +02:00
getArmors ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "protection" ] )
2022-10-22 11:09:48 +02:00
}
2022-12-11 18:42:16 +01:00
getHistoriques ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "historique" ] )
2022-10-22 11:09:48 +02:00
}
2022-11-09 23:48:08 +01:00
getProfils ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "profil" ] )
2022-10-22 11:09:48 +02:00
}
2022-10-23 21:26:18 +02:00
getTalents ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "talent" ] )
2022-10-22 11:09:48 +02:00
}
2022-11-10 23:43:51 +01:00
getRessources ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "ressource" ] )
2022-11-10 23:43:51 +01:00
}
getContacts ( ) {
2023-03-19 18:58:28 +01:00
return this . getItemSorted ( [ "contact" ] )
2022-11-10 23:43:51 +01:00
}
2024-02-24 15:54:47 +01:00
getMutations ( ) {
return this . getItemSorted ( [ "mutation" ] )
}
2023-03-19 18:58:28 +01:00
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
getSkills ( ) {
let comp = [ ]
for ( let item of this . items ) {
2024-05-02 09:27:16 +02:00
item = foundry . utils . duplicate ( item )
2022-10-22 11:09:48 +02:00
if ( item . type == "competence" ) {
item . system . attribut1total = item . system . niveau + ( this . system . attributs [ item . system . attribut1 ] ? . value || 0 )
item . system . attribut2total = item . system . niveau + ( this . system . attributs [ item . system . attribut2 ] ? . value || 0 )
item . system . attribut3total = item . system . niveau + ( this . system . attributs [ item . system . attribut3 ] ? . value || 0 )
if ( item . system . niveau == 0 ) {
item . system . attribut1total -= 3
item . system . attribut2total -= 3
item . system . attribut3total -= 3
}
item . system . attribut1label = this . system . attributs [ item . system . attribut1 ] ? . label || ""
item . system . attribut2label = this . system . attributs [ item . system . attribut2 ] ? . label || ""
item . system . attribut3label = this . system . attributs [ item . system . attribut3 ] ? . label || ""
comp . push ( item )
}
}
2023-03-19 18:58:28 +01:00
HawkmoonUtility . sortArrayObjectsByName ( comp )
return comp
}
/* ----------------------- --------------------- */
addMember ( actorId ) {
2024-05-02 09:27:16 +02:00
let members = foundry . utils . duplicate ( this . system . members )
2023-03-19 18:58:28 +01:00
members . push ( { id : actorId } )
this . update ( { 'system.members' : members } )
}
async removeMember ( actorId ) {
let members = this . system . members . filter ( it => it . id != actorId )
this . update ( { 'system.members' : members } )
2022-10-22 11:09:48 +02:00
}
/* -------------------------------------------- */
getDefenseBase ( ) {
2024-02-15 11:47:15 +01:00
return Math . max ( this . system . attributs . tre . value , this . system . attributs . adr . value )
2022-10-22 11:09:48 +02:00
}
/* -------------------------------------------- */
getVitesseBase ( ) {
return 5 + _ _vitesseBonus [ this . system . attributs . adr . value ]
}
2022-11-10 11:04:05 +01:00
/* -------------------------------------------- */
getProtection ( ) {
let equipProtection = 0
2024-02-15 11:47:15 +01:00
for ( let armor of this . items ) {
2022-11-10 11:04:05 +01:00
if ( armor . type == "protection" && armor . system . equipped ) {
equipProtection += Number ( armor . system . protection )
}
}
if ( equipProtection < 4 ) {
return 4 + equipProtection // Cas des boucliers + sans armure
}
return equipProtection // Uniquement la protection des armures + boucliers
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
getCombatValues ( ) {
let combat = {
initBase : this . system . attributs . adr . value ,
initTotal : this . system . attributs . adr . value + this . system . combat . initbonus ,
bonusDegats : this . getBonusDegats ( ) ,
bonusDegatsTotal : this . getBonusDegats ( ) + this . system . combat . bonusdegats ,
vitesseBase : this . getVitesseBase ( ) ,
vitesseTotal : this . getVitesseBase ( ) + this . system . combat . vitessebonus ,
defenseBase : this . getDefenseBase ( ) ,
2023-03-19 18:58:28 +01:00
protection : this . getProtection ( ) ,
2024-04-01 22:48:18 +02:00
defenseTotal : this . getDefenseBase ( ) + this . system . combat . defensebonus + this . getProtection ( ) - this . getTotalAdversite ( ) + ( this . system . combat . defensetotale ? 3 : 0 )
2022-10-22 11:09:48 +02:00
}
return combat
}
/* -------------------------------------------- */
prepareBaseData ( ) {
}
/* -------------------------------------------- */
async prepareData ( ) {
super . prepareData ( ) ;
}
/* -------------------------------------------- */
prepareDerivedData ( ) {
if ( this . type == 'personnage' ) {
2022-11-29 10:54:56 +01:00
let talentBonus = this . getVigueurBonus ( )
2023-08-16 10:51:19 +02:00
let vigueur = Math . floor ( ( this . system . attributs . pui . value + this . system . attributs . tre . value ) / 2 ) + talentBonus + this . system . sante . vigueurmodifier
2022-10-25 17:54:13 +02:00
if ( vigueur != this . system . sante . vigueur ) {
2022-11-10 11:04:05 +01:00
this . update ( { 'system.sante.vigueur' : vigueur } )
2022-10-25 17:54:13 +02:00
}
2022-10-22 11:09:48 +02:00
}
super . prepareDerivedData ( )
}
/* -------------------------------------------- */
_preUpdate ( changed , options , user ) {
2024-05-05 18:06:29 +02:00
if ( changed ? . system ? . sante ? . etat && changed ? . system ? . sante ? . etat != this . system . sante . etat ) {
setTimeout ( ( ) => {
this . processCombativite ( changed . system . sante )
} , 800 )
}
2022-10-22 11:09:48 +02:00
super . _preUpdate ( changed , options , user ) ;
}
2024-05-05 18:06:29 +02:00
/* -------------------------------------------- */
_onUpdate ( data , options , user ) {
super . _onUpdate ( data , options , user ) ;
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
getItemById ( id ) {
let item = this . items . find ( item => item . id == id ) ;
if ( item ) {
2024-05-02 09:27:16 +02:00
item = foundry . utils . duplicate ( item )
2022-10-22 11:09:48 +02:00
}
return item ;
}
/* -------------------------------------------- */
async equipItem ( itemId ) {
let item = this . items . find ( item => item . id == itemId )
if ( item && item . system ) {
let update = { _id : item . id , "system.equipped" : ! item . system . equipped }
await this . updateEmbeddedDocuments ( 'Item' , [ update ] ) ; // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
editItemField ( itemId , itemType , itemField , dataType , value ) {
let item = this . items . find ( item => item . id == itemId )
if ( item ) {
console . log ( "Item " , item , itemField , dataType , value )
if ( dataType . toLowerCase ( ) == "number" ) {
value = Number ( value )
} else {
value = String ( value )
}
let update = { _id : item . id , [ ` system. ${ itemField } ` ] : value } ;
this . updateEmbeddedDocuments ( "Item" , [ update ] )
}
}
2022-10-28 21:44:49 +02:00
/* -------------------------------------------- */
2022-11-10 11:04:05 +01:00
checkAttribut ( attribut , minLevel ) {
let attr = this . system . attributs . find ( at => at . labelnorm == attribut . toLowerCase ( ) )
2022-10-28 21:44:49 +02:00
if ( attr && attr . value >= minLevel ) {
2024-05-02 09:27:16 +02:00
return { isValid : true , attr : foundry . utils . duplicate ( attr ) }
2022-10-28 21:44:49 +02:00
}
2022-11-10 11:04:05 +01:00
return { isValid : false }
2022-10-28 21:44:49 +02:00
}
/* -------------------------------------------- */
2022-11-09 23:39:55 +01:00
checkAttributOrCompetenceLevel ( compName , minLevel ) {
2022-10-28 21:44:49 +02:00
let comp = this . items . find ( i => i . type == "competence" && i . name . toLowerCase ( ) == compName . toLowerCase ( ) && i . system . niveau >= minLevel )
2022-11-10 11:04:05 +01:00
if ( comp ) {
2024-05-02 09:27:16 +02:00
return { isValid : true , item : foundry . utils . duplicate ( comp ) }
2022-11-09 23:39:55 +01:00
} else {
for ( let attrKey in this . system . attributs ) {
2022-11-10 11:04:05 +01:00
if ( this . system . attributs [ attrKey ] . label . toLowerCase ( ) == compName . toLowerCase ( ) && this . system . attributs [ attrKey ] . value >= minLevel ) {
2024-05-02 09:27:16 +02:00
return { isValid : true , item : foundry . utils . duplicate ( this . system . attributs [ attrKey ] ) }
2022-11-09 23:39:55 +01:00
}
}
2022-10-28 21:44:49 +02:00
}
2022-11-10 11:04:05 +01:00
return { isValid : false , warningMessage : ` Prérequis insuffisant : la compétence/attribut ${ compName } doit être de niveau ${ minLevel } au minimum ` }
2022-10-28 21:44:49 +02:00
}
/* -------------------------------------------- */
2022-11-05 10:03:23 +01:00
addCompetenceBonus ( compName , bonus , baCost ) {
let comp = this . items . find ( i => i . type == "competence" && i . name . toLowerCase ( ) == compName . toLowerCase ( ) )
2022-11-10 11:04:05 +01:00
if ( comp ) {
2024-05-02 09:27:16 +02:00
comp = foundry . utils . duplicate ( comp )
2022-11-05 10:03:23 +01:00
comp . system . bonus = bonus
comp . system . baCost = baCost
2022-11-10 11:04:05 +01:00
return { isValid : true , item : comp }
2022-11-05 10:03:23 +01:00
}
2022-11-10 11:04:05 +01:00
return { isValid : false , warningMessage : ` Compétence ${ compName } non trouvée ` }
2022-11-05 10:03:23 +01:00
}
/* -------------------------------------------- */
2022-11-10 11:04:05 +01:00
checkIfCompetence ( compName ) {
2022-10-28 21:44:49 +02:00
let comp = this . items . find ( i => i . type == "competence" && i . name . toLowerCase ( ) == compName . toLowerCase ( ) )
2022-11-10 11:04:05 +01:00
if ( comp ) {
return { isValid : true , item : comp }
2022-10-28 21:44:49 +02:00
}
2022-11-10 11:04:05 +01:00
return { isValid : false }
2022-10-28 21:44:49 +02:00
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
2022-11-13 23:01:41 +01:00
getVigueur ( ) {
return this . system . sante . vigueur
}
2022-11-29 10:54:56 +01:00
/* -------------------------------------------- */
getVigueurBonus ( ) {
let talents = this . items . filter ( item => item . type == "talent" && item . system . isautomated )
let bonus = 0
for ( let talent of talents ) {
for ( let auto of talent . system . automations ) {
if ( auto . eventtype == "bonus-permanent" && auto . bonusname == "vigueur" ) {
bonus += Number ( auto . bonus || 0 )
}
}
}
return bonus
}
2022-11-13 23:01:41 +01:00
/* -------------------------------------------- */
2022-10-22 11:09:48 +02:00
getBonneAventure ( ) {
return this . system . bonneaventure . actuelle
}
2022-11-05 10:03:23 +01:00
/* -------------------------------------------- */
checkBonneAventure ( cost ) {
return ( this . system . bonneaventure . actuelle >= cost )
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
changeBonneAventure ( value ) {
let newBA = this . system . bonneaventure . actuelle
newBA += value
this . update ( { 'system.bonneaventure.actuelle' : newBA } )
}
/* -------------------------------------------- */
getEclat ( ) {
return this . system . eclat . value
}
/* -------------------------------------------- */
changeEclat ( value ) {
let newE = this . system . eclat . value
newE += value
this . update ( { 'system.eclat.value' : newE } )
}
/* -------------------------------------------- */
compareName ( a , b ) {
if ( a . name < b . name ) {
return - 1 ;
}
if ( a . name > b . name ) {
return 1 ;
}
return 0 ;
}
/* -------------------------------------------- */
getAttribute ( attrKey ) {
return this . system . attributes [ attrKey ]
}
/* -------------------------------------------- */
getBonusDegats ( ) {
2023-03-19 18:58:28 +01:00
return 0 ;
2022-10-22 11:09:48 +02:00
}
2023-12-28 18:40:46 +01:00
/* -------------------------------------------- */
changeEtatCombativite ( value ) {
2024-05-02 09:27:16 +02:00
if ( value === "vaincu" ) {
2024-04-01 22:48:18 +02:00
value = 200
}
2024-05-02 09:27:16 +02:00
let sante = foundry . utils . duplicate ( this . system . sante )
2023-12-28 18:40:46 +01:00
sante . etat += Number ( value )
sante . etat = Math . max ( sante . etat , 0 )
2024-05-05 18:06:29 +02:00
sante . etat = Math . min ( sante . etat , this . system . sante . nbcombativite )
2023-12-28 18:40:46 +01:00
this . update ( { 'system.sante' : sante } )
if ( sante . etat == this . system . sante . nbcombativite ) {
ChatMessage . create ( { content : ` <strong> ${ this . name } est vaincu !</strong> ` } )
}
2024-05-05 18:06:29 +02:00
this . processCombativite ( sante )
}
/* -------------------------------------------- */
processCombativite ( sante ) {
sante = sante || foundry . utils . duplicate ( this . system . sante )
2023-12-28 18:40:46 +01:00
// Gestion des états affaibli et très affaibli
2024-05-02 09:27:16 +02:00
if ( sante . etat == this . system . sante . nbcombativite - 2 || sante . etat == this . system . sante . nbcombativite - 1 ) {
if ( sante . etat == this . system . sante . nbcombativite - 2 && this . items . find ( item => item . type == "talent" && item . name . toLowerCase ( ) == "encaissement" ) ) {
2023-12-28 18:40:46 +01:00
ChatMessage . create ( { content : ` <strong> ${ this . name } ne subit pas les 2 adversités rouge grâce à Encaissement. Pensez à les ajouter à la fin de la scène !</strong> ` } )
2024-05-02 09:27:16 +02:00
} else if ( sante . etat == this . system . sante . nbcombativite - 1 && this . items . find ( item => item . type == "talent" && item . name . toLowerCase ( ) . includes ( "vaillant" ) ) ) {
2023-12-28 18:40:46 +01:00
ChatMessage . create ( { content : ` <strong> ${ this . name } ne subit pas les 2 adversités rouge grâce à Vaillant. Pensez à les ajouter à la fin de la scène !</strong> ` } )
} else {
ChatMessage . create ( { content : ` <strong> ${ this . name } subit 2 adversités rouge !</strong> ` } )
this . incDecAdversite ( "rouge" , 2 )
}
}
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
async equipGear ( equipmentId ) {
let item = this . items . find ( item => item . id == equipmentId ) ;
2023-12-28 18:40:46 +01:00
if ( item ? . system ? . data ) {
2022-10-22 11:09:48 +02:00
let update = { _id : item . id , "system.equipped" : ! item . system . equipped } ;
await this . updateEmbeddedDocuments ( 'Item' , [ update ] ) ; // Updates one EmbeddedEntity
}
}
/* -------------------------------------------- */
getSubActors ( ) {
let subActors = [ ] ;
for ( let id of this . system . subactors ) {
2024-05-02 09:27:16 +02:00
subActors . push ( foundry . utils . duplicate ( game . actors . get ( id ) ) ) ;
2022-10-22 11:09:48 +02:00
}
return subActors ;
}
/* -------------------------------------------- */
async addSubActor ( subActorId ) {
2024-05-02 09:27:16 +02:00
let subActors = foundry . utils . duplicate ( this . system . subactors ) ;
2022-10-22 11:09:48 +02:00
subActors . push ( subActorId ) ;
await this . update ( { 'system.subactors' : subActors } ) ;
}
/* -------------------------------------------- */
async delSubActor ( subActorId ) {
let newArray = [ ] ;
for ( let id of this . system . subactors ) {
if ( id != subActorId ) {
newArray . push ( id ) ;
}
}
await this . update ( { 'system.subactors' : newArray } ) ;
}
2022-11-10 11:04:05 +01:00
/* -------------------------------------------- */
getTotalAdversite ( ) {
return this . system . adversite . bleue + this . system . adversite . rouge + this . system . adversite . noire
}
/* -------------------------------------------- */
async incDecAdversite ( adv , incDec = 0 ) {
2024-05-02 09:27:16 +02:00
let adversite = foundry . utils . duplicate ( this . system . adversite )
2022-11-10 11:04:05 +01:00
adversite [ adv ] += Number ( incDec )
adversite [ adv ] = Math . max ( adversite [ adv ] , 0 )
2024-05-05 18:06:29 +02:00
adversite [ adv ] = Math . min ( adversite [ adv ] , 20 )
2022-11-10 11:04:05 +01:00
this . update ( { 'system.adversite' : adversite } )
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
async incDecQuantity ( objetId , incDec = 0 ) {
let objetQ = this . items . get ( objetId )
if ( objetQ ) {
2022-12-03 23:57:30 +01:00
let newQ = objetQ . system . quantite + incDec
2022-11-10 11:04:05 +01:00
newQ = Math . max ( newQ , 0 )
2023-12-28 18:40:46 +01:00
await this . updateEmbeddedDocuments ( 'Item' , [ { _id : objetQ . id , 'system.quantite' : newQ } ] ) ; // pdates one EmbeddedEntity
2022-12-03 23:57:30 +01:00
}
}
/* -------------------------------------------- */
computeRichesse ( ) {
let valueSC = 0
2023-03-19 18:58:28 +01:00
for ( let monnaie of this . items ) {
2022-12-03 23:57:30 +01:00
if ( monnaie . type == "monnaie" ) {
2023-03-19 18:58:28 +01:00
valueSC += Number ( monnaie . system . prixsc ) * Number ( monnaie . system . quantite )
2022-12-03 23:57:30 +01:00
}
2022-10-22 11:09:48 +02:00
}
2023-03-19 18:58:28 +01:00
return HawkmoonUtility . computeMonnaieDetails ( valueSC )
2022-10-22 11:09:48 +02:00
}
2022-12-03 23:57:30 +01:00
/* -------------------------------------------- */
computeValeurEquipement ( ) {
let valueSC = 0
2023-03-19 18:58:28 +01:00
for ( let equip of this . items ) {
2022-12-03 23:57:30 +01:00
if ( equip . type == "equipement" || equip . type == "arme" || equip . type == "protection" ) {
2023-03-19 18:58:28 +01:00
valueSC += Number ( equip . system . prixsc ) * Number ( equip . system . quantite ? ? 1 )
valueSC += ( Number ( equip . system . prixca ) * Number ( equip . system . quantite ? ? 1 ) ) * 20
valueSC += ( Number ( equip . system . prixpo ) * Number ( equip . system . quantite ? ? 1 ) ) * 400
2022-12-03 23:57:30 +01:00
}
}
2023-03-19 18:58:28 +01:00
return HawkmoonUtility . computeMonnaieDetails ( valueSC )
2022-12-03 23:57:30 +01:00
}
2023-03-19 18:58:28 +01:00
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
getCompetence ( compId ) {
return this . items . get ( compId )
}
/* -------------------------------------------- */
async setPredilectionUsed ( compId , predIdx ) {
let comp = this . items . get ( compId )
2024-05-02 09:27:16 +02:00
let pred = foundry . utils . duplicate ( comp . system . predilections )
2022-10-22 11:09:48 +02:00
pred [ predIdx ] . used = true
await this . updateEmbeddedDocuments ( 'Item' , [ { _id : compId , 'system.predilections' : pred } ] )
}
/* -------------------------------------------- */
2022-11-10 11:04:05 +01:00
getInitiativeScore ( ) {
2022-11-29 10:54:56 +01:00
let init = this . getFlag ( "world" , "last-initiative" )
return init || - 1
2022-10-22 11:09:48 +02:00
}
2022-11-13 23:01:41 +01:00
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
getBestDefenseValue ( ) {
2022-11-10 23:43:51 +01:00
let defenseList = this . items . filter ( item => ( item . type == "arme" ) && item . system . equipped )
2022-10-22 11:09:48 +02:00
let maxDef = 0
let bestArme
2022-11-10 11:04:05 +01:00
for ( let arme of defenseList ) {
2023-03-19 18:58:28 +01:00
if ( arme . type == "arme" ) {
2022-10-22 11:09:48 +02:00
arme = this . prepareArme ( arme )
}
2022-11-10 11:04:05 +01:00
if ( arme . system . totalDefensif > maxDef ) {
2022-10-22 11:09:48 +02:00
maxDef = arme . system . totalDefensif
2024-05-02 09:27:16 +02:00
bestArme = foundry . utils . duplicate ( arme )
2022-10-22 11:09:48 +02:00
}
}
return bestArme
}
2022-10-28 21:44:49 +02:00
/* -------------------------------------------- */
searchRelevantTalents ( competence ) {
let talents = [ ]
2022-11-10 11:04:05 +01:00
for ( let talent of this . items ) {
2022-10-28 21:44:49 +02:00
if ( talent . type == "talent" && talent . system . isautomated && talent . system . automations . length > 0 ) {
for ( let auto of talent . system . automations ) {
2022-11-05 10:03:23 +01:00
if ( auto . eventtype === "prepare-roll" ) {
2022-11-10 11:04:05 +01:00
if ( auto . competence . toLowerCase ( ) == competence . name . toLowerCase ( ) ) {
2024-05-02 09:27:16 +02:00
talent = foundry . utils . duplicate ( talent )
2022-11-10 11:04:05 +01:00
talent . system . bonus = auto . bonus
2022-11-05 10:03:23 +01:00
talent . system . baCost = auto . baCost
2022-11-10 11:04:05 +01:00
talents . push ( talent )
2022-10-28 21:44:49 +02:00
}
}
}
}
}
return talents
}
2022-12-03 23:13:08 +01:00
/* -------------------------------------------- */
buildListeAdversites ( ) {
return [ ]
}
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
getCommonRollData ( attrKey = undefined , compId = undefined , compName = undefined ) {
let rollData = HawkmoonUtility . getBasicRollData ( )
rollData . alias = this . name
rollData . actorImg = this . img
rollData . actorId = this . id
2022-11-29 10:54:56 +01:00
rollData . tokenId = this . token ? . id
2022-10-22 11:09:48 +02:00
rollData . img = this . img
rollData . attributs = HawkmoonUtility . getAttributs ( )
2022-10-25 17:54:13 +02:00
rollData . maitriseId = "none"
2022-11-10 11:04:05 +01:00
rollData . nbEclat = this . system . eclat . value
2022-10-25 17:54:13 +02:00
rollData . nbBA = this . system . bonneaventure . actuelle
2022-11-10 11:04:05 +01:00
rollData . nbAdversites = this . getTotalAdversite ( )
rollData . talents = [ ]
2023-12-28 18:40:46 +01:00
rollData . attrKey2 = "none"
2024-05-02 09:27:16 +02:00
rollData . coupDevastateur = this . items . find ( it => it . type == "talent" && it . name . toLowerCase ( ) == "coup dévastateur" && ! it . system . used )
2024-04-01 22:48:18 +02:00
rollData . hasAmbidextre = this . items . find ( it => it . type == "talent" && it . name . toLowerCase ( ) == "ambidextre" )
2024-05-02 09:27:16 +02:00
rollData . hasFeinte = this . system . bonneaventure . actuelle > 0 && this . items . find ( it => it . type == "talent" && it . name . toLowerCase ( ) == "feinte" )
2024-04-01 22:48:18 +02:00
rollData . isMonte = this . system . combat . monte
2024-05-02 09:27:16 +02:00
rollData . config = game . system . hawkmoon . config
2022-10-22 11:09:48 +02:00
if ( attrKey ) {
rollData . attrKey = attrKey
if ( attrKey != "tochoose" ) {
2022-11-10 11:04:05 +01:00
rollData . actionImg = "systems/fvtt-hawkmoon-cyd/assets/icons/" + this . system . attributs [ attrKey ] . labelnorm + ".webp"
2024-05-02 09:27:16 +02:00
rollData . attr = foundry . utils . duplicate ( this . system . attributs [ attrKey ] )
2022-10-22 11:09:48 +02:00
}
}
if ( compId ) {
2024-05-02 09:27:16 +02:00
rollData . competence = foundry . utils . duplicate ( this . items . get ( compId ) || { } )
2024-05-05 18:06:29 +02:00
let maitrises = [ { key : "none" , label : "Aucune" } ]
rollData . competence . system . predilections . forEach ( function ( item ) {
if ( item . maitrise ) {
maitrises . push ( { key : item . id , label : item . name } ) ;
2024-05-02 09:27:16 +02:00
}
} )
rollData . maitrises = maitrises // rollData.competence.system.predilections.filter(p => p.maitrise)
2022-11-10 11:04:05 +01:00
rollData . actionImg = rollData . competence ? . img
rollData . talents = this . searchRelevantTalents ( rollData . competence )
2022-10-22 11:09:48 +02:00
}
if ( compName ) {
2024-05-02 09:27:16 +02:00
rollData . competence = foundry . utils . duplicate ( this . items . find ( item => item . name . toLowerCase ( ) == compName . toLowerCase ( ) ) || { } )
2022-10-22 11:09:48 +02:00
rollData . actionImg = rollData . competence ? . img
}
return rollData
}
/* -------------------------------------------- */
2022-11-13 23:01:41 +01:00
async rollAttribut ( attrKey , isInit = false ) {
2023-03-19 18:58:28 +01:00
let rollData = this . getCommonRollData ( attrKey )
rollData . multiplier = ( isInit ) ? 1 : 2
2022-11-13 23:01:41 +01:00
rollData . isInit = isInit
2022-10-22 11:09:48 +02:00
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
/* -------------------------------------------- */
async rollCompetence ( attrKey , compId ) {
let rollData = this . getCommonRollData ( attrKey , compId )
2022-11-10 23:43:51 +01:00
rollData . multiplier = 1 // Attr multiplier, always 1 in competence mode
2022-10-22 11:09:48 +02:00
console . log ( "RollDatra" , rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
/* -------------------------------------------- */
async rollArmeOffensif ( armeId ) {
let arme = this . items . get ( armeId )
if ( arme . type == "arme" ) {
arme = this . prepareArme ( arme )
}
let rollData = this . getCommonRollData ( arme . system . attrKey , arme . system . competence . _id )
rollData . arme = arme
2022-11-29 10:54:56 +01:00
HawkmoonUtility . updateWithTarget ( rollData )
2022-10-22 11:09:48 +02:00
console . log ( "ARME!" , rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
2024-04-01 22:48:18 +02:00
/* -------------------------------------------- */
async rollAssomer ( ) {
let rollData = this . getCommonRollData ( "pui" , undefined , "Filouterie" )
rollData . assomer = true
rollData . conditionsCommunes = true
HawkmoonUtility . updateWithTarget ( rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
/* -------------------------------------------- */
async rollCoupBas ( ) {
let rollData = this . getCommonRollData ( "pui" , undefined , "Mêlée" )
rollData . coupBas = true
rollData . conditionsCommunes = true
HawkmoonUtility . updateWithTarget ( rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
/* -------------------------------------------- */
async rollImmobiliser ( ) {
let rollData = this . getCommonRollData ( "pui" , undefined , "Mêlée" )
rollData . immobiliser = true
rollData . conditionsCommunes = true
rollData . cibleconsciente = true
HawkmoonUtility . updateWithTarget ( rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
/* -------------------------------------------- */
async rollRepousser ( ) {
let rollData = this . getCommonRollData ( "pui" , undefined , "Mêlée" )
rollData . repousser = true
rollData . conditionsCommunes = true
rollData . cibleconsciente = true
HawkmoonUtility . updateWithTarget ( rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
/* -------------------------------------------- */
async rollDesengager ( ) {
let rollData = this . getCommonRollData ( "adr" , undefined , "Mouvements" )
rollData . desengager = true
rollData . conditionsCommunes = true
HawkmoonUtility . updateWithTarget ( rollData )
let rollDialog = await HawkmoonRollDialog . create ( this , rollData )
rollDialog . render ( true )
}
2024-05-02 09:27:16 +02:00
2022-10-22 11:09:48 +02:00
/* -------------------------------------------- */
2023-04-24 22:20:47 +02:00
async rollArmeDegats ( armeId , targetVigueur = undefined , rollDataInput = undefined ) {
2022-10-22 11:09:48 +02:00
let arme = this . items . get ( armeId )
if ( arme . type == "arme" ) {
arme = this . prepareArme ( arme )
}
2023-12-28 18:40:46 +01:00
console . log ( "DEGATS" , arme , targetVigueur , rollDataInput )
2023-04-24 22:20:47 +02:00
let roll
2023-05-25 07:23:25 +02:00
let bonus = 0
2023-12-28 18:40:46 +01:00
let bonus2 = 0
if ( rollDataInput ? . applyCoupDevastateur ) {
bonus2 = Math . floor ( this . system . attributs . pui . value / 2 )
let talent = this . items . find ( item => item . type == "talent" && item . name . toLowerCase ( ) == "coup dévastateur" )
2024-05-02 09:27:16 +02:00
this . updateEmbeddedDocuments ( 'Item' , [ { _id : talent . id , 'system.used' : true } ] )
2023-12-28 18:40:46 +01:00
}
2023-04-24 22:20:47 +02:00
if ( rollDataInput ? . isHeroique ) {
2023-05-25 07:23:25 +02:00
if ( rollDataInput ? . attaqueCharge ) {
bonus = 5
}
2024-04-01 22:48:18 +02:00
if ( rollDataInput ? . chargeCavalerie ) {
bonus = 6
}
2024-05-02 09:27:16 +02:00
roll = await new Roll ( "2d10rr10+" + arme . system . totalDegats + "+" + bonus + "+" + bonus2 ) . roll ( )
2023-04-24 22:20:47 +02:00
} else {
2023-05-25 07:23:25 +02:00
if ( rollDataInput ? . attaqueCharge ) {
bonus = 3
}
2024-04-01 22:48:18 +02:00
if ( rollDataInput ? . chargeCavalerie ) {
bonus = 4
}
2024-05-02 09:27:16 +02:00
roll = await new Roll ( "1d10+" + arme . system . totalDegats + "+" + bonus + "+" + bonus2 ) . roll ( )
2023-04-24 22:20:47 +02:00
}
2022-10-22 11:09:48 +02:00
await HawkmoonUtility . showDiceSoNice ( roll , game . settings . get ( "core" , "rollMode" ) ) ;
2023-03-19 18:58:28 +01:00
let nbEtatPerdus = 0
2022-11-13 23:01:41 +01:00
if ( targetVigueur ) {
nbEtatPerdus = Math . floor ( roll . total / targetVigueur )
2024-05-02 09:27:16 +02:00
}
2024-04-01 22:48:18 +02:00
//console.log(roll)
2022-10-22 11:09:48 +02:00
let rollData = {
arme : arme ,
finalResult : roll . total ,
2023-12-28 18:40:46 +01:00
formula : roll . formula ,
2022-10-22 11:09:48 +02:00
alias : this . name ,
actorImg : this . img ,
actorId : this . id ,
2023-12-28 18:40:46 +01:00
defenderTokenId : rollDataInput ? . defenderTokenId ,
2022-10-22 11:09:48 +02:00
actionImg : arme . img ,
2022-11-13 23:01:41 +01:00
targetVigueur : targetVigueur ,
nbEtatPerdus : nbEtatPerdus
2022-10-22 11:09:48 +02:00
}
HawkmoonUtility . createChatWithRollMode ( rollData . alias , {
2022-11-10 11:04:05 +01:00
content : await renderTemplate ( ` systems/fvtt-hawkmoon-cyd/templates/chat-degats-result.html ` , rollData )
2022-10-22 11:09:48 +02:00
} )
2023-12-28 18:40:46 +01:00
if ( rollDataInput ? . defenderTokenId && nbEtatPerdus ) {
HawkmoonUtility . applyCombativite ( rollDataInput , nbEtatPerdus )
}
2022-10-22 11:09:48 +02:00
}
}