2020-05-21 21:48:20 +02:00
/ * *
* Extend the basic ActorSheet with some very simple modifications
* @ extends { ActorSheet }
* /
2020-05-22 22:37:02 +02:00
import { RdDUtility } from "./rdd-utility.js" ;
2020-09-20 21:45:46 +02:00
/* -------------------------------------------- */
2020-05-22 00:48:43 +02:00
export class RdDActorSheet extends ActorSheet {
2020-05-21 21:48:20 +02:00
/** @override */
static get defaultOptions ( ) {
return mergeObject ( super . defaultOptions , {
2020-05-22 00:48:43 +02:00
classes : [ "rdd" , "sheet" , "actor" ] ,
template : "systems/foundryvtt-reve-de-dragon/templates/actor-sheet.html" ,
2020-07-27 16:27:41 +02:00
width : 640 ,
height : 720 ,
2020-08-14 22:24:35 +02:00
tabs : [ { navSelector : ".sheet-tabs" , contentSelector : ".sheet-body" , initial : "carac" } ] ,
2020-05-21 21:48:20 +02:00
dragDrop : [ { dragSelector : ".item-list .item" , dropSelector : null } ]
} ) ;
}
2020-05-22 22:37:02 +02:00
/* -------------------------------------------- */
_checkNull ( items ) {
if ( items && items . length ) {
return items ;
}
return [ ] ;
}
2020-05-21 21:48:20 +02:00
/* -------------------------------------------- */
2020-05-22 19:28:01 +02:00
getData ( ) {
let data = super . getData ( ) ;
data . itemsByType = { } ;
for ( const item of data . items ) {
let list = data . itemsByType [ item . type ] ;
if ( ! list ) {
list = [ ] ;
data . itemsByType [ item . type ] = list ;
}
list . push ( item ) ;
}
2020-06-07 23:16:29 +02:00
// Competence per category
2020-05-22 19:28:01 +02:00
data . competenceByCategory = { } ;
2020-08-13 22:28:56 +02:00
let competenceXPTotal = 0 ;
2020-05-22 19:28:01 +02:00
if ( data . itemsByType . competence ) {
for ( const item of data . itemsByType . competence ) {
2020-06-07 23:16:29 +02:00
//console.log("Push...", item, item.data.categorie);
2020-05-22 19:28:01 +02:00
let list = data . competenceByCategory [ item . data . categorie ] ;
if ( ! list ) {
list = [ ] ;
data . competenceByCategory [ item . data . categorie ] = list ;
}
2020-08-14 22:24:35 +02:00
if ( ! RdDUtility . isTronc ( item . name ) ) // Ignorer les compétences 'troncs' à ce stade
competenceXPTotal += RdDUtility . computeCompetenceXPCost ( item )
2020-05-22 19:28:01 +02:00
list . push ( item ) ;
}
}
2020-08-14 22:24:35 +02:00
competenceXPTotal += RdDUtility . computeCompetenceTroncXP ( data . itemsByType . competence ) ;
2020-08-13 22:28:56 +02:00
data . data . competenceXPTotal = competenceXPTotal ;
//console.log("XP competence : ", competenceXPTotal);
// Compute current carac sum
let sum = 0 ;
Object . values ( data . data . carac ) . forEach ( carac => { if ( ! carac . derivee ) { sum += parseInt ( carac . value ) } } ) ;
data . data . caracSum = sum ;
2020-06-10 08:23:58 +02:00
// Force empty arme, at least for Esquive
if ( data . itemsByType . arme == undefined ) data . itemsByType . arme = [ ] ;
for ( const arme of data . itemsByType . arme ) {
arme . data . niveau = 0 ; // Per default, TODO to be fixed
for ( const melee of data . competenceByCategory . melee ) {
if ( melee . name == arme . data . competence )
arme . data . niveau = melee . data . niveau
}
2020-09-02 22:00:35 +02:00
for ( const tir of data . competenceByCategory . tir ) {
if ( tir . name == arme . data . competence )
arme . data . niveau = tir . data . niveau
}
for ( const lancer of data . competenceByCategory . lancer ) {
if ( lancer . name == arme . data . competence )
arme . data . niveau = lancer . data . niveau
}
}
2020-06-23 23:34:12 +02:00
// To avoid armour and so on...
data . data . armes _seules = duplicate ( this . _checkNull ( data . itemsByType [ 'arme' ] ) ) ;
2020-06-10 08:23:58 +02:00
if ( data . competenceByCategory && data . competenceByCategory . melee ) {
//Specific case for Esquive and Corps à Corps
for ( const melee of data . competenceByCategory . melee ) {
if ( melee . name == "Esquive" )
data . itemsByType . arme . push ( { name : "Esquive" , data : { niveau : melee . data . niveau , description : "" , force : 6 , competence : "Esquive" , dommages : 0 } } ) ;
if ( melee . name == "Corps à corps" )
data . itemsByType . arme . push ( { name : "Corps à corps" , data : { niveau : melee . data . niveau , description : "" , force : 6 , competence : "Corps à corps" , dommages : data . data . attributs . plusdom . value } } ) ;
2020-06-07 23:16:29 +02:00
}
}
2020-06-12 22:46:04 +02:00
data . data . carac . taille . isTaille = true ; // To avoid button link;
2020-07-27 16:27:41 +02:00
data . data . nbLegeres = this . actor . GetNumberBlessures ( data . data . blessures . legeres . liste ) ;
data . data . nbGraves = this . actor . GetNumberBlessures ( data . data . blessures . graves . liste ) ;
data . data . nbCritiques = this . actor . GetNumberBlessures ( data . data . blessures . critiques . liste ) ;
2020-08-29 22:52:41 +02:00
2020-06-12 22:46:04 +02:00
// low is normal, this the base used to compute the grid.
2020-05-29 00:43:16 +02:00
data . data . fatigueHTML = "<table class='table-fatigue'>" + RdDUtility . makeHTMLfatigueMatrix ( data . data . sante . fatigue . value , data . data . sante . endurance . max ) . html ( ) + "</table>" ;
2020-05-22 19:28:01 +02:00
data . data . materiel = this . _checkNull ( data . itemsByType [ 'objet' ] ) ;
data . data . armes = this . _checkNull ( data . itemsByType [ 'arme' ] ) ;
data . data . armures = this . _checkNull ( data . itemsByType [ 'armure' ] ) ;
data . data . livres = this . _checkNull ( data . itemsByType [ 'livre' ] ) ;
data . data . potions = this . _checkNull ( data . itemsByType [ 'potions' ] ) ;
2020-06-23 23:34:12 +02:00
data . data . herbes = this . _checkNull ( data . itemsByType [ 'herbes' ] ) ;
2020-07-05 21:45:25 +02:00
data . data . sorts = this . _checkNull ( data . itemsByType [ 'sort' ] ) ;
2020-07-24 10:51:11 +02:00
data . data . queues = this . _checkNull ( data . itemsByType [ 'queue' ] ) ;
data . data . souffles = this . _checkNull ( data . itemsByType [ 'souffle' ] ) ;
data . data . ombres = this . _checkNull ( data . itemsByType [ 'ombre' ] ) ;
data . data . tetes = this . _checkNull ( data . itemsByType [ 'tete' ] ) ;
2020-05-22 19:28:01 +02:00
data . data . competenceByCategory = data . competenceByCategory ;
2020-11-04 18:00:42 +01:00
data . data . isGM = game . user . isGM ;
2020-11-07 21:06:37 +01:00
data . bonusmalusTable = CONFIG . RDD . bonusmalus ;
2020-05-22 19:28:01 +02:00
return data ;
}
/* -------------------------------------------- */
2020-05-21 21:48:20 +02:00
/** @override */
activateListeners ( html ) {
super . activateListeners ( html ) ;
2020-06-12 11:47:41 +02:00
2020-05-21 21:48:20 +02:00
// Everything below here is only needed if the sheet is editable
if ( ! this . options . editable ) return ;
// Update Inventory Item
html . find ( '.item-edit' ) . click ( ev => {
const li = $ ( ev . currentTarget ) . parents ( ".item" ) ;
2020-11-05 20:23:16 +01:00
const item = this . actor . getOwnedItem ( li . data ( "item-id" ) ) ;
2020-05-21 21:48:20 +02:00
item . sheet . render ( true ) ;
} ) ;
2020-11-07 21:06:37 +01:00
2020-05-21 21:48:20 +02:00
// Delete Inventory Item
html . find ( '.item-delete' ) . click ( ev => {
const li = $ ( ev . currentTarget ) . parents ( ".item" ) ;
2020-11-05 20:23:16 +01:00
this . actor . deleteOwnedItem ( li . data ( "item-id" ) ) ;
console . log ( "Delete item :" , li . data ( "item-id" ) ) ;
2020-05-21 21:48:20 +02:00
li . slideUp ( 200 , ( ) => this . render ( false ) ) ;
} ) ;
2020-11-07 21:06:37 +01:00
// Update Inventory Item
html . find ( '.encaisser-direct' ) . click ( ev => {
let result = new Roll ( "2d10" ) . roll ( ) . result ;
const item = this . actor . encaisserDommagesHorsCombat ( result ) ;
console . log ( "ENCAISSER:" , result ) ;
} ) ;
2020-07-27 16:27:41 +02:00
// Blessure control
html . find ( '.blessure-control' ) . click ( ev => {
const li = $ ( ev . currentTarget ) . parents ( ".item" ) ;
let btype = li . data ( "blessure-type" ) ;
let index = li . data ( 'blessure-index' ) ;
let active = $ ( ev . currentTarget ) . data ( 'blessure-active' ) ;
//console.log(btype, index, active);
this . actor . manageBlessureFromSheet ( btype , index , active ) . then ( this . render ( true ) ) ;
} ) ;
// Blessure data
html . find ( '.blessures-soins' ) . change ( ev => {
const li = $ ( ev . currentTarget ) . parents ( ".item" ) ;
let btype = li . data ( 'blessure-type' ) ;
let index = li . data ( 'blessure-index' ) ;
let psoins = li . find ( 'input[name=premiers_soins]' ) . val ( ) ;
let pcomplets = li . find ( 'input[name=soins_complets]' ) . val ( ) ;
let jours = li . find ( 'input[name=jours]' ) . val ( ) ;
let loc = li . find ( 'input[name=localisation]' ) . val ( ) ;
//console.log(btype, index, psoins, pcomplets, jours, loc);
this . actor . setDataBlessureFromSheet ( btype , index , psoins , pcomplets , jours , loc ) . then ( this . render ( true ) ) ;
2020-07-20 12:02:07 +02:00
} ) ;
2020-06-23 23:34:12 +02:00
// Equip Inventory Item
html . find ( '.item-equip' ) . click ( ev => {
const li = $ ( ev . currentTarget ) . parents ( ".item" ) ;
2020-11-05 20:23:16 +01:00
this . actor . equiperObjet ( li . data ( "item-id" ) ) ;
2020-06-23 23:34:12 +02:00
this . render ( true ) ;
} ) ;
2020-06-12 22:46:04 +02:00
// Roll Carac
html . find ( '.carac-label a' ) . click ( ( event ) => {
let caracName = event . currentTarget . attributes . name . value ;
this . actor . rollCarac ( caracName . toLowerCase ( ) ) ;
} ) ;
2020-05-22 22:37:02 +02:00
// Roll Skill
html . find ( '.competence-label a' ) . click ( ( event ) => {
let compName = event . currentTarget . text ;
this . actor . rollCompetence ( compName ) ;
} ) ;
2020-06-07 23:16:29 +02:00
// Roll Weapon
html . find ( '.arme-label a' ) . click ( ( event ) => {
let armeName = event . currentTarget . text ;
this . actor . rollArme ( armeName ) ;
} ) ;
2020-05-27 23:47:49 +02:00
2020-07-25 10:29:28 +02:00
// Display TMR, normal
2020-07-24 10:51:11 +02:00
html . find ( '.monte-tmr a' ) . click ( ( event ) => {
2020-07-25 10:29:28 +02:00
this . actor . displayTMR ( false ) ;
} ) ;
// Display TMR, fast
html . find ( '.monte-tmr-rapide a' ) . click ( ( event ) => {
this . actor . displayTMR ( true ) ;
2020-07-24 10:51:11 +02:00
} ) ;
// Display info about queue
html . find ( '.queuesouffle-label a' ) . click ( ( event ) => {
2020-07-27 16:27:41 +02:00
let myID = event . currentTarget . attributes [ 'data-item-id' ] . value ;
2020-07-24 10:51:11 +02:00
const item = this . actor . getOwnedItem ( myID ) ;
item . sheet . render ( true ) ;
} ) ;
// Display info about queue
2020-07-05 21:45:25 +02:00
html . find ( '.sort-label a' ) . click ( ( event ) => {
2020-07-24 10:51:11 +02:00
let myID = event . currentTarget . attributes [ 'data-id' ] . value ;
const item = this . actor . getOwnedItem ( myID ) ;
item . sheet . render ( true ) ;
2020-07-05 21:45:25 +02:00
} ) ;
2020-07-24 10:51:11 +02:00
2020-05-24 20:19:57 +02:00
// On carac change
2020-06-23 23:34:12 +02:00
html . find ( '.carac-value' ) . change ( ( event ) => {
2020-05-24 20:19:57 +02:00
let caracName = event . currentTarget . name . replace ( ".value" , "" ) . replace ( "data.carac." , "" ) ;
2020-06-07 23:16:29 +02:00
//console.log("Value changed :", event, caracName);
2020-05-24 20:19:57 +02:00
this . actor . updateCarac ( caracName , parseInt ( event . target . value ) ) ;
} ) ;
2020-06-12 22:46:04 +02:00
2020-06-01 23:50:10 +02:00
// On competence change
2020-06-23 23:34:12 +02:00
html . find ( '.competence-value' ) . change ( ( event ) => {
2020-06-01 23:50:10 +02:00
let compName = event . currentTarget . attributes . compname . value ;
2020-06-07 23:16:29 +02:00
//console.log("Competence changed :", compName);
2020-06-01 23:50:10 +02:00
this . actor . updateCompetence ( compName , parseInt ( event . target . value ) ) ;
2020-07-14 22:19:29 +02:00
} ) ;
// On pts de reve change
html . find ( '.pointsreve-value' ) . change ( ( event ) => {
let reveValue = event . currentTarget . value ;
let reve = duplicate ( this . actor . data . data . reve . reve ) ;
reve . value = reveValue ;
2020-07-28 09:20:01 +02:00
this . actor . update ( { "data.reve.reve" : reve } ) ;
2020-06-01 23:50:10 +02:00
} ) ;
2020-07-14 22:19:29 +02:00
2020-06-12 22:46:04 +02:00
// On competence change
2020-06-23 23:34:12 +02:00
html . find ( '.competence-xp' ) . change ( ( event ) => {
2020-06-12 22:46:04 +02:00
let compName = event . currentTarget . attributes . compname . value ;
this . actor . updateCompetenceXP ( compName , parseInt ( event . target . value ) ) ;
} ) ;
2020-08-29 22:52:41 +02:00
// On stress change
html . find ( '.compteur-edit' ) . change ( ( event ) => {
let fieldName = event . currentTarget . attributes . name . value ;
this . actor . updateCompteurValue ( fieldName , parseInt ( event . target . value ) ) ;
} ) ;
html . find ( '#stress-test' ) . click ( ( event ) => {
this . actor . stressTest ( ) ;
this . render ( true ) ;
} ) ;
2020-05-28 23:36:09 +02:00
2020-06-23 23:34:12 +02:00
html . find ( '#vie-plus' ) . click ( ( event ) => {
2020-05-28 23:36:09 +02:00
this . actor . santeIncDec ( "vie" , 1 ) ;
this . render ( true ) ;
} ) ;
2020-06-23 23:34:12 +02:00
html . find ( '#vie-moins' ) . click ( ( event ) => {
2020-05-28 23:36:09 +02:00
this . actor . santeIncDec ( "vie" , - 1 ) ;
this . render ( true ) ;
} ) ;
2020-06-23 23:34:12 +02:00
html . find ( '#endurance-plus' ) . click ( ( event ) => {
2020-05-28 23:36:09 +02:00
this . actor . santeIncDec ( "endurance" , 1 ) ;
this . render ( true ) ;
} ) ;
2020-06-23 23:34:12 +02:00
html . find ( '#endurance-moins' ) . click ( ( event ) => {
2020-05-28 23:36:09 +02:00
this . actor . santeIncDec ( "endurance" , - 1 ) ;
this . render ( true ) ;
} ) ;
2020-06-23 23:34:12 +02:00
html . find ( '#fatigue-plus' ) . click ( ( event ) => {
2020-05-28 23:36:09 +02:00
this . actor . santeIncDec ( "fatigue" , 1 ) ;
this . render ( true ) ;
} ) ;
2020-06-23 23:34:12 +02:00
html . find ( '#fatigue-moins' ) . click ( ( event ) => {
2020-05-28 23:36:09 +02:00
this . actor . santeIncDec ( "fatigue" , - 1 ) ;
this . render ( true ) ;
} ) ;
2020-05-21 21:48:20 +02:00
}
2020-05-28 23:36:09 +02:00
2020-05-21 21:48:20 +02:00
/* -------------------------------------------- */
/** @override */
setPosition ( options = { } ) {
const position = super . setPosition ( options ) ;
const sheetBody = this . element . find ( ".sheet-body" ) ;
const bodyHeight = position . height - 192 ;
sheetBody . css ( "height" , bodyHeight ) ;
return position ;
}
/* -------------------------------------------- */
/** @override */
_updateObject ( event , formData ) {
// Update the Actor
return this . object . update ( formData ) ;
}
}