Amélioration messages de stress

This commit is contained in:
Vincent Vandemeulebrouck 2021-01-29 12:08:02 +01:00
parent 861e8de590
commit a12f9bbf01
5 changed files with 78 additions and 57 deletions

View File

@ -459,7 +459,7 @@ export class RdDActorSheet extends ActorSheet {
this.actor.setEthylisme(parseInt(event.target.value));
});
html.find('#stress-test').click((event) => {
this.actor.stressTest();
this.actor.transformerStress();
this.render(true);
});
html.find('#moral-malheureux').click((event) => {

View File

@ -321,7 +321,7 @@ export class RdDActor extends Actor {
await this._recupererVie(message);
await this.jetDeMoral('neutre');
await this.chanceActuelleIncDec(1);
await this.transformerStress(message);
this.transformerStress();
await this.retourSeuilDeReve(message);
message.content = `A la fin Chateau Dormant, ${message.content}<br>Un nouveau jour se lève`;
ChatMessage.create(message);
@ -1417,69 +1417,72 @@ export class RdDActor extends Actor {
}
/* -------------------------------------------- */
async stressTest() {
const message = {
content: "",
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name)
};
await this.transformerStress(message);
ChatMessage.create(message);
}
/* -------------------------------------------- */
async transformerStress(message) {
let compteurs = duplicate(this.data.data.compteurs);
const stress = Misc.toInt(compteurs.stress.value);
async transformerStress() {
const stress = Misc.toInt(this.data.data.compteurs.stress.value);
if (stress <= 0) {
return false;
return;
}
let stressRoll = await this._stressRoll();
let convertis = Math.floor(stress * stressRoll.factor);
compteurs.stress.value = Math.max(stress - convertis - 1, 0);
const stressRoll = await this._stressRoll(this.getReveActuel());
let dissolution = Math.max(0, Misc.toInt(compteurs.dissolution.value));
let exaltation = Math.max(0, Misc.toInt(compteurs.exaltation.value));
const conversion = Math.floor(stress * stressRoll.factor / 100);
let dissolution = Math.max(0, Misc.toInt(this.data.data.compteurs.dissolution.value));
let exaltation = Math.max(0, Misc.toInt(this.data.data.compteurs.exaltation.value));
const annule = Math.min(dissolution, exaltation);
dissolution -= annule;
exaltation -= annule;
if (dissolution > 0) {
const perdus = Math.min(dissolution, convertis);
convertis -= perdus;
dissolution -= perdus;
}
compteurs.experience.value += convertis + exaltation;
compteurs.dissolution.value = dissolution;
const perteDissolution = Math.max(0, Math.min(dissolution, conversion));
let stressRollData = {
alias: this.name,
selectedCarac: this.data.data.carac.reve,
rolled: stressRoll,
stress: stress,
perte: Math.min(conversion, stress),
convertis: conversion - perteDissolution,
xp: conversion - perteDissolution + exaltation,
dissolution: dissolution,
exaltation: exaltation
};
ChatMessage.create({
whisper: ChatUtility.getWhisperRecipientsAndGMs(game.user.name),
content: await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/chat-resultat-transformer-stress.html`, stressRollData)
});
let compteurs = duplicate(this.data.data.compteurs);
compteurs.stress.value = Math.max(stress - stressRollData.perte - 1, 0);
compteurs.experience.value += stressRollData.xp;
compteurs.dissolution.value = dissolution - perteDissolution;
compteurs.exaltation.value = 0;
message.content += "<br>Vous transformez " + convertis + " points de Stress en Expérience" + stressRoll.comment;
await this.update({ "data.compteurs": compteurs });
return true;
}
/* -------------------------------------------- */
async _stressRoll() {
let reveActuel = this.getReveActuel();
async _stressRoll(reveActuel) {
let result = await RdDResolutionTable.roll(reveActuel, 0);
console.log("_stressRoll", result);
switch (result.code) {
case "sign": return { factor: 0.75, comment: " (75%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "norm": return { factor: 0.5, comment: " (50%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "echec": return { factor: 0.2, comment: " (20%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "epart": return { factor: 0.1, comment: " (10%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "etotal": return { factor: 0, comment: " (0%): " + result.quality + " - " + result.roll + " sur " + result.score + "%" }
case "part":
{
let second = await RdDResolutionTable.roll(reveActuel, 0);
console.log("_stressRoll", second);
switch (second.code) {
case "part": case "sign":
return { factor: 1.5, comment: " (150%): Double Particulière - " + result.roll + " puis " + second.roll + " sur " + result.score + "%" }
default:
return { factor: 1, comment: " (100%): " + result.quality + " - " + result.roll + " puis " + second.roll + " sur " + result.score + "%" }
}
}
if (result.isPart) {
result.second = await RdDResolutionTable.roll(reveActuel, 0);
}
result.factor = this._getFacteurStress(result);
return result;
}
_getFacteurStress(stressRoll) {
switch (stressRoll.code) {
case "sign": return 75;
case "norm": return 50;
case "echec": return 20;
case "epart": return 10;
case "etotal": return 0;
case "part":
if (stressRoll.second.isSign) {
stressRoll.quality = "Double Particulière";
return 150;
}
return 100;
}
return 0;
}
/* -------------------------------------------- */

View File

@ -249,7 +249,7 @@ export class RdDCommands {
getCoutXpCarac(msg, params) {
if (params && params.length == 1) {
let to = Number(params[0]);
RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDUtility.getCaractXp(to)}`);
RdDCommands._chatAnswer(msg, `Coût pour passer une caractéristique de ${to - 1} à ${to}: ${RdDUtility.getCaracXp(to)}`);
}
else {
return false;

View File

@ -412,11 +412,11 @@ export class RdDUtility {
static getCaracNextXp(value) {
const nextValue = Number(value) + 1;
// xp est le coût pour atteindre cette valeur, on regarde donc le coût de la valeur+1
return RdDUtility.getCaractXp(nextValue);
return RdDUtility.getCaracXp(nextValue);
}
static getCaractXp(targetValue) {
return tableCaracDerivee[targetValue].xp;
static getCaracXp(targetValue) {
return tableCaracDerivee[targetValue]?.xp ?? 200 ;
}
/* -------------------------------------------- */

View File

@ -0,0 +1,18 @@
<h4>
{{alias}} transforme {{rolled.factor}}% de son stress
</h4>
{{> "systems/foundryvtt-reve-de-dragon/templates/chat-infojet.html"}}
{{#if rolled.isPart}}
<div>
<span>
Deuxième jet: {{rolled.second.roll}} <span class="rdd-roll-{{rolled.second.code}} strong-text">{{rolled.second.quality}}</span>
</span>
</div>
{{/if}}
<hr>
<span>
Transformation de {{perte}} points de stress sur {{stress}}
{{~#if (gt dissolution 0)}}; {{dissolution}} points perdus par la dissolution{{/if~}}
{{~#if (gt exaltation 0)}}; {{exaltation}} points gagnés par l'exaltation{{/if~}}
, gain de {{xp}} points d'expérience
</span>