Gestion des compteur et du Stress

This commit is contained in:
2020-08-29 22:52:41 +02:00
parent 1fd3c9d22f
commit ca8bf7f6d5
7 changed files with 130 additions and 25 deletions

View File

@ -94,7 +94,8 @@ export class RdDActorSheet extends ActorSheet {
data.data.nbLegeres = this.actor.GetNumberBlessures(data.data.blessures.legeres.liste );
data.data.nbGraves = this.actor.GetNumberBlessures(data.data.blessures.graves.liste );
data.data.nbCritiques = this.actor.GetNumberBlessures(data.data.blessures.critiques.liste );
console.log( data.data.compteurs );
// 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.materiel = this._checkNull(data.itemsByType['objet']);
@ -234,6 +235,17 @@ export class RdDActorSheet extends ActorSheet {
let compName = event.currentTarget.attributes.compname.value;
this.actor.updateCompetenceXP( compName, parseInt(event.target.value) );
} );
// On stress change
html.find('.compteur-edit').change((event) => {
let fieldName = event.currentTarget.attributes.name.value;
this.actor.updateCompteurValue( fieldName, parseInt(event.target.value) );
} );
html.find('#stress-test').click((event) => {
this.actor.stressTest();
this.render(true);
});
html.find('#vie-plus').click((event) => {
this.actor.santeIncDec("vie", 1);

View File

@ -333,6 +333,16 @@ export class RdDActor extends Actor {
}
}
/* -------------------------------------------- */
async updateCompteurValue( fieldName, fieldValue )
{
//console.log("Update", fieldName, fieldValue);
let content;
let compteurs = duplicate(this.data.data.compteurs);
compteurs[fieldName].value = fieldValue;
await this.update( {"data.compteurs": compteurs } );
}
/* -------------------------------------------- */
computeEtatGeneral( )
{
@ -426,6 +436,7 @@ export class RdDActor extends Actor {
}
return nbB;
}
/* -------------------------------------------- */
async santeIncDec(name, inc ) {
const sante = duplicate(this.data.data.sante);
@ -467,6 +478,7 @@ export class RdDActor extends Actor {
await this.update( {"data.sante": sante } );
}
/* -------------------------------------------- */
async manageBlessureFromSheet( bType, index, active ) {
let bList = duplicate(this.data.data.blessures);
@ -545,6 +557,59 @@ export class RdDActor extends Actor {
}
}
/* -------------------------------------------- */
async stressTest( ) {
let compteurs = duplicate(this.data.data.compteurs);
let stress = compteurs.stress;
let xp = compteurs.experience;
let scoreTarget = RdDUtility.getResolutionField( this.data.data.carac.reve.value, 0 );
scoreTarget.sig = Math.floor(scoreTarget.score / 2);
let scoreValue = new Roll("d100").roll().total;
let newXP = xp.value;
let factor = 0;
let comment = "Echec Total (0%)"
if (scoreValue <= scoreTarget.part ) {
scoreValue = new Roll("d100").roll().total;
if (scoreValue <= scoreTarget.sig) {
factor = 1.5;
comment = "Double Particulière (150%)"
} else {
factor = 1;
comment = "Particulière (100%)"
}
} else {
if ( scoreValue <= scoreTarget.sig ) {
factor = 0.75;
comment = "Significative (75%)"
} else {
if ( scoreValue <= scoreTarget.score ) {
factor = 0.5;
comment = "Normale (50%)"
} else if (scoreValue <= scoreTarget.epart) {
factor = 0.2;
comment = "Echec (20%)"
} else if (scoreValue <= scoreTarget.etotal) {
factor = 0.1;
comment = "Echec (10%)"
}
}
}
let xpValue = Math.floor(stress.value * factor);
stress.value -= xpValue;
stress.value -= 1;
if (stress.value < 0 ) stress.value = 0;
ChatMessage.create( { title: "Jet de Stress", content: "Vous avez transformé "+ xpValue + " points de Stress en Expérience avec une réussite " + comment ,
whisper: ChatMessage.getWhisperRecipients(game.user.name) } );
xp.value += xpValue;
await this.update( { "data.compteurs": compteurs } );
}
/* -------------------------------------------- */
async rollUnSort( coord ) {
let draconicList = this.getDraconicList();
@ -675,9 +740,7 @@ export class RdDActor extends Actor {
for (const item of this.data.items) {
if (item.type == "armure" && item.data.equipe) {
let update = duplicate(item);
let myroll = new Roll(update.data.protection.toString());
myroll.roll();
protection += myroll.total;
protection += new Roll(update.data.protection.toString()).roll().total;
update.data.deterioration += domArmePlusDom;
domArmePlusDom = 0; // Reset it
if ( update.data.deterioration >= 10) {

View File

@ -329,7 +329,7 @@ export class RdDUtility {
/* -------------------------------------------- */
// Build the nice (?) html table used to manage fatigue.
// max should be the endurance max value
// max should Mbe the endurance max value
static makeHTMLfatigueMatrix( value, max )
{
max = (max < 16) ? 16 : max;
@ -442,8 +442,7 @@ export class RdDUtility {
return -7; // This is the max !
}
/* -------------------------------------------- */
/* -------------------------------------------- */
static findCompetence(compList, compName)
{
for (const item of compList) {