2021-01-07 00:40:56 +01:00
|
|
|
import { RollDataAjustements } from "./rolldata-ajustements.js";
|
2020-12-06 19:29:10 +01:00
|
|
|
import { HtmlUtility } from "./html-utility.js";
|
2020-12-20 21:54:09 +01:00
|
|
|
import { RdDItemCompetence } from "./item-competence.js";
|
2020-12-06 19:29:10 +01:00
|
|
|
import { RdDItemSort } from "./item-sort.js";
|
|
|
|
import { Misc } from "./misc.js";
|
2020-12-16 23:02:15 +01:00
|
|
|
import { RdDBonus } from "./rdd-bonus.js";
|
2021-01-05 18:43:13 +01:00
|
|
|
import { RdDCarac } from "./rdd-carac.js";
|
2020-12-06 19:29:10 +01:00
|
|
|
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
2023-06-20 23:43:24 +02:00
|
|
|
import { ReglesOptionnelles } from "./settings/regles-optionnelles.js";
|
2020-12-06 19:29:10 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Extend the base Dialog entity to select roll parameters
|
|
|
|
* @extends {Dialog}
|
|
|
|
*/
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-06 19:29:10 +01:00
|
|
|
export class RdDRoll extends Dialog {
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-12-09 02:00:31 +01:00
|
|
|
static async create(actor, rollData, dialogConfig, action) {
|
|
|
|
RdDRoll._ensureCorrectAction(action);
|
2020-12-06 19:29:10 +01:00
|
|
|
RdDRoll._setDefaultOptions(actor, rollData);
|
|
|
|
|
2020-12-06 23:31:23 +01:00
|
|
|
const html = await renderTemplate(dialogConfig.html, rollData);
|
2020-12-06 19:29:10 +01:00
|
|
|
|
2023-11-21 21:07:37 +01:00
|
|
|
let options = { classes: ["rdd-roll-dialog"], width: 650, height: 'fit-content', 'z-index': 99999, close: html => { } };
|
2022-12-09 02:00:31 +01:00
|
|
|
if (dialogConfig.close) {
|
|
|
|
options.close = dialogConfig.close;
|
2020-12-06 23:31:23 +01:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
return new RdDRoll(actor, rollData, html, options, action);
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-06 19:29:10 +01:00
|
|
|
static _setDefaultOptions(actor, rollData) {
|
2020-12-15 08:37:52 +01:00
|
|
|
let defaultRollData = {
|
2024-11-15 00:01:55 +01:00
|
|
|
alias: actor.getAlias(),
|
2020-12-15 08:37:52 +01:00
|
|
|
ajustementsConditions: CONFIG.RDD.ajustementsConditions,
|
|
|
|
difficultesLibres: CONFIG.RDD.difficultesLibres,
|
2021-01-05 18:43:13 +01:00
|
|
|
etat: actor.getEtatGeneral(),
|
2021-02-09 23:23:40 +01:00
|
|
|
moral: actor.getMoralTotal(), /* La valeur du moral pour les jets de volonté */
|
2023-11-21 21:07:37 +01:00
|
|
|
amoureux: actor.listeSuivants(it => it.coeur > 0),
|
2022-11-23 22:34:39 +01:00
|
|
|
carac: actor.system.carac,
|
2020-12-15 08:37:52 +01:00
|
|
|
finalLevel: 0,
|
2021-01-13 03:42:13 +01:00
|
|
|
diffConditions: 0,
|
2022-04-30 23:42:55 +02:00
|
|
|
diffLibre: rollData.competence?.system.default_diffLibre ?? 0,
|
2021-03-16 21:49:21 +01:00
|
|
|
perteMoralEchec: false, /* Pour l'affichage dans le chat */
|
2022-11-19 01:35:01 +01:00
|
|
|
use: {
|
2023-12-08 22:26:29 +01:00
|
|
|
astrologique: true,
|
2022-11-23 22:34:39 +01:00
|
|
|
moral: false, /* Est-ce que le joueur demande d'utiliser le moral ? Utile si le joueur change plusieurs fois de carac associée. */
|
2022-11-19 01:35:01 +01:00
|
|
|
libre: true,
|
2023-11-21 21:07:37 +01:00
|
|
|
coeur: undefined,
|
2022-11-19 01:35:01 +01:00
|
|
|
conditions: true,
|
2022-11-23 22:34:39 +01:00
|
|
|
surenc: actor.isSurenc(),
|
|
|
|
encTotal: true
|
2022-11-19 01:35:01 +01:00
|
|
|
},
|
2022-11-23 22:34:39 +01:00
|
|
|
isMalusEncombrementTotal: RdDItemCompetence.isMalusEncombrementTotal(rollData.competence),
|
2021-01-05 18:39:12 +01:00
|
|
|
encTotal: actor.getEncTotal(),
|
2021-01-02 14:10:43 +01:00
|
|
|
ajustementAstrologique: actor.ajustementAstrologique(),
|
2021-01-13 03:42:13 +01:00
|
|
|
surprise: actor.getSurprise(false),
|
2021-06-28 20:19:02 +02:00
|
|
|
canClose: true,
|
|
|
|
isGM: game.user.isGM,
|
|
|
|
forceDiceResult: -1
|
2022-06-12 08:17:59 +02:00
|
|
|
}
|
|
|
|
// Mini patch :Ajout du rêve actuel
|
2022-12-09 02:00:31 +01:00
|
|
|
if (actor.system.type == "personnage") {
|
2022-11-23 22:34:39 +01:00
|
|
|
defaultRollData.carac["reve-actuel"] = actor.system.reve.reve
|
2022-06-12 08:17:59 +02:00
|
|
|
}
|
2021-04-24 00:50:20 +02:00
|
|
|
|
2024-05-01 09:13:21 +02:00
|
|
|
foundry.utils.mergeObject(rollData, defaultRollData, { recursive: true, overwrite: false });
|
2021-02-06 02:29:58 +01:00
|
|
|
if (rollData.forceCarac) {
|
2021-01-27 23:35:45 +01:00
|
|
|
rollData.carac = rollData.forceCarac;
|
|
|
|
}
|
2021-04-03 23:59:29 +02:00
|
|
|
rollData.diviseurSignificative = RdDRoll.getDiviseurSignificative(rollData);
|
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
RollDataAjustements.calcul(rollData, actor);
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
|
2021-04-03 23:59:29 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
static getDiviseurSignificative(rollData) {
|
|
|
|
let facteurSign = 1;
|
|
|
|
if (rollData.surprise == 'demi') {
|
|
|
|
facteurSign *= 2;
|
|
|
|
}
|
|
|
|
if (rollData.needParadeSignificative) {
|
|
|
|
facteurSign *= 2;
|
|
|
|
}
|
|
|
|
if (RdDBonus.isDefenseAttaqueFinesse(rollData)) {
|
|
|
|
facteurSign *= 2;
|
|
|
|
}
|
2023-06-20 23:43:24 +02:00
|
|
|
if (!ReglesOptionnelles.isUsing('tripleSignificative')) {
|
2021-04-03 23:59:29 +02:00
|
|
|
facteurSign = Math.min(facteurSign, 4);
|
|
|
|
}
|
|
|
|
return facteurSign;
|
|
|
|
}
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-12-09 02:00:31 +01:00
|
|
|
static _ensureCorrectAction(action) {
|
|
|
|
if (action.callbacks == undefined) {
|
|
|
|
console.warn('No callback defined for ', action.name);
|
|
|
|
action.callbacks = [{ action: r => console.warn(action.name, r) }];
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-12-09 02:00:31 +01:00
|
|
|
constructor(actor, rollData, html, options, action) {
|
2020-12-06 19:29:10 +01:00
|
|
|
let conf = {
|
2022-12-09 02:00:31 +01:00
|
|
|
title: action.label,
|
2020-12-06 19:29:10 +01:00
|
|
|
content: html,
|
2022-12-09 02:00:31 +01:00
|
|
|
buttons: {
|
|
|
|
"onAction": {
|
|
|
|
label: action.label, callback: html => {
|
|
|
|
this.rollData.canClose = true;
|
|
|
|
this.onAction(action)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
default: "onAction",
|
2022-12-06 01:30:12 +01:00
|
|
|
close: options.close
|
2020-12-06 19:29:10 +01:00
|
|
|
};
|
|
|
|
super(conf, options);
|
|
|
|
|
|
|
|
this.actor = actor;
|
|
|
|
this.rollData = rollData;
|
|
|
|
}
|
|
|
|
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html = html;
|
2020-12-06 19:29:10 +01:00
|
|
|
this.bringToTop();
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
console.log('RdDRoll.activateListeners', this.rollData);
|
2021-02-06 02:29:58 +01:00
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
// Update html, according to rollData
|
|
|
|
if (this.rollData.competence) {
|
|
|
|
const defaut_carac = this.rollData.competence.system.defaut_carac
|
|
|
|
// Set the default carac from the competence item
|
|
|
|
this.rollData.selectedCarac = this.rollData.carac[defaut_carac];
|
|
|
|
this.html.find("[name='carac']").val(defaut_carac);
|
2021-01-05 18:43:13 +01:00
|
|
|
}
|
2022-12-09 02:00:31 +01:00
|
|
|
if (this.rollData.selectedSort) {
|
|
|
|
this.setSelectedSort(this.rollData.selectedSort);
|
|
|
|
this.html.find(".draconic").val(this.rollData.selectedSort.system.listIndex); // Uniquement a la selection du sort, pour permettre de changer
|
|
|
|
}
|
|
|
|
RdDItemSort.setCoutReveReel(this.rollData.selectedSort);
|
|
|
|
this.html.find("[name='diffLibre']").val(Misc.toInt(this.rollData.diffLibre));
|
|
|
|
this.html.find("[name='diffConditions']").val(Misc.toInt(this.rollData.diffConditions));
|
|
|
|
this.updateRollResult(html);
|
2021-01-05 18:43:13 +01:00
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='diffLibre']").change((event) => {
|
2021-01-05 18:43:13 +01:00
|
|
|
this.rollData.diffLibre = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='diffConditions']").change((event) => {
|
2021-01-05 18:43:13 +01:00
|
|
|
this.rollData.diffConditions = Misc.toInt(event.currentTarget.value); // Update the selected bonus/malus
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='force-dice-result']").change((event) => {
|
2021-06-28 20:19:02 +02:00
|
|
|
this.rollData.forceDiceResult = Misc.toInt(event.currentTarget.value);
|
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='carac']").change((event) => {
|
2020-12-06 19:29:10 +01:00
|
|
|
let caracKey = event.currentTarget.value;
|
2021-01-05 18:43:13 +01:00
|
|
|
this.rollData.selectedCarac = this.rollData.carac[caracKey]; // Update the selectedCarac
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.roll-draconic').change((event) => {
|
2020-12-06 19:29:10 +01:00
|
|
|
let draconicKey = Misc.toInt(event.currentTarget.value);
|
2021-01-05 18:43:13 +01:00
|
|
|
this.rollData.competence = this.rollData.draconicList[draconicKey]; // Update the selectedCarac
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.roll-sort').change((event) => {
|
2020-12-06 19:29:10 +01:00
|
|
|
let sortKey = Misc.toInt(event.currentTarget.value);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.setSelectedSort(this.rollData.sortList[sortKey]);
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='diffLibre']").val(this.rollData.diffLibre);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.roll-carac-competence').change((event) => {
|
2022-11-19 01:37:00 +01:00
|
|
|
const competence = event.currentTarget.value;
|
|
|
|
this.rollData.competence = this.rollData.competences.find(it => it.name == competence);
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2022-11-19 01:37:00 +01:00
|
|
|
});
|
2023-11-21 21:07:37 +01:00
|
|
|
this.html.find('.select-suivant-coeur').change((event) => {
|
|
|
|
const selectedActorId = event.currentTarget.value;
|
|
|
|
this.rollData.use.coeur = this.actor.getSuivant(selectedActorId)
|
|
|
|
if (this.rollData.use.coeur) {
|
|
|
|
this.html.find(".utilisation-coeur img.selected-suivant-coeur").attr('src', this.rollData.use.coeur?.img)
|
|
|
|
this.html.find(".utilisation-coeur img.selected-suivant-coeur").attr('title', this.rollData.use.coeur?.name)
|
|
|
|
}
|
|
|
|
this.updateRollResult(html);
|
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.roll-signedraconique').change((event) => {
|
2021-05-10 19:18:11 +02:00
|
|
|
let sortKey = Misc.toInt(event.currentTarget.value);
|
|
|
|
this.setSelectedSigneDraconique(this.rollData.signes[sortKey]);
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2021-05-10 19:18:11 +02:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("[name='ptreve-variable']").change((event) => {
|
2020-12-06 19:29:10 +01:00
|
|
|
let ptreve = Misc.toInt(event.currentTarget.value);
|
2022-09-07 09:01:23 +02:00
|
|
|
this.rollData.selectedSort.system.ptreve_reel = ptreve;
|
2020-12-06 19:29:10 +01:00
|
|
|
console.log("RdDRollSelectDialog - Cout reve", ptreve);
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2023-10-30 21:33:38 +01:00
|
|
|
this.html.find("input.check-mortalite").change((event) => {
|
2020-12-16 23:02:15 +01:00
|
|
|
this.rollData.dmg.mortalite = event.currentTarget.checked ? "non-mortel" : "mortel";
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-12 21:58:44 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.cuisine-proportions').change((event) => {
|
2021-04-08 20:36:02 +02:00
|
|
|
this.rollData.proportions = Number(event.currentTarget.value);
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.select-by-name').change((event) => {
|
2021-04-09 01:05:32 +02:00
|
|
|
const attribute = event.currentTarget.attributes['name'].value;
|
|
|
|
this.rollData[attribute] = event.currentTarget.value;
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2021-04-09 01:05:32 +02:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.checkbox-by-name').change((event) => {
|
2021-04-08 20:36:02 +02:00
|
|
|
const attribute = event.currentTarget.attributes['name'].value;
|
|
|
|
this.rollData[attribute] = event.currentTarget.checked;
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2023-12-08 22:26:29 +01:00
|
|
|
this.html.find('input.use-astrologique').change((event) => {
|
|
|
|
this.rollData.use.astrologique = event.currentTarget.checked;
|
|
|
|
this.updateRollResult(html);
|
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('input.use-encTotal').change((event) => {
|
2022-11-19 01:35:01 +01:00
|
|
|
this.rollData.use.encTotal = event.currentTarget.checked;
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2022-11-19 01:35:01 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('input.use-surenc').change((event) => {
|
2022-11-19 01:35:01 +01:00
|
|
|
this.rollData.use.surenc = event.currentTarget.checked;
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2022-11-19 01:35:01 +01:00
|
|
|
});
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.appel-moral').click((event) => { /* l'appel au moral, qui donne un bonus de +1 */
|
2022-11-23 22:34:39 +01:00
|
|
|
this.rollData.use.moral = !this.rollData.use.moral;
|
2022-12-09 02:00:31 +01:00
|
|
|
const appelMoral = this.html.find('.icon-appel-moral')[0];
|
|
|
|
const tooltip = this.html.find('.tooltipAppelAuMoralText')[0];
|
2022-11-23 22:34:39 +01:00
|
|
|
if (this.rollData.use.moral) {
|
2021-03-16 21:49:21 +01:00
|
|
|
if (this.rollData.moral > 0) {
|
2021-05-19 00:55:00 +02:00
|
|
|
tooltip.innerHTML = "Appel au moral";
|
2021-05-19 09:36:39 +02:00
|
|
|
appelMoral.src = "/systems/foundryvtt-reve-de-dragon/icons/moral-heureux.svg";
|
2021-03-16 21:49:21 +01:00
|
|
|
} else {
|
2021-05-19 00:55:00 +02:00
|
|
|
tooltip.innerHTML = "Appel à l'énergie du désespoir";
|
2021-05-19 09:36:39 +02:00
|
|
|
appelMoral.src = "/systems/foundryvtt-reve-de-dragon/icons/moral-malheureux.svg";
|
2021-03-16 21:49:21 +01:00
|
|
|
}
|
|
|
|
} else {
|
2021-05-19 00:55:00 +02:00
|
|
|
tooltip.innerHTML = "Sans appel au moral";
|
2021-05-19 09:36:39 +02:00
|
|
|
appelMoral.src = "/systems/foundryvtt-reve-de-dragon/icons/moral-neutre.svg";
|
2021-03-16 21:49:21 +01:00
|
|
|
}
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2021-03-16 21:49:21 +01:00
|
|
|
});
|
2021-01-04 22:03:00 +01:00
|
|
|
// Section Méditation
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find('.conditionMeditation').change((event) => {
|
2022-12-06 01:30:12 +01:00
|
|
|
let condition = event.currentTarget.attributes['name'].value;
|
2021-01-05 18:43:13 +01:00
|
|
|
this.rollData.conditionMeditation[condition] = event.currentTarget.checked;
|
2022-12-06 01:30:12 +01:00
|
|
|
this.updateRollResult(html);
|
2021-01-04 22:03:00 +01:00
|
|
|
});
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
close() {
|
|
|
|
if (this.rollData.canClose) {
|
|
|
|
return super.close();
|
|
|
|
}
|
|
|
|
ui.notifications.info("Vous devez faire ce jet de dés!");
|
|
|
|
}
|
|
|
|
|
|
|
|
async onAction(action) {
|
|
|
|
this.rollData.forceDiceResult = Number.parseInt(this.html.find("[name='force-dice-result']").val()) ?? -1;
|
|
|
|
await RdDResolutionTable.rollData(this.rollData);
|
|
|
|
console.log("RdDRoll -=>", this.rollData, this.rollData.rolled);
|
|
|
|
if (action.callbacks)
|
|
|
|
for (let callback of action.callbacks) {
|
|
|
|
if (callback.condition == undefined || callback.condition(this.rollData)) {
|
|
|
|
await callback.action(this.rollData);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
async setSelectedSort(sort) {
|
2021-04-24 00:50:20 +02:00
|
|
|
this.rollData.selectedSort = sort; // Update the selectedCarac
|
2022-06-12 08:17:59 +02:00
|
|
|
this.rollData.competence = RdDItemCompetence.getVoieDraconic(this.rollData.draconicList, sort.system.draconic);
|
2021-04-24 00:50:20 +02:00
|
|
|
this.rollData.bonus = RdDItemSort.getCaseBonus(sort, this.rollData.tmr.coord);
|
|
|
|
this.rollData.diffLibre = RdDItemSort.getDifficulte(sort, -7);
|
|
|
|
RdDItemSort.setCoutReveReel(sort);
|
|
|
|
const htmlSortDescription = await renderTemplate("systems/foundryvtt-reve-de-dragon/templates/partial-description-sort.html", { sort: sort });
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find(".sort-ou-rituel").text(sort.system.isrituel ? "rituel" : "sort");
|
|
|
|
this.html.find(".bonus-case").text(`${this.rollData.bonus}%`);
|
|
|
|
this.html.find(".placeholder-description-sort").children().remove();
|
|
|
|
this.html.find(".placeholder-description-sort").append(htmlSortDescription);
|
|
|
|
this.html.find(".roll-draconic").val(sort.system.listIndex);
|
|
|
|
this.html.find(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.system.difficulte));
|
|
|
|
this.html.find(".div-sort-ptreve-fixe").text(sort.system.ptreve);
|
2021-04-24 00:50:20 +02:00
|
|
|
const diffVariable = RdDItemSort.isDifficulteVariable(sort);
|
|
|
|
const coutVariable = RdDItemSort.isCoutVariable(sort);
|
2022-11-19 01:35:01 +01:00
|
|
|
|
2023-01-10 22:11:16 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".div-sort-non-rituel"), !sort.system.isrituel);
|
|
|
|
HtmlUtility.showControlWhen(this.html.find(".div-sort-difficulte-var"), diffVariable);
|
|
|
|
HtmlUtility.showControlWhen(this.html.find(".div-sort-difficulte-fixe"), !diffVariable);
|
|
|
|
HtmlUtility.showControlWhen(this.html.find(".div-sort-ptreve-var"), coutVariable);
|
|
|
|
HtmlUtility.showControlWhen(this.html.find(".div-sort-ptreve-fixe"), !coutVariable);
|
2021-04-24 00:50:20 +02:00
|
|
|
}
|
|
|
|
|
2022-12-09 02:00:31 +01:00
|
|
|
async setSelectedSigneDraconique(signe) {
|
2021-05-10 19:18:11 +02:00
|
|
|
this.rollData.signe = signe;
|
2022-09-07 00:09:17 +02:00
|
|
|
this.rollData.diffLibre = signe.system.difficulte,
|
2022-12-09 02:00:31 +01:00
|
|
|
$(".signe-difficulte").text(Misc.toSignedString(this.rollData.diffLibre));
|
2021-05-10 19:18:11 +02:00
|
|
|
}
|
|
|
|
|
2021-01-29 20:10:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-12-06 01:30:12 +01:00
|
|
|
async updateRollResult(html) {
|
2023-10-30 21:33:38 +01:00
|
|
|
const rollData = this.rollData;
|
2021-03-16 21:49:21 +01:00
|
|
|
|
2024-09-27 02:32:13 +02:00
|
|
|
rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor)
|
2022-06-12 08:17:59 +02:00
|
|
|
rollData.caracValue = parseInt(rollData.selectedCarac.value)
|
2023-10-30 21:33:38 +01:00
|
|
|
rollData.dmg.mortalite = rollData.dmg.mortalite ?? 'mortel';
|
2021-03-16 21:49:21 +01:00
|
|
|
rollData.use.appelAuMoral = this.actor.isPersonnage() && RdDCarac.isActionPhysique(rollData.selectedCarac);
|
2021-02-09 23:23:40 +01:00
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
RollDataAjustements.calcul(rollData, this.actor);
|
2021-02-06 02:29:58 +01:00
|
|
|
|
2022-12-06 01:30:12 +01:00
|
|
|
const resolutionTable = await RdDResolutionTable.buildHTMLTable(RdDResolutionTable.subTable(rollData.caracValue, rollData.finalLevel))
|
|
|
|
const adjustements = await this.buildAjustements(rollData);
|
2023-11-21 21:07:37 +01:00
|
|
|
|
2023-01-13 01:48:00 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".use-encTotal"), rollData.ajustements.encTotal.visible && RdDCarac.isAgiliteOuDerobee(rollData.selectedCarac));
|
2023-01-10 22:11:16 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".use-surenc"), rollData.ajustements.surenc.visible && RdDCarac.isActionPhysique(rollData.selectedCarac));
|
2023-12-08 22:26:29 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".use-astrologique"), rollData.ajustements.astrologique.visible);
|
2023-01-10 22:11:16 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".utilisation-moral"), rollData.use.appelAuMoral);
|
|
|
|
HtmlUtility.showControlWhen(this.html.find(".divAppelAuMoral"), rollData.use.appelAuMoral);
|
2023-11-21 21:07:37 +01:00
|
|
|
HtmlUtility.showControlWhen(this.html.find(".utilisation-coeur"), rollData.ajustements.coeur.visible);
|
|
|
|
HtmlUtility.showControlWhen(this.html.find(".utilisation-coeur img.selected-suivant-coeur"), rollData.ajustements.coeur.visible && rollData.use.coeur != undefined)
|
2023-10-30 21:33:38 +01:00
|
|
|
// HtmlUtility.showControlWhen(this.html.find(".diffMoral"), rollData.ajustements.moral.used);
|
2021-01-05 18:43:13 +01:00
|
|
|
|
|
|
|
// Mise à jour valeurs
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find(".dialog-roll-title").text(this._getTitle(rollData));
|
2023-10-30 21:33:38 +01:00
|
|
|
this.html.find("input.check-mortalite").prop('checked', rollData.dmg.mortalite == 'non-mortel');
|
2023-11-21 21:07:37 +01:00
|
|
|
this.html.find("label.dmg-arme-actor").text(rollData.dmg.mortalite == 'empoignade' ? 'empoignade' : Misc.toSignedString(rollData.dmg.total));
|
2023-10-30 21:33:38 +01:00
|
|
|
this.html.find("label.arme-mortalite").text(rollData.dmg.mortalite);
|
|
|
|
// this.html.find("[name='dmg-arme-actor']").text(rollData.dmg.mortalite == 'empoignade'? 'empoignade': Misc.toSignedString(rollData.dmg.total) );
|
|
|
|
// this.html.find("[name='arme-mortalite']").text(rollData.dmg.mortalite);
|
2022-12-09 02:00:31 +01:00
|
|
|
this.html.find("div.placeholder-ajustements").empty().append(adjustements);
|
|
|
|
this.html.find("div.placeholder-resolution").empty().append(resolutionTable)
|
2021-01-05 18:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2021-01-29 20:10:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2021-02-06 02:29:58 +01:00
|
|
|
async buildAjustements(rollData) {
|
2022-12-06 01:30:12 +01:00
|
|
|
return await renderTemplate(`systems/foundryvtt-reve-de-dragon/templates/partial-roll-ajustements.html`, rollData);
|
2021-01-04 22:03:00 +01:00
|
|
|
}
|
|
|
|
|
2020-12-06 19:29:10 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-18 23:57:28 +01:00
|
|
|
_getTitle(rollData) {
|
2024-11-15 00:01:55 +01:00
|
|
|
const alias = rollData.alias
|
2022-06-12 08:17:59 +02:00
|
|
|
const carac = rollData.selectedCarac.label;
|
2021-01-14 00:50:12 +01:00
|
|
|
if (!rollData.competence) {
|
2024-11-15 00:01:55 +01:00
|
|
|
return `${alias}: ${carac}`
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
2022-06-12 08:17:59 +02:00
|
|
|
const compName = rollData.competence.name;
|
2022-04-30 23:42:55 +02:00
|
|
|
const niveau = Misc.toSignedString(rollData.competence.system.niveau)
|
2021-01-14 00:50:12 +01:00
|
|
|
if (compName == carac) {
|
|
|
|
// cas des créatures
|
2024-11-15 00:01:55 +01:00
|
|
|
return `${alias}: ${carac} Niveau ${niveau}`
|
2023-10-30 21:33:38 +01:00
|
|
|
}
|
|
|
|
if (rollData.draconicList && rollData.selectedSort) {
|
|
|
|
// cas de lancer de sort
|
2024-11-15 00:01:55 +01:00
|
|
|
return `${alias}: ${rollData.competence.name} Niveau ${niveau} ${rollData.selectedSort.name}`
|
2023-10-30 21:33:38 +01:00
|
|
|
}
|
|
|
|
if (rollData.arme && rollData.arme.name != compName) {
|
|
|
|
// ajouter l'arme au titre si son nom n'est pas la compétence
|
2024-11-15 00:01:55 +01:00
|
|
|
return `${alias}: ${carac} / ${compName} (${rollData.arme.name}) Niveau ${niveau}`
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
2024-11-15 00:01:55 +01:00
|
|
|
return `${alias}: ${carac} / ${compName} Niveau ${niveau}`
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
}
|