Compute general state

This commit is contained in:
LeRatierBretonnien 2020-05-29 00:43:16 +02:00
parent 458ba4b365
commit 4b465920f0
5 changed files with 60 additions and 12 deletions

View File

@ -54,7 +54,9 @@ export class RdDActorSheet extends ActorSheet {
list.push(item); list.push(item);
} }
} }
data.data.fatigueHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.fatigue.max ).html() + "</table>";
//endurance.max below is normal, this the base used to compute the grid.
data.data.fatigueHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>";
data.data.materiel = this._checkNull(data.itemsByType['objet']); data.data.materiel = this._checkNull(data.itemsByType['objet']);
data.data.armes = this._checkNull(data.itemsByType['arme']); data.data.armes = this._checkNull(data.itemsByType['arme']);
data.data.armures = this._checkNull(data.itemsByType['armure']); data.data.armures = this._checkNull(data.itemsByType['armure']);
@ -105,26 +107,32 @@ export class RdDActorSheet extends ActorSheet {
$("#vie-plus").click((event) => { $("#vie-plus").click((event) => {
this.actor.santeIncDec("vie", 1); this.actor.santeIncDec("vie", 1);
this.actor.update({"data.sante.vie.value": this.actor.data.data.sante.vie.value});
this.render(true); this.render(true);
}); });
$("#vie-moins").click((event) => { $("#vie-moins").click((event) => {
this.actor.santeIncDec("vie", -1); this.actor.santeIncDec("vie", -1);
this.actor.update({"data.sante.vie.value": this.actor.data.data.sante.vie.value});
this.render(true); this.render(true);
}); });
$("#endurance-plus").click((event) => { $("#endurance-plus").click((event) => {
this.actor.santeIncDec("endurance", 1); this.actor.santeIncDec("endurance", 1);
this.actor.update({"data.sante.endurance.value": this.actor.data.data.sante.endurance.value});
this.render(true); this.render(true);
}); });
$("#endurance-moins").click((event) => { $("#endurance-moins").click((event) => {
this.actor.santeIncDec("endurance", -1); this.actor.santeIncDec("endurance", -1);
this.actor.update({"data.sante.endurance.value": this.actor.data.data.sante.endurance.value});
this.render(true); this.render(true);
}); });
$("#fatigue-plus").click((event) => { $("#fatigue-plus").click((event) => {
this.actor.santeIncDec("fatigue", 1); this.actor.santeIncDec("fatigue", 1);
this.actor.update({"data.sante.fatigue.value": this.actor.data.data.sante.fatigue.value});
this.render(true); this.render(true);
}); });
$("#fatigue-moins").click((event) => { $("#fatigue-moins").click((event) => {
this.actor.santeIncDec("fatigue", -1); this.actor.santeIncDec("fatigue", -1);
this.actor.update({"data.sante.fatigue.value": this.actor.data.data.sante.fatigue.value});
this.render(true); this.render(true);
}); });
} }

View File

@ -92,6 +92,16 @@ export class RdDActor extends Actor {
RdDUtility.computeCarac( data ); 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 ) { santeIncDec(name, inc ) {
let data = this.data.data.sante[name]; 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 > data.max ) data.value = data.max;
if ( data.value < 0 ) data.value = 0; if ( data.value < 0 ) data.value = 0;
console.log(">>>> NEW VI", name, data.value); console.log(">>>> NEW VI", name, data.value);
this.computeEtatGeneral();
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -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) ); 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.max = endurance;
data.sante.endurance.value = endurance; data.sante.endurance.value = endurance;
data.sante.fatigue.max = endurance; data.sante.fatigue.max = endurance*2;
data.sante.fatigue.value = endurance; data.sante.fatigue.value = 0;
data.attributs.sconst.value = 5; // Max ! data.attributs.sconst.value = 5; // Max !
if ( data.carac.constitution.value < 9 ) if ( data.carac.constitution.value < 9 )
@ -240,24 +240,26 @@ export class RdDUtility {
data.attributs.sust.value = 2; data.attributs.sust.value = 2;
else if (data.carac.taille.value < 14 ) else if (data.carac.taille.value < 14 )
data.attributs.sust.value = 3; 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;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
// Build the nice (?) html table used to manage fatigue.
// max should be the endurance max value
static makeHTMLfatigueMatrix( value, max ) static makeHTMLfatigueMatrix( value, max )
{ {
max = (max < 16) ? 16 : max; max = (max < 16) ? 16 : max;
max = (max > 30) ? 30 : max; max = (max > 30) ? 30 : max;
value = (value > max) ? max : value; value = (value > max*2) ? max*2 : value;
value = (value < 0) ? 0 : value; value = (value < 0) ? 0 : value;
let fatigueTab = fatigueMatrix[max]; 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 = $("<table/>").addClass('table-fatigue'); let table = $("<table/>").addClass('table-fatigue');
let segmentIdx = 0; let segmentIdx = 0;
let fatigueCount = 0; let fatigueCount = 0;
@ -287,6 +289,25 @@ export class RdDUtility {
return table; 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<fatigueTab.length; idx++) {
fatigueRem -= fatigueTab[idx];
if ( fatigueRem <= 0) {
return fatigueMalus[idx];
}
}
return -7; // This is the max !
}
/* -------------------------------------------- */ /* -------------------------------------------- */
static findCompetence(compList, compName) static findCompetence(compList, compName)

View File

@ -244,6 +244,7 @@
}, },
"chance": { "chance": {
"value": 0, "value": 0,
"max": 0,
"label": "Chance" "label": "Chance"
}, },
"destinee": { "destinee": {

View File

@ -19,6 +19,13 @@
<span>{{{data.fatigueHTML}}}</span> <span>{{{data.fatigueHTML}}}</span>
</div> </div>
</div> </div>
<div class="flexrow">
{{#each data.compteurs as |compteur key|}}
<div class="flexcol flex-group-center">
{{compteur.label}} : {{compteur.value}}
</div>
{{/each}}
</div>
</div> </div>
</header> </header>