Merge branch 'master-fix-182' into 'master'

Fix xp des compétences tronc #182

See merge request LeRatierBretonnien/foundryvtt-reve-de-dragon!195
This commit is contained in:
Leratier Bretonnien 2021-04-09 06:05:05 +00:00
commit 03839397ce
2 changed files with 24 additions and 6 deletions

View File

@ -132,10 +132,10 @@ export class RdDItemCompetence extends Item {
list => list.map(name => RdDItemCompetence.findCompetence(competences, name)) list => list.map(name => RdDItemCompetence.findCompetence(competences, name))
// calcul du coût xp jusqu'au niveau 0 maximum // calcul du coût xp jusqu'au niveau 0 maximum
.map(it => RdDItemCompetence.computeDeltaXP(it?.data.base ?? -11, Math.min(it?.data.niveau ?? -11, 0))) .map(it => RdDItemCompetence.computeDeltaXP(it?.data.base ?? -11, Math.min(it?.data.niveau ?? -11, 0)))
.sort((a, b) => b - a) // tri descendant .sort(Misc.ascending())
.splice(0, 1) // ignorer le coût xp le plus élevé .splice(0, list.length-1) // prendre toutes les valeurs sauf l'une des plus élevées
.reduce((a, b) => a + b, 0) .reduce(Misc.sum(), 0)
).reduce((a, b) => a + b, 0); ).reduce(Misc.sum(), 0);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */

View File

@ -18,6 +18,24 @@ export class Misc {
return isPositiveNumber ? "+" + number : number return isPositiveNumber ? "+" + number : number
} }
static sum() {
return (a, b) => a + b;
}
static ascending(orderFunction = x=>x) {
return (a, b) => Misc.sortingBy(orderFunction(a), orderFunction(b));
}
static descending(orderFunction = x=>x) {
return (a, b) => Misc.sortingBy(orderFunction(b), orderFunction(a));
}
static sortingBy(a, b) {
if (a > b) return 1;
if (a < b) return -1;
return 0;
}
/** /**
* Converts the value to an integer, or to 0 if undefined/null/not representing integer * Converts the value to an integer, or to 0 if undefined/null/not representing integer
* @param {*} value value to convert to an integer using parseInt * @param {*} value value to convert to an integer using parseInt