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";
|
2022-11-06 21:39:03 +01:00
|
|
|
import { ReglesOptionelles } from "./settings/regles-optionelles.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
|
|
|
/* -------------------------------------------- */
|
2020-12-06 23:31:23 +01:00
|
|
|
static async create(actor, rollData, dialogConfig, ...actions) {
|
|
|
|
RdDRoll._ensureCorrectActions(actions);
|
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
|
|
|
|
2022-12-06 01:30:12 +01:00
|
|
|
let options = { classes: [ "rdd-roll-dialog"], width: 600, height: 'fit-content', 'z-index': 99999 };
|
2020-12-06 23:31:23 +01:00
|
|
|
if (dialogConfig.options) {
|
|
|
|
mergeObject(options, dialogConfig.options, { overwrite: true })
|
|
|
|
}
|
2022-12-06 01:30:12 +01:00
|
|
|
return new RdDRoll(actor, rollData, html, options, actions);
|
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 = {
|
2021-01-02 04:28:43 +01:00
|
|
|
alias: actor.name,
|
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é */
|
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: {
|
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,
|
|
|
|
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),
|
|
|
|
malusArmureValue: actor.getMalusArmure(),
|
|
|
|
surencMalusValue: actor.computeMalusSurEncombrement(),
|
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-11-23 22:34:39 +01:00
|
|
|
if ( actor.system.type == "personnage") {
|
|
|
|
defaultRollData.carac["reve-actuel"] = actor.system.reve.reve
|
2022-06-12 08:17:59 +02:00
|
|
|
}
|
2021-04-24 00:50:20 +02:00
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
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
|
|
|
}
|
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;
|
|
|
|
}
|
|
|
|
if (!ReglesOptionelles.isUsing('tripleSignificative')) {
|
|
|
|
facteurSign = Math.min(facteurSign, 4);
|
|
|
|
}
|
|
|
|
return facteurSign;
|
|
|
|
}
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-06 19:29:10 +01:00
|
|
|
static _ensureCorrectActions(actions) {
|
2020-12-06 23:31:23 +01:00
|
|
|
if (actions.length == 0) {
|
2020-12-06 19:29:10 +01:00
|
|
|
throw 'No action defined';
|
|
|
|
}
|
|
|
|
actions.forEach(action => {
|
|
|
|
if (action.callbacks == undefined) {
|
2020-12-06 23:31:23 +01:00
|
|
|
action.callbacks = [{ action: r => console.log(action.name, r) }];
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2022-12-06 01:30:12 +01:00
|
|
|
constructor(actor, rollData, html, options, actions) {
|
2020-12-06 19:29:10 +01:00
|
|
|
let conf = {
|
|
|
|
title: actions[0].label,
|
|
|
|
content: html,
|
|
|
|
buttons: {},
|
2020-12-28 10:17:40 +01:00
|
|
|
default: actions[0].name,
|
2022-12-06 01:30:12 +01:00
|
|
|
close: options.close
|
2020-12-06 19:29:10 +01:00
|
|
|
};
|
|
|
|
for (let action of actions) {
|
2021-02-06 02:29:58 +01:00
|
|
|
conf.buttons[action.name] = {
|
|
|
|
label: action.label, callback: html => {
|
|
|
|
this.rollData.canClose = true;
|
|
|
|
this.onAction(action, html)
|
|
|
|
}
|
|
|
|
};
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
super(conf, options);
|
|
|
|
|
|
|
|
this.actor = actor;
|
|
|
|
this.rollData = rollData;
|
|
|
|
}
|
|
|
|
|
2021-02-06 02:29:58 +01:00
|
|
|
close() {
|
|
|
|
if (this.rollData.canClose) {
|
|
|
|
return super.close();
|
|
|
|
}
|
|
|
|
ui.notifications.info("Vous devez faire ce jet de dés!");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-16 23:02:15 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-06 19:29:10 +01:00
|
|
|
async onAction(action, html) {
|
2022-12-06 01:30:12 +01:00
|
|
|
this.rollData.forceDiceResult = Number.parseInt(html.find("[name='force-dice-result']").val()) ?? -1;
|
2020-12-06 19:29:10 +01:00
|
|
|
await RdDResolutionTable.rollData(this.rollData);
|
2020-12-08 23:07:41 +01:00
|
|
|
console.log("RdDRoll -=>", this.rollData, this.rollData.rolled);
|
2020-12-06 19:29:10 +01:00
|
|
|
if (action.callbacks)
|
2020-12-06 23:31:23 +01:00
|
|
|
for (let callback of action.callbacks) {
|
|
|
|
if (callback.condition == undefined || callback.condition(this.rollData)) {
|
2021-03-18 00:41:26 +01:00
|
|
|
await callback.action(this.rollData);
|
2020-12-06 23:31:23 +01:00
|
|
|
}
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
activateListeners(html) {
|
|
|
|
super.activateListeners(html);
|
|
|
|
|
|
|
|
this.bringToTop();
|
|
|
|
|
2020-12-18 23:57:28 +01:00
|
|
|
var dialog = this;
|
2021-02-06 02:29:58 +01:00
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
function onLoad() {
|
|
|
|
let rollData = dialog.rollData;
|
2022-09-07 00:09:17 +02:00
|
|
|
console.log('Ouverture RdDRoll', rollData);
|
2022-09-07 18:47:56 +02:00
|
|
|
// Update html, according to rollData
|
2020-12-06 19:29:10 +01:00
|
|
|
if (rollData.competence) {
|
2022-04-30 23:42:55 +02:00
|
|
|
const defaut_carac = rollData.competence.system.defaut_carac
|
2020-12-06 19:29:10 +01:00
|
|
|
// Set the default carac from the competence item
|
2022-06-12 08:17:59 +02:00
|
|
|
rollData.selectedCarac = rollData.carac[defaut_carac];
|
2022-12-06 01:30:12 +01:00
|
|
|
html.find("[name='carac']").val(defaut_carac);
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
2021-02-02 07:56:45 +01:00
|
|
|
if (rollData.selectedSort) {
|
2022-12-06 01:30:12 +01:00
|
|
|
dialog.setSelectedSort(rollData.selectedSort, html);
|
|
|
|
html.find(".draconic").val(rollData.selectedSort.system.listIndex); // Uniquement a la selection du sort, pour permettre de changer
|
2021-02-02 07:56:45 +01:00
|
|
|
}
|
2020-12-06 19:29:10 +01:00
|
|
|
RdDItemSort.setCoutReveReel(rollData.selectedSort);
|
2022-12-06 01:30:12 +01:00
|
|
|
html.find("[name='diffLibre']").val(Misc.toInt(rollData.diffLibre));
|
|
|
|
html.find("[name='diffConditions']").val(Misc.toInt(rollData.diffConditions));
|
|
|
|
dialog.updateRollResult(html);
|
2021-01-05 18:43:13 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Setup everything onload
|
|
|
|
$(function () { onLoad(); });
|
2020-12-06 19:29:10 +01:00
|
|
|
|
|
|
|
// Update !
|
2022-12-06 01:30:12 +01:00
|
|
|
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-06 01:30:12 +01:00
|
|
|
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-06 01:30:12 +01:00
|
|
|
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-06 01:30:12 +01:00
|
|
|
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
|
|
|
});
|
2021-04-24 00:50:20 +02:00
|
|
|
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
|
|
|
});
|
2021-04-24 00:50:20 +02:00
|
|
|
html.find('.roll-sort').change((event) => {
|
2020-12-06 19:29:10 +01:00
|
|
|
let sortKey = Misc.toInt(event.currentTarget.value);
|
2022-12-06 01:30:12 +01:00
|
|
|
this.setSelectedSort(this.rollData.sortList[sortKey], html);
|
|
|
|
this.updateRollResult(html);
|
|
|
|
html.find("[name='diffLibre']").val(this.rollData.diffLibre);
|
2020-12-06 19:29:10 +01:00
|
|
|
});
|
2022-11-19 01:37:00 +01:00
|
|
|
html.find('.roll-carac-competence').change((event) => {
|
|
|
|
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
|
|
|
});
|
2021-05-10 19:18:11 +02:00
|
|
|
html.find('.roll-signedraconique').change((event) => {
|
|
|
|
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-06 01:30:12 +01:00
|
|
|
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
|
|
|
});
|
2021-06-28 16:08:45 +02:00
|
|
|
html.find("[name='coupsNonMortels']").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
|
|
|
});
|
2021-04-08 20:36:02 +02:00
|
|
|
html.find('.cuisine-proportions').change((event) => {
|
|
|
|
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
|
|
|
});
|
2021-04-09 01:05:32 +02:00
|
|
|
html.find('.select-by-name').change((event) => {
|
|
|
|
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
|
|
|
});
|
2021-04-08 20:36:02 +02:00
|
|
|
html.find('.checkbox-by-name').change((event) => {
|
|
|
|
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
|
|
|
});
|
2022-11-19 01:35:01 +01:00
|
|
|
html.find('input.use-encTotal').change((event) => {
|
|
|
|
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
|
|
|
});
|
|
|
|
html.find('input.use-surenc').change((event) => {
|
|
|
|
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
|
|
|
});
|
2021-05-19 00:55:00 +02:00
|
|
|
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;
|
2021-05-19 00:55:00 +02:00
|
|
|
const appelMoral = html.find('.icon-appel-moral')[0];
|
|
|
|
const tooltip = 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
|
2021-01-05 18:43:13 +01:00
|
|
|
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-06 01:30:12 +01:00
|
|
|
async setSelectedSort(sort, html) {
|
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-06 01:30:12 +01:00
|
|
|
html.find(".sort-ou-rituel").text(sort.system.isrituel ? "rituel" : "sort");
|
|
|
|
html.find(".bonus-case").text(`${this.rollData.bonus}%`);
|
|
|
|
html.find(".details-sort").remove();
|
|
|
|
html.find(".description-sort").append(htmlSortDescription);
|
|
|
|
html.find(".roll-draconic").val(sort.system.listIndex);
|
|
|
|
html.find(".div-sort-difficulte-fixe").text(Misc.toSignedString(sort.system.difficulte));
|
|
|
|
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
|
|
|
|
2022-12-06 01:30:12 +01:00
|
|
|
HtmlUtility._showControlWhen(html.find(".div-sort-non-rituel"), !sort.system.isrituel);
|
|
|
|
HtmlUtility._showControlWhen(html.find(".div-sort-difficulte-var"), diffVariable);
|
|
|
|
HtmlUtility._showControlWhen(html.find(".div-sort-difficulte-fixe"), !diffVariable);
|
|
|
|
HtmlUtility._showControlWhen(html.find(".div-sort-ptreve-var"), coutVariable);
|
|
|
|
HtmlUtility._showControlWhen(html.find(".div-sort-ptreve-fixe"), !coutVariable);
|
2021-04-24 00:50:20 +02:00
|
|
|
}
|
|
|
|
|
2022-06-12 08:17:59 +02: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-06-12 08:17:59 +02: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) {
|
2021-01-05 18:43:13 +01:00
|
|
|
let rollData = this.rollData;
|
2021-03-16 21:49:21 +01:00
|
|
|
|
2022-06-12 08:17:59 +02:00
|
|
|
rollData.dmg = rollData.attackerRoll?.dmg ?? RdDBonus.dmg(rollData, this.actor.getBonusDegat())
|
|
|
|
rollData.caracValue = parseInt(rollData.selectedCarac.value)
|
2021-06-28 16:08:45 +02:00
|
|
|
rollData.mortalite = rollData.attackerRoll?.dmg.mortalite ?? rollData.dmg.mortalite ?? 'mortel';
|
2021-01-05 18:43:13 +01:00
|
|
|
rollData.coupsNonMortels = (rollData.attackerRoll?.dmg.mortalite ?? rollData.dmg.mortalite) == 'non-mortel';
|
2021-03-16 21:49:21 +01:00
|
|
|
rollData.use.appelAuMoral = this.actor.isPersonnage() && RdDCarac.isActionPhysique(rollData.selectedCarac);
|
2021-01-05 18:43:13 +01:00
|
|
|
let dmgText = Misc.toSignedString(rollData.dmg.total);
|
|
|
|
|
2022-06-12 08:17:59 +02:00
|
|
|
switch (rollData.mortalite){
|
|
|
|
case 'non-mortel': dmgText = `(${dmgText}) non-mortel`; break;
|
|
|
|
case 'empoignade': dmgText = `empoignade`; break;
|
2021-01-04 22:03:00 +01:00
|
|
|
}
|
2021-02-09 23:23:40 +01:00
|
|
|
|
2021-01-05 18:43:13 +01:00
|
|
|
RollDataAjustements.calcul(rollData, this.actor);
|
|
|
|
rollData.finalLevel = this._computeFinalLevel(rollData);
|
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);
|
|
|
|
|
2022-11-23 22:34:39 +01:00
|
|
|
HtmlUtility._showControlWhen($(".use-encTotal"), rollData.ajustements.encTotal.visible && RdDCarac.isAgiliteOuDerivee(rollData.selectedCarac));
|
|
|
|
HtmlUtility._showControlWhen($(".use-surenc"), rollData.ajustements.surenc.visible && RdDCarac.isActionPhysique(rollData.selectedCarac));
|
|
|
|
HtmlUtility._showControlWhen($(".utilisation-moral"), rollData.use.appelAuMoral);
|
2021-01-05 18:43:13 +01:00
|
|
|
HtmlUtility._showControlWhen($(".diffMoral"), rollData.ajustements.moralTotal.used);
|
2021-03-16 21:49:21 +01:00
|
|
|
HtmlUtility._showControlWhen($(".divAppelAuMoral"), rollData.use.appelAuMoral);
|
2021-01-05 18:43:13 +01:00
|
|
|
|
|
|
|
// Mise à jour valeurs
|
2022-12-06 01:30:12 +01:00
|
|
|
html.find(".dialog-roll-title").text(this._getTitle(rollData));
|
|
|
|
html.find("[name='coupsNonMortels']").prop('checked', rollData.mortalite == 'non-mortel');
|
|
|
|
html.find(".dmg-arme-actor").text(dmgText);
|
|
|
|
html.find("div.placeholder-ajustements").empty().append(adjustements);
|
|
|
|
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
|
|
|
_computeFinalLevel(rollData) {
|
2022-06-12 08:17:59 +02:00
|
|
|
return RollDataAjustements.sum(rollData.ajustements);
|
2020-12-16 23:02:15 +01:00
|
|
|
}
|
2021-01-04 22:03:00 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-18 23:57:28 +01:00
|
|
|
_computeDiffCompetence(rollData) {
|
2020-12-16 23:02:15 +01:00
|
|
|
if (rollData.competence) {
|
2022-09-07 09:01:23 +02:00
|
|
|
return Misc.toInt(rollData.competence.system.niveau);
|
2020-12-16 23:02:15 +01:00
|
|
|
}
|
|
|
|
if (rollData.draconicList) {
|
2022-09-07 09:01:23 +02:00
|
|
|
return Misc.toInt(rollData.competence.system.niveau);
|
2020-12-16 23:02:15 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2021-01-29 20:10:43 +01:00
|
|
|
/* -------------------------------------------- */
|
2020-12-18 23:57:28 +01:00
|
|
|
_computeMalusArmure(rollData) {
|
2020-12-06 19:29:10 +01:00
|
|
|
let malusArmureValue = 0;
|
2021-01-05 18:43:13 +01:00
|
|
|
if (rollData.malusArmureValue && (rollData.selectedCarac.label == "Agilité" || rollData.selectedCarac.label == "Dérobée")) {
|
2020-12-06 19:29:10 +01:00
|
|
|
malusArmureValue = rollData.malusArmureValue;
|
|
|
|
}
|
2020-12-16 23:02:15 +01:00
|
|
|
return malusArmureValue;
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
2020-12-18 23:57:28 +01:00
|
|
|
_getTitle(rollData) {
|
2022-06-12 08:17:59 +02:00
|
|
|
const carac = rollData.selectedCarac.label;
|
2021-01-14 00:50:12 +01:00
|
|
|
if (!rollData.competence) {
|
2022-06-12 08:17:59 +02:00
|
|
|
return carac;
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
2022-06-12 08:17:59 +02:00
|
|
|
const compName = rollData.competence.name;
|
2021-01-14 00:50:12 +01:00
|
|
|
if (rollData.draconicList && rollData.selectedSort) {
|
2022-06-12 08:17:59 +02:00
|
|
|
return compName + " - " + rollData.selectedSort.name;
|
2021-01-14 00:50:12 +01:00
|
|
|
}
|
|
|
|
// If a weapon is there, add it in the title
|
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
|
2021-04-20 00:52:51 +02:00
|
|
|
return carac + " Niveau " + niveau
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
2021-01-14 00:50:12 +01:00
|
|
|
const armeTitle = (rollData.arme) ? " (" + rollData.arme.name + ") " : "";
|
2021-04-20 00:52:51 +02:00
|
|
|
return carac + "/" + compName + armeTitle + " Niveau " + niveau
|
2020-12-06 19:29:10 +01:00
|
|
|
}
|
|
|
|
}
|