Récupération de fatigue

This commit is contained in:
Vincent Vandemeulebrouck 2020-11-17 13:08:52 +01:00
parent 59be07b3e9
commit a5ead0c77a
3 changed files with 126 additions and 74 deletions

View File

@ -329,38 +329,76 @@ export class RdDActor extends Actor {
} }
async dormir(heures=1) { async dormir(heures=1) {
let message = { title : "Récupération", content :"Vous dormez " + heures + " heure" + (heures > 1 ? "s": "") };
this.recupereEndurance(message);
for (let i=0; i<heures; i++) { for (let i=0; i<heures; i++) {
console.log("recuperationReve", this.data.data); await this.recupererFatigueUneHeure(message);
/** this.recuperationReve(message);
* TODO: récupérer les segment de fatigue }
*/ ChatMessage.create( message );
this.recuperationReve(); }
recupereEndurance(message) {
const avant = this.data.data.sante.endurance.value;
this.santeIncDec("endurance", this.data.data.sante.endurance.max - avant);
const recupere = this.data.data.sante.endurance.value - avant;
if (recupere>0) {
message.content += "<br>Vous récuperez " + recupere + " points d'endurance";
} }
} }
async recuperationReve() { async recupererFatigueUneHeure(message) {
const seuil = this.data.data.reve.seuil.value; let fatigue = duplicate(this.data.data.sante.fatigue)
const reve = this.getReveActuel(); if (fatigue.value == 0) {
console.log("recuperationReve", this.data.data); message.content += "<br>Vous êtes déjà reposé";
let message = { title : "Récupération" } return;
if (reve > seuil) { }
message.content = "Vous avez déjà récupéré suffisament (seuil " + seuil + ", rêve actuel "+reve+")"; const segments = RdDUtility.getSegmentsFatigue(this.data.data.sante.endurance.max);
} let cumul = 0;
else { console.log("recupererFatigue", segments);
let deRecuperation = await RdDDice.deDraconique();
console.log("recuperationReve", deRecuperation); let i;
if (deRecuperation>=7) for (i=0; i <11; i++) {
{ cumul += segments[i];
// Rêve de Dragon ! let diff = cumul - fatigue.value ;
message.content = "Vous faites un <strong>Rêve de Dragon</strong> de " + deRecuperation + " Points de rêve"; if (diff >= 0)
message.content += await this.combattreReveDeDragon(deRecuperation); {
} const limit2Segments = Math.floor(segments[i] / 2);
else{ if (diff > limit2Segments && i > 0) {
message.content = "Vous récupérez " + deRecuperation + " Points de rêve"; cumul -= segments[i-1]; // le segment est à moins de la moitié, il est récupéré
await this.updatePointsDeReve(deRecuperation);
} }
cumul -= segments[i];
break;
} }
ChatMessage.create( message ); }
fatigue.value = cumul;
await this.update( {"data.sante.fatigue": fatigue } );
if (fatigue.value == 0)
{
message.content += "<br>Vous êtes bien reposé";
}
}
recuperationReve(message) {
const seuil = this.data.data.reve.seuil.value;
const reve = this.getReveActuel();
if (reve >= seuil) {
message.content += "<br>Vous avez suffisament rêvé (seuil " + seuil + ", rêve actuel "+reve+")";
}
else {
let deRecuperation = RdDDice.deDraconique();
console.log("recuperationReve", deRecuperation);
if (deRecuperation>=7)
{
// Rêve de Dragon !
message.content += "<br>Vous faites un <strong>Rêve de Dragon</strong> de " + deRecuperation + " Points de rêve";
message.content += this.combattreReveDeDragon(deRecuperation);
}
else{
message.content += "<br>Vous récupérez " + deRecuperation + " Points de rêve";
this.updatePointsDeReve(deRecuperation);
}
}
} }
combattreReveDeDragon(force){ combattreReveDeDragon(force){
@ -370,6 +408,7 @@ export class RdDActor extends Actor {
let difficulte = niveau - etat - force; let difficulte = niveau - etat - force;
let reveActuel = this.getReveActuel(); let reveActuel = this.getReveActuel();
let rolled = RdDResolutionTable.roll(reveActuel, difficulte); let rolled = RdDResolutionTable.roll(reveActuel, difficulte);
// TODO: xp particulière
consome.log("combattreReveDeDragon", rolled ); consome.log("combattreReveDeDragon", rolled );
return this.appliquerReveDeDragon(rolled, force); return this.appliquerReveDeDragon(rolled, force);
} }

View File

@ -27,22 +27,23 @@ const competence_xp_par_niveau = [ 5, 5, 5, 10, 10, 10, 10, 15, 15, 15, 15, 20,
const carac_array = [ "taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"]; const carac_array = [ "taille", "apparence", "constitution", "force", "agilite", "dexterite", "vue", "ouie", "odoratgout", "volonte", "intellect", "empathie", "reve", "chance", "melee", "tir", "lancer", "derobee"];
const difficultesLibres = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10]; const difficultesLibres = [0, -1, -2, -3, -4, -5, -6, -7, -8, -9, -10];
const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10]; const ajustementsConditions = [-10, -9, -8, -7, -6, -5, -4, -3, -2, -1, 0, +1, +2, +3, +4, +5, +6, +7, +8, +9, +10];
const fatigueMatrix = [ 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, // Dummy filler for the array.
[2, 3, 3, 2, 3, 3, 2, 3, 3, 2, 3, 3 ], function _buildAllSegmentsFatigue(max) {
[2, 3, 3, 3, 3, 3, 2, 3, 3, 3, 3, 3 ], const cycle = [5, 2, 4, 1, 3, 0];
[3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3 ], let fatigue = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]];
[3, 3, 3, 3, 3, 4, 3, 3, 3, 3, 3, 4 ], for (let i = 0; i <= 40; i++) {
[3, 3, 4, 3, 3, 4, 3, 3, 4, 3, 3, 4 ], const ligneFatigue= duplicate(fatigue[i]);
[3, 3, 4, 3, 4, 4, 3, 3, 4, 3, 4, 4 ], const caseIncrementee = cycle[i % 6];
[3, 4, 4, 3, 4, 4, 3, 4, 4, 3, 4, 4 ], ligneFatigue[caseIncrementee]++;
[3, 4, 4, 4, 4, 4, 3, 4, 4, 4, 4, 4 ], ligneFatigue[caseIncrementee + 6]++;
[4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4 ], ligneFatigue.fatigueMax = 2 * (i + 1);
[4, 4, 4, 4, 4, 5, 4, 4, 4, 4, 4, 5 ], fatigue[i + 1] = ligneFatigue ;
[4, 4, 5, 4, 4, 5, 4, 4, 5, 4, 4, 5 ], }
[4, 4, 5, 4, 5, 5, 4, 4, 5, 4, 5, 5 ], return fatigue;
[4, 5, 5, 4, 5, 5, 4, 5, 5, 4, 5, 5 ], }
[4, 5, 5, 5, 5, 5, 4, 5, 5, 5, 5, 5 ],
[5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5 ] ]; const fatigueMatrix = _buildAllSegmentsFatigue(30);
const fatigueMalus = [ 0, 0, 0, -1, -1, -1, -2, -3, -4, -5, -6, -7 ]; // Provides the malus for each segment of fatigue 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]; const fatigueLineSize = [ 3, 6, 7, 8, 9, 10, 11, 12];
const fatigueLineMalus = [ 0, -1, -2, -3, -4, -5, -6, -7 ]; const fatigueLineMalus = [ 0, -1, -2, -3, -4, -5, -6, -7 ];
@ -84,7 +85,6 @@ const definitionsEncaissement = {
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDUtility { export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static async preloadHandlebarsTemplates( ) { static async preloadHandlebarsTemplates( ) {
const templatePaths = [ const templatePaths = [
@ -255,12 +255,12 @@ export class RdDUtility {
/* -------------------------------------------- */ /* -------------------------------------------- */
static computeCarac( data) static computeCarac( data)
{ {
let fmax = parseInt(data.carac.taille.value) + 4; data.carac.force.value = Math.min(data.carac.force.value, parseInt(data.carac.taille.value) + 4);
if ( data.carac.force.value > fmax )
data.carac.force.value = fmax;
data.carac.derobee.value = Math.floor(parseInt(((21 - data.carac.taille.value)) + parseInt(data.carac.agilite.value)) / 2); data.carac.derobee.value = Math.floor(parseInt(((21 - data.carac.taille.value)) + parseInt(data.carac.agilite.value)) / 2);
let bonusDomKey = Math.floor( (parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2); let bonusDomKey = Math.floor( (parseInt(data.carac.force.value) + parseInt(data.carac.taille.value)) / 2);
// TODO: gérer table des bonus dommages (et autres) des créatures
data.attributs.plusdom.value = 2 data.attributs.plusdom.value = 2
if (bonusDomKey < 8) if (bonusDomKey < 8)
data.attributs.plusdom.value = -1; data.attributs.plusdom.value = -1;
@ -275,15 +275,12 @@ export class RdDUtility {
data.carac.lancer.value = Math.floor( (parseInt(data.carac.tir.value) + parseInt(data.carac.force.value)) / 2); data.carac.lancer.value = Math.floor( (parseInt(data.carac.tir.value) + parseInt(data.carac.force.value)) / 2);
data.sante.vie.max = Math.ceil( (parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value)) /2 ); data.sante.vie.max = Math.ceil( (parseInt(data.carac.taille.value) + parseInt(data.carac.constitution.value)) /2 );
if ( data.sante.vie.value > data.sante.vie.max)
data.sante.vie.value = data.sante.vie.max; data.sante.vie.value = Math.min(data.sante.vie.value, data.sante.vie.max)
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 = 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.value = Math.min(data.sante.endurance.value, data.sante.endurance.max);
if ( data.sante.endurance.value > endurance) data.sante.fatigue.max = data.sante.endurance.max*2;
data.sante.endurance.value = endurance; data.sante.fatigue.value = Math.min(data.sante.fatigue.value, data.sante.fatigue.max);
data.sante.fatigue.max = endurance*2;
if ( data.sante.fatigue.value > data.sante.fatigue.max )
data.sante.fatigue.value = data.sante.fatigue.max;
data.attributs.sconst.value = 5; // Max ! data.attributs.sconst.value = 5; // Max !
if ( data.carac.constitution.value < 9 ) if ( data.carac.constitution.value < 9 )
@ -305,36 +302,52 @@ export class RdDUtility {
//data.compteurs.chance.value = data.carac.chance.value; //data.compteurs.chance.value = data.carac.chance.value;
data.compteurs.chance.max = data.carac.chance.value; 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 cumulSegments(segments) {
let cumuls = [segments[0]];
for (let i = 1; i < 12; i++) {
cumuls[i] = segments[i] + cumuls[i - 1];
}
return cumuls;
}
/* -------------------------------------------- */ /* -------------------------------------------- */
// Build the nice (?) html table used to manage fatigue. // Build the nice (?) html table used to manage fatigue.
// max should Mbe the endurance max value // max should be the endurance max value
static makeHTMLfatigueMatrix( value, max ) static makeHTMLfatigueMatrix( fatigue, maxEndurance) {
{ let segments = this.getSegmentsFatigue(maxEndurance);
max = (max < 16) ? 16 : max; return this.makeHTMLfatigueMatrixForSegment(fatigue, segments);
max = (max > 30) ? 30 : max; }
value = (value > max*2) ? max*2 : value;
value = (value < 0) ? 0 : value;
let fatigueTab = fatigueMatrix[max];
let table = $("<table/>").addClass('table-fatigue'); static makeHTMLfatigueMatrixForSegment(fatigue, segments) {
fatigue = Math.max(fatigue, 0);
fatigue = Math.min(fatigue, segments.fatigueMax);
let table = $("<table/>").addClass('table-fatigue');
let segmentIdx = 0; let segmentIdx = 0;
let fatigueCount = 0; let fatigueCount = 0;
for (var line=0; line < fatigueLineSize.length; line++) { for (var line = 0; line < fatigueLineSize.length; line++) {
let row = $("<tr/>"); let row = $("<tr/>");
let segmentsPerLine = fatigueLineSize[line]; let segmentsPerLine = fatigueLineSize[line];
row.append("<td class='fatigue-malus'>" + fatigueLineMalus[line] + "</td>"); row.append("<td class='fatigue-malus'>" + fatigueLineMalus[line] + "</td>");
while (segmentIdx < segmentsPerLine) { while (segmentIdx < segmentsPerLine) {
let freeSize = fatigueTab[segmentIdx]; let freeSize = segments[segmentIdx];
for (let col=0; col <5; col++) { for (let col = 0; col < 5; col++) {
if ( col < freeSize ) { if (col < freeSize) {
if (fatigueCount < value ) if (fatigueCount < fatigue)
row.append("<td class='fatigue-used'/>"); row.append("<td class='fatigue-used'/>");
else else
row.append("<td class='fatigue-free'/>"); row.append("<td class='fatigue-free'/>");
fatigueCount++; fatigueCount++;
} else { } else {
row.append("<td class='fatigue-none'/>"); row.append("<td class='fatigue-none'/>");
} }
} }
@ -343,10 +356,9 @@ export class RdDUtility {
} }
table.append(row); table.append(row);
} }
//console.log("fatigue", table);
return table; return table;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static getLocalisation( ) static getLocalisation( )
{ {

View File

@ -373,6 +373,7 @@ export class TMRUtility {
msg += "Ce Tourbillon Noir disparait !" msg += "Ce Tourbillon Noir disparait !"
} else if (rencontre.name == "Rêve de Dragon") { } else if (rencontre.name == "Rêve de Dragon") {
// TODO: xp particulière
msg += "Vous maîtrisez le Rêve de Dragon !" msg += "Vous maîtrisez le Rêve de Dragon !"
msg += actor.appliquerReveDeDragon(rolled, rencontre.force); msg += actor.appliquerReveDeDragon(rolled, rencontre.force);
} }