#1 gestion encombrement et malus associé

This commit is contained in:
2020-11-11 14:42:11 +01:00
parent 70abeb2c87
commit 021948bf6e
4 changed files with 26 additions and 4 deletions

View File

@ -66,6 +66,9 @@ export class RdDActor extends Actor {
const data = actorData.data;
const flags = actorData.flags;
// Dynamic computing fields
this.encombrementTotal = 0;
// Make separate methods for each Actor type (character, npc, etc.) to keep
// things organized.
if (actorData.type === 'personnage') this._prepareCharacterData(actorData);
@ -80,6 +83,7 @@ export class RdDActor extends Actor {
_prepareCharacterData(actorData) {
// Initialize empty items
RdDUtility.computeCarac(actorData.data);
this.computeEncombrementTotal();
this.computeEtatGeneral();
}
@ -367,6 +371,19 @@ export class RdDActor extends Actor {
await this.update( {"data.compteurs": compteurs } );
}
/* -------------------------------------------- */
detectSurEncombrement( ) {
let diffEnc = Number(this.encombrementTotal) - Number(this.data.data.attributs.encombrement.value);
console.log("Sur enc", this.encombrementTotal, diffEnc);
if ( diffEnc > 0 ) { // Sur-encombrement
let malus = Math.round( diffEnc);
malus = (malus == 0) ? 1 : malus; // Always 1 at least
console.log("Sur enc malus", malus);
return malus;
}
return 0;
}
/* -------------------------------------------- */
computeEncombrementTotal( ) {
let totalEnc = 0;
@ -375,7 +392,8 @@ export class RdDActor extends Actor {
totalEnc += Number(item.data.encombrement);
}
}
console.log("Enc total : ", totalEnc);
this.encombrementTotal = totalEnc;
this.detectSurEncombrement();
}
/* -------------------------------------------- */
@ -386,6 +404,7 @@ export class RdDActor extends Actor {
state = state - (data.sante.vie.max - data.sante.vie.value);
if (data.sante.fatigue) // Creatures n'ont pas de fatigue
state = state + RdDUtility.currentFatigueMalus(data.sante.fatigue.value, data.sante.endurance.max);
state = state - this.detectSurEncombrement();
data.compteurs.etat.value = state;
}