diff --git a/module/actor-sheet.js b/module/actor-sheet.js index f08f9dc9..d0efa603 100644 --- a/module/actor-sheet.js +++ b/module/actor-sheet.js @@ -54,7 +54,9 @@ export class RdDActorSheet extends ActorSheet { list.push(item); } } - data.data.fatigueHTML = "" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.fatigue.max ).html() + "
"; + + //endurance.max below is normal, this the base used to compute the grid. + data.data.fatigueHTML = "" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "
"; data.data.materiel = this._checkNull(data.itemsByType['objet']); data.data.armes = this._checkNull(data.itemsByType['arme']); data.data.armures = this._checkNull(data.itemsByType['armure']); @@ -105,26 +107,32 @@ export class RdDActorSheet extends ActorSheet { $("#vie-plus").click((event) => { this.actor.santeIncDec("vie", 1); + this.actor.update({"data.sante.vie.value": this.actor.data.data.sante.vie.value}); this.render(true); }); $("#vie-moins").click((event) => { this.actor.santeIncDec("vie", -1); + this.actor.update({"data.sante.vie.value": this.actor.data.data.sante.vie.value}); this.render(true); }); $("#endurance-plus").click((event) => { this.actor.santeIncDec("endurance", 1); + this.actor.update({"data.sante.endurance.value": this.actor.data.data.sante.endurance.value}); this.render(true); }); $("#endurance-moins").click((event) => { this.actor.santeIncDec("endurance", -1); + this.actor.update({"data.sante.endurance.value": this.actor.data.data.sante.endurance.value}); this.render(true); }); $("#fatigue-plus").click((event) => { this.actor.santeIncDec("fatigue", 1); + this.actor.update({"data.sante.fatigue.value": this.actor.data.data.sante.fatigue.value}); this.render(true); }); $("#fatigue-moins").click((event) => { this.actor.santeIncDec("fatigue", -1); + this.actor.update({"data.sante.fatigue.value": this.actor.data.data.sante.fatigue.value}); this.render(true); }); } diff --git a/module/actor.js b/module/actor.js index 4a04c0d7..b1863ab4 100644 --- a/module/actor.js +++ b/module/actor.js @@ -92,6 +92,16 @@ export class RdDActor extends Actor { RdDUtility.computeCarac( data ); } + /* -------------------------------------------- */ + computeEtatGeneral( ) + { + let data = this.data.data; + let state = 0; + state = state - (data.sante.vie.max - data.sante.vie.value); + state = state + RdDUtility.currentFatigueMalus(data.sante.fatigue.value, data.sante.endurance.max); + data.compteurs.etat.value = state; + } + /* -------------------------------------------- */ santeIncDec(name, inc ) { let data = this.data.data.sante[name]; @@ -99,6 +109,7 @@ export class RdDActor extends Actor { if ( data.value > data.max ) data.value = data.max; if ( data.value < 0 ) data.value = 0; console.log(">>>> NEW VI", name, data.value); + this.computeEtatGeneral(); } /* -------------------------------------------- */ diff --git a/module/rdd-utility.js b/module/rdd-utility.js index 2d42ec8f..754ec2b0 100644 --- a/module/rdd-utility.js +++ b/module/rdd-utility.js @@ -224,8 +224,8 @@ export class RdDUtility { let endurance = Math.max( parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value), parseInt(data.sante.vie.max) + parseInt(data.carac.volonte.value) ); data.sante.endurance.max = endurance; data.sante.endurance.value = endurance; - data.sante.fatigue.max = endurance; - data.sante.fatigue.value = endurance; + data.sante.fatigue.max = endurance*2; + data.sante.fatigue.value = 0; data.attributs.sconst.value = 5; // Max ! if ( data.carac.constitution.value < 9 ) @@ -240,24 +240,26 @@ export class RdDUtility { data.attributs.sust.value = 2; else if (data.carac.taille.value < 14 ) data.attributs.sust.value = 3; + + //Compteurs + data.compteurs.reve.value = data.carac.reve.value; + data.compteurs.reve.max = data.carac.reve.value; + data.compteurs.chance.value = data.carac.chance.value; + data.compteurs.chance.max = data.carac.chance.value; } /* -------------------------------------------- */ - static makeHTMLfatigueMatrix( value, max ) + // Build the nice (?) html table used to manage fatigue. + // max should be the endurance max value + static makeHTMLfatigueMatrix( value, max ) { max = (max < 16) ? 16 : max; max = (max > 30) ? 30 : max; - value = (value > max) ? max : value; + value = (value > max*2) ? max*2 : value; value = (value < 0) ? 0 : value; let fatigueTab = fatigueMatrix[max]; - let idx = 0; // Current fatigue slot - let remFatigue = value; - while ( remFatigue >= fatigueTab[idx] ) { // computes the fatigue segment consumed - remFatigue = remFatigue - fatigueTab[idx]; - idx = idx + 1; - } - // At this point, we have the segment id in idx and the remaing fatigue points for the next segment in remFatigue + let table = $("").addClass('table-fatigue'); let segmentIdx = 0; let fatigueCount = 0; @@ -287,6 +289,25 @@ export class RdDUtility { return table; } + /* -------------------------------------------- */ + static currentFatigueMalus( value, max) + { + max = (max < 16) ? 16 : max; + max = (max > 30) ? 30 : max; + value = (value > max*2) ? max*2 : value; + value = (value < 0) ? 0 : value; + + let fatigueTab = fatigueMatrix[max]; + let fatigueRem = value; + for (let idx=0; idx{{{data.fatigueHTML}}} +
+ {{#each data.compteurs as |compteur key|}} +
+ {{compteur.label}} : {{compteur.value}} +
+ {{/each}} +