Merge branch 'master' of gitlab.com:LeRatierBretonnien/foundryvtt-reve-de-dragon

This commit is contained in:
2020-11-18 23:49:12 +01:00
6 changed files with 94 additions and 32 deletions

View File

@ -106,7 +106,11 @@ export class RdDActorSheet extends ActorSheet {
data.difficultesLibres = CONFIG.RDD.difficultesLibres;
// low 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.fatigue = {
malus: RdDUtility.calculMalusFatigue(data.data.sante.fatigue.value, data.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( data.data.sante.fatigue.value, data.data.sante.endurance.max ).html() + "</table>"
}
RdDUtility.filterItemsPerTypeForSheet(data );
data.data.sortReserve = data.data.reve.reserve.list;

View File

@ -998,7 +998,10 @@ export class RdDActor extends Actor {
}
let data = {
fatigueHTML:"<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max ).html() + "</table>",
fatigue: {
malus: RdDUtility.calculMalusFatigue(this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max),
html: "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.data.data.sante.fatigue.value, this.data.data.sante.endurance.max ).html() + "</table>"
},
draconic: this.getDraconicList(),
sort: this.getSortList(),
caracReve: this.data.data.carac.reve.value,

View File

@ -31,18 +31,33 @@ const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1,
function _buildAllSegmentsFatigue(max) {
const cycle = [5, 2, 4, 1, 3, 0];
let fatigue = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
for (let i = 0; i <= 40; i++) {
for (let i = 0; i <= max; i++) {
const ligneFatigue= duplicate(fatigue[i]);
const caseIncrementee = cycle[i % 6];
ligneFatigue[caseIncrementee]++;
ligneFatigue[caseIncrementee + 6]++;
ligneFatigue.fatigueMax = 2 * (i + 1);
fatigue[i + 1] = ligneFatigue ;
}
return fatigue;
}
function _cumulSegmentsFatigue(matrix) {
let cumulMatrix = [];
for (let line of matrix)
{
let cumul = duplicate(line);
for (let i = 1; i < 12; i++) {
cumul[i] += cumul[i - 1];
}
cumulMatrix.push(cumul);
}
return cumulMatrix;
}
const fatigueMatrix = _buildAllSegmentsFatigue(30);
const cumulFatigueMatrix = _cumulSegmentsFatigue(fatigueMatrix);
const fatigueMalus = [ 0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7 ]; // Provides the malus for each segment of fatigue
const fatigueLineSize = [ 3, 6, 7, 8, 9, 10, 11, 12];
@ -372,20 +387,24 @@ export class RdDUtility {
data.compteurs.chance.max = data.carac.chance.value;
}
static getSegmentsFatigue(endurance) {
endurance = Math.max(endurance, 1);
endurance = Math.min(endurance, fatigueMatrix.length);
return fatigueMatrix[endurance];
static getSegmentsFatigue(maxEnd) {
maxEnd = Math.max(maxEnd, 1);
maxEnd = Math.min(maxEnd, fatigueMatrix.length);
return fatigueMatrix[maxEnd];
}
static cumulSegments(segments) {
let cumuls = [segments[0]];
for (let i = 1; i < 12; i++) {
cumuls[i] = segments[i] + cumuls[i - 1];
static calculMalusFatigue(fatigue, maxEnd)
{
maxEnd = Math.max(maxEnd, 1);
maxEnd = Math.min(maxEnd, cumulFatigueMatrix.length);
let segments = cumulFatigueMatrix[maxEnd];
for (let i=0; i<12; i++) {
if (fatigue <= segments[i]) {
return fatigueMalus[i]
}
}
return cumuls;
return -7;
}
/* -------------------------------------------- */
// Build the nice (?) html table used to manage fatigue.
// max should be the endurance max value