#42 Tchat message fin

parade, esquive

 inclus deterioration arme de parade
 inclus recul sous le choc
This commit is contained in:
Vincent Vandemeulebrouck
2021-01-02 04:28:43 +01:00
parent cd36331702
commit 0a3f578bf3
19 changed files with 428 additions and 337 deletions

View File

@ -1,6 +1,10 @@
import { ChatUtility } from "./chat-utility.js";
import { RdDItemArme } from "./item-arme.js";
import { Misc } from "./misc.js";
import { RdDBonus } from "./rdd-bonus.js";
import { RdDCombat } from "./rdd-combat.js";
import { RdDDice } from "./rdd-dice.js";
import { RdDRollTables } from "./rdd-rolltables.js";
/**
* difficultés au delà de -10
@ -82,25 +86,30 @@ 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.needSignificative ? "(significative sur " : "(")
message += (rolled.diviseur > 1 ? `(1/${rolled.diviseur} de ` : "(")
+ rolled.caracValue + " à " + Misc.toSignedString(rolled.finalLevel) + ") ";
}
message += '<strong>' + rolled.quality + '</strong>'
return message;
}
static async explainRollDataV2(rollData, template = 'chat-resultat-general.html') {
static async buildRollDataHtml(rollData, template = 'chat-resultat-general.html') {
rollData.ajustements = RdDResolutionTable._buildAjustements(rollData);
rollData.show = rollData.show || {};
let html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/${template}`, rollData);
return html;
return await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/${template}`, rollData);
}
static async displayRollData(rollData, userName, template = 'chat-resultat-general.html') {
let html = await RdDResolutionTable.buildRollDataHtml(rollData, template);
ChatUtility.chatWithRollMode({ content: html }, userName)
}
static _buildAjustements(rollData) {
let list = [];
if (rollData.competence) {
list.push({ label: rollData.competence.name, value: rollData.competence.data.niveau});
list.push({ label: rollData.competence.name, value: rollData.competence.data.niveau });
}
if (rollData.tactique) {
const surprise = RdDBonus.find(rollData.tactique);
@ -124,64 +133,61 @@ export class RdDResolutionTable {
list.push({ label: 'Moral', value: rollData.selectedCarac != undefined && rollData.moral != undefined && rollData.selectedCarac.label == 'Volonté' ? rollData.moral : undefined });
}
if (RdDResolutionTable.isAjustementAstrologique(rollData)) {
list.push({ label: 'Astrologique', value: rollData.ajustementAstrologique||0 });
list.push({ label: 'Astrologique', value: rollData.ajustementAstrologique || 0 });
}
if (rollData.rolled.bonus && rollData.selectedSort) {
list.push({ label: 'Bonus de case', value: rollData.rolled.bonus, unit: '%' });
list.push({ descr: `Bonus de case: ${rollData.rolled.bonus}%` });
}
if (rollData.diviseur > 1) {
list.push({ descr: `Facteur significative &times;${RdDResolutionTable._getFractionHtml(rollData.diviseur)}` });
}
if (RdDCombat.isAttaqueFinesse(rollData.attackerRoll)) {
list.push({ descr: 'Attaque particulière en finesse' });
}
if (rollData.needParadeSignificative) {
const catAttaque = RdDItemArme.getNomCategorieParade(rollData.attackerRoll.arme);
const catParade = RdDItemArme.getNomCategorieParade(rollData.arme);
list.push({ descr: `${catAttaque} vs ${catParade}` });
}
if (rollData.surprise) {
list.push({ descr: RdDBonus.find(rollData.surprise).descr });
}
return list;
}
static explainRollData(rollData) {
let parts = RdDResolutionTable._buildAjustementsList(rollData);
let message = parts.length > 0 ? "<br>Difficulté " + parts.reduce((a, b) => a + ' / ' + b) : "";
return message+ RdDResolutionTable.explain(rollData.rolled)
}
static _buildAjustementsList(rollData) {
let parts = [];
if (rollData.diffLibre != undefined) {
parts.push(`<strong>libre: ${rollData.diffLibre}</strong>`);
static _getFractionHtml(diviseur) {
if (!diviseur || diviseur <= 1) return undefined;
switch (diviseur || 1) {
case 2: return '&frac12;';
case 4: return '&frac14;';
default: return '1/' + diviseur;
}
if (rollData.diffConditions != undefined) {
parts.push(`conditions: ${Misc.toSignedString(rollData.diffConditions)}`);
}
if (rollData.etat != undefined) {
parts.push(`état: ${rollData.etat}`);
}
if (rollData.selectedCarac != undefined && rollData.moral != undefined && rollData.selectedCarac.label == 'Volonté') {
parts.push(`moral: ${rollData.moral}`);
}
return parts;
}
/* -------------------------------------------- */
static async rollData(rollData) {
rollData.rolled = await this.roll(rollData.caracValue, rollData.finalLevel, rollData.bonus, rollData.needSignificative, rollData.showDice);
rollData.rolled = await this.roll(rollData.caracValue, rollData.finalLevel, rollData.bonus, rollData.diviseur, rollData.showDice);
return rollData;
}
/* -------------------------------------------- */
static async roll(caracValue, finalLevel, bonus = undefined, needSignificative = undefined, showDice = true) {
static async roll(caracValue, finalLevel, bonus = undefined, diviseur = undefined, showDice = true) {
let chances = this.computeChances(caracValue, finalLevel);
this._updateChancesWithBonus(chances, bonus);
this._updateChancesNeedSignificative(chances, needSignificative);
this._updateChancesFactor(chances, diviseur);
chances.showDice = showDice;
let rolled = await this.rollChances(chances);
rolled.caracValue = caracValue;
rolled.finalLevel = finalLevel;
rolled.bonus = bonus;
rolled.needSignificative = needSignificative;
rolled.factor = RdDResolutionTable._getFractionHtml(diviseur);
return rolled;
}
/* -------------------------------------------- */
static _updateChancesNeedSignificative(chances, needSignificative) {
if (needSignificative) {
let newScore = Math.floor(Number(chances.score) / 2);
static _updateChancesFactor(chances, diviseur) {
if (diviseur && diviseur > 1) {
let newScore = Math.floor(Number(chances.score) / diviseur);
mergeObject(chances, this._computeCell(null, newScore), { overwrite: true });
}
}
@ -261,16 +267,7 @@ export class RdDResolutionTable {
/* -------------------------------------------- */
static _computeReussite(chances, roll) {
const reussite = reussites.find(x => x.condition(chances, roll));
if (chances.needSignificative) {
if (reussite.isSign) {
return reussiteNormale;
}
if (reussite.isSuccess) {
return echecNormal;
}
}
return reussite;
return reussites.find(x => x.condition(chances, roll));
}
/* -------------------------------------------- */