Amélioration fenêtre de Tchat #42

This commit is contained in:
Vincent Vandemeulebrouck
2020-12-31 02:08:58 +01:00
parent 77ed4f1482
commit dbe37233d5
7 changed files with 142 additions and 44 deletions

View File

@ -1548,17 +1548,12 @@ export class RdDActor extends Actor {
/* -------------------------------------------- */
async _rollCaracResult(rollData) {
let rolled = rollData.rolled;
let resumeCompetence = (rollData.diffLibre + rollData.diffConditions);
let explications = "<br>Points de taches : " + rolled.ptTache;
rollData.show = {
title: rollData.selectedCarac.label,
points: true
};
// Final chat message
let chatOptions = {
content: "<strong>Test : " + rollData.selectedCarac.label + " / " + resumeCompetence + "</strong>"
+ RdDResolutionTable.explainRollData(rollData)
+ explications
}
let chatOptions = { content: await RdDResolutionTable.explainRollDataV2(rollData) }
ChatUtility.chatWithRollMode(chatOptions, this.name)
}

View File

@ -88,7 +88,47 @@ export class RdDResolutionTable {
return message;
}
static async explainRollDataV2(rollData, template = 'chat-resultat-rdd.html') {
rollData.ajustements = RdDResolutionTable._buildAjustements(rollData);
rollData.show = rollData.show || {};
let html = await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/${template}`, rollData);
return html;
}
static _buildAjustements(rollData) {
let list = [];
if (rollData.competence) {
list.push({ label: rollData.competence.name, value: rollData.competence.data.niveau});
}
if (rollData.diffLibre != undefined) {
const label = rollData.selectedSort ? rollData.selectedSort.name : 'libre';
list.push({ label: label, value: rollData.diffLibre });
}
if (rollData.diffConditions != undefined) {
list.push({ label: 'conditions', value: rollData.diffConditions });
}
if (rollData.etat != undefined) {
list.push({ label: 'état', value: rollData.etat });
}
if (rollData.selectedCarac != undefined && rollData.moral != undefined && rollData.selectedCarac.label == 'Volonté') {
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 });
}
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>`);
@ -102,9 +142,7 @@ export class RdDResolutionTable {
if (rollData.selectedCarac != undefined && rollData.moral != undefined && rollData.selectedCarac.label == 'Volonté') {
parts.push(`moral: ${rollData.moral}`);
}
let message = parts.length > 0 ? "<br>Difficulté " + parts.reduce((a, b) => a + ' / ' + b) : "";
return message+ RdDResolutionTable.explain(rollData.rolled)
return parts;
}
/* -------------------------------------------- */
@ -165,6 +203,16 @@ export class RdDResolutionTable {
return duplicate(this.resolutionTable[caracValue][difficulte + 10]);
}
static isAjustementAstrologique(rollData) {
if (rollData.selectedCarac.label.toLowerCase().includes('chance')) {
return true;
}
if (rollData.selectedSort && rollData.selectedSort.data.isrituel) {
return true;
}
return false;
}
/* -------------------------------------------- */
static isEchec(rollData) {
switch (rollData.surprise) {

View File

@ -2,6 +2,7 @@ import { ChatUtility } from "./chat-utility.js";
import { Misc } from "./misc.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
const titleTableDeResolution = 'Table de résolution';
/**
* Extend the base Dialog entity to select roll parameters
* @extends {Dialog}
@ -21,6 +22,7 @@ export class RdDRollResolution extends Dialog {
static _setDefaultOptions(rollData) {
let defRollData = {
show: {title: titleTableDeResolution, points:true},
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
difficultesLibres: CONFIG.RDD.difficultesLibres,
etat: 0,
@ -36,15 +38,13 @@ export class RdDRollResolution extends Dialog {
if (rollData.selectedCarac == i) {
rollData.selectedCarac = rollData.carac[i];
}
}
}
/* -------------------------------------------- */
constructor(rollData, html) {
let conf = {
title: 'Lancer les dés',
title: titleTableDeResolution,
content: html,
buttons: {
'lancer': { label: 'Lancer les dés', callback: html => this.onAction(html) }
@ -59,9 +59,7 @@ export class RdDRollResolution extends Dialog {
async onAction(html) {
await RdDResolutionTable.rollData(this.rollData);
console.log("RdDRollResolution -=>", this.rollData, this.rollData.rolled);
const message = {
content: "Table de résolution: " + RdDResolutionTable.explainRollData(this.rollData)
};
const message = { content: await RdDResolutionTable.explainRollDataV2(this.rollData)};
ChatUtility.chatWithRollMode(message, game.user.name)
}
@ -121,9 +119,4 @@ export class RdDRollResolution extends Dialog {
_computeDiffLibre(rollData) {
return Misc.toInt(rollData.diffLibre);
}
/* -------------------------------------------- */
_getTitle(rollData) {
return 'Table de résolution';
}
}

View File

@ -121,7 +121,7 @@ export class RdDRoll extends Dialog {
HtmlUtility._showControlWhen($(".diffMoral"), rollData.selectedCarac == actor.data.data.carac.volonte);
HtmlUtility._showControlWhen($("#etat-general"), !dialog._isIgnoreEtatGeneral(rollData));
HtmlUtility._showControlWhen($("#ajust-astrologique"), dialog._isAjustementAstrologique(rollData));
HtmlUtility._showControlWhen($("#ajust-astrologique"), RdDResolutionTable.isAjustementAstrologique(rollData));
// Sort management
if (rollData.selectedSort) {
@ -229,7 +229,7 @@ export class RdDRoll extends Dialog {
const malusEnc = (rollData.surencMalusApply) ? rollData.surencMalusValue : 0;
const bonusTactique = RdDBonus.bonusAttaque(rollData.tactique);
const malusEncTotal = (rollData.useMalusEncTotal) ? -rollData.encTotal : 0;
const ajustementChance = this._isAjustementAstrologique(rollData) ? rollData.ajustementAstrologique : 0;
const ajustementChance = RdDResolutionTable.isAjustementAstrologique(rollData) ? rollData.ajustementAstrologique : 0;
// Gestion malus armure
const malusArmureValue = this._computeMalusArmure(rollData);
@ -240,16 +240,6 @@ export class RdDRoll extends Dialog {
return etat + diffCompetence + diffLibre + diffMoral + diffConditions + malusEnc + malusEncTotal + malusArmureValue + ajustementChance + bonusTactique;
}
_isAjustementAstrologique(rollData) {
if (rollData.selectedCarac.label.toLowerCase().includes('chance')) {
return true;
}
if (rollData.selectedSort && rollData.selectedSort.data.isrituel) {
return true;
}
return false;
}
_computeDiffCompetence(rollData) {
if (rollData.competence) {
return Misc.toInt(rollData.competence.data.niveau);