Gestion experience

This commit is contained in:
2020-12-14 10:38:43 +01:00
9 changed files with 950 additions and 219 deletions

View File

@ -42,13 +42,13 @@ const specialResults = [
const reussites = [
{ code: "etotal", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: -4, ptQualite: -6, quality: "Echec total", condition: (target, roll) => roll >= target.etotal && roll <= 100 },
{ code: "epart", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: false, ptTache: -2, ptQualite: -4, quality: "Echec particulier", condition: (target, roll) => (roll >= target.epart && roll < target.etotal) },
{ code: "echec", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: false, isETotal: false, ptTache: 0, ptQualite: -2, quality: "Echec normal", condition: (target, roll) => (roll > target.score && roll < target.etotal) },
{ code: "norm", isPart: false, isSign: false, isSuccess: true, isEchec: false, isEPart: false, isETotal: false, ptTache: 1, ptQualite: 0, quality: "Réussite normale", condition: (target, roll) => (roll > target.sign && roll <= target.score) },
{ code: "sign", isPart: false, isSign: true, isSuccess: true, isEchec: false, isEPart: false, isETotal: false, ptTache: 2, ptQualite: 1, quality: "Réussite significative", condition: (target, roll) => (roll > target.part && roll <= target.sign) },
{ code: "part", isPart: true, isSign: true, isSuccess: true, isEchec: false, isEPart: false, isETotal: false, ptTache: 3, ptQualite: 2, quality: "Réussite Particulière!", condition: (target, roll) => (roll > 0 && roll <= target.part) },
{ code: "error", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: 0, ptQualite: 0, quality: "Jet de dés invalide", condition: (target, roll) => (roll <= 0 || roll > 100) }
{ code: "etotal", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: -4, ptQualite: -6, quality: "Echec total", condition: (target, roll) => roll >= target.etotal && roll <= 100 },
{ code: "epart", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: false, ptTache: -2, ptQualite: -4, quality: "Echec particulier", condition: (target, roll) => (roll >= target.epart && roll < target.etotal) },
{ code: "echec", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: false, isETotal: false, ptTache: 0, ptQualite: -2, quality: "Echec normal", condition: (target, roll) => (roll > target.score && roll < target.etotal) },
{ code: "norm", isPart: false, isSign: false, isSuccess: true, isEchec: false, isEPart: false, isETotal: false, ptTache: 1, ptQualite: 0, quality: "Réussite normale", condition: (target, roll) => (roll > target.sign && roll <= target.score) },
{ code: "sign", isPart: false, isSign: true, isSuccess: true, isEchec: false, isEPart: false, isETotal: false, ptTache: 2, ptQualite: 1, quality: "Réussite significative", condition: (target, roll) => (roll > target.part && roll <= target.sign) },
{ code: "part", isPart: true, isSign: true, isSuccess: true, isEchec: false, isEPart: false, isETotal: false, ptTache: 3, ptQualite: 2, quality: "Réussite Particulière!", condition: (target, roll) => (roll > 0 && roll <= target.part) },
{ code: "error", isPart: false, isSign: false, isSuccess: false, isEchec: true, isEPart: true, isETotal: true, ptTache: 0, ptQualite: 0, quality: "Jet de dés invalide", condition: (target, roll) => (roll <= 0 || roll > 100) }
];
/* -------------------------------------------- */
@ -81,8 +81,9 @@ export class RdDResolutionTable {
/* -------------------------------------------- */
static explain(rolled) {
let message = "<br>Jet : <strong>" + rolled.roll + "</strong> sur " + rolled.score + "% ";
if (rolled.caracValue != null && rolled.finalLevel!= null) {
message += "(" + rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ") ";
if (rolled.caracValue != null && rolled.finalLevel != null) {
message += (rolled.needSignificative ? "(significative sur " : "(")
+ rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ") ";
}
message += '<strong>' + rolled.quality + '</strong>'
return message;
@ -90,28 +91,39 @@ export class RdDResolutionTable {
}
/* -------------------------------------------- */
static updateChancesWithBonus( chances, bonus ) {
if (bonus) {
let newScore = Number(chances.score) + Number(bonus);
mergeObject(chances, this._computeCell(null, newScore), {overwrite: true});
static async rollData(rollData) {
rollData.rolled = await this.roll(rollData.caracValue, rollData.finalLevel, rollData.bonus, rollData.needSignificative);
}
/* -------------------------------------------- */
static async roll(caracValue, finalLevel, bonus = undefined, needSignificative = undefined, showDice = true) {
let chances = this.computeChances(caracValue, finalLevel);
this._updateChancesWithBonus(chances, bonus);
this._updateChancesNeedSignificative(chances, needSignificative);
chances.showDice = showDice;
let rolled = await this.rollChances(chances);
rolled.caracValue = caracValue;
rolled.finalLevel = finalLevel;
rolled.bonus = bonus;
rolled.needSignificative = needSignificative;
return rolled;
}
/* -------------------------------------------- */
static _updateChancesNeedSignificative(chances, needSignificative) {
if (needSignificative) {
let newScore = Math.floor(Number(chances.score) / 2);
mergeObject(chances, this._computeCell(null, newScore), { overwrite: true });
}
}
/* -------------------------------------------- */
static async rollData(rollData ) {
rollData.rolled = await this.roll(rollData.caracValue, rollData.finalLevel, rollData.bonus);
}
/* -------------------------------------------- */
static async roll(caracValue, finalLevel, bonus = undefined, showDice = true ) {
let chances = this.computeChances(caracValue, finalLevel);
chances.showDice = showDice;
this.updateChancesWithBonus( chances, bonus);
let rolled = await this.rollChances(chances);
rolled.caracValue = caracValue;
rolled.finalLevel = finalLevel;
rolled.bonus = bonus;
return rolled;
static _updateChancesWithBonus(chances, bonus) {
if (bonus) {
let newScore = Number(chances.score) + Number(bonus);
mergeObject(chances, this._computeCell(null, newScore), { overwrite: true });
}
}
/* -------------------------------------------- */
@ -136,14 +148,20 @@ export class RdDResolutionTable {
}
/* -------------------------------------------- */
static buildXpMessage(rolled, level) {
if (rolled.isPart && level < 0) {
const xp = Math.abs(level);
const xpcarac = Math.floor(xp / 2);
const xpcomp = xp - xpcarac;
return "<br>Points d'expérience gagnés ! Carac: " + xpcarac + ", Comp: " + xpcomp;
}
return "";
static isEchec(rollData) {
return rollData.demiSurprise ? !rollData.rolled.isSign : rollData.rolled.isEchec;
}
/* -------------------------------------------- */
static isEchecTotal(rollData) {
return (rollData.demiSurprise && rollData.arme) ? rollData.rolled.isEchec : rollData.rolled.isETotal;
}
/* -------------------------------------------- */
static isParticuliere(rollData) {
return (rollData.demiSurprise && rollData.arme) ? false : rollData.rolled.isPart;
}
/* -------------------------------------------- */
static isReussite(rollData) {
return rollData.demiSurprise ? rollData.rolled.isSign : rollData.rolled.isSuccess;
}
/* -------------------------------------------- */