/**
* Extend the base Dialog entity by defining a custom window to perform spell.
* @extends {Dialog}
*/
import { RdDUtility } from "./rdd-utility.js";
import { TMRUtility } from "./tmr-utility.js";
export class RdDTMRDialog extends Dialog {
/* -------------------------------------------- */
constructor(sort, html, actor) {
// Common conf
let dialogConf = {
content: html,
buttons:
{
rollButton:
{
label: "Fermer",
callback: html => this.performRoll(html)
}
},
default: "rollButton"
}
let dialogOptions = { classes: [ "tmrdialog"] }
dialogConf.title = "Terres Médianes de Rêve",
dialogOptions.width = 920;
dialogOptions.height = 960;
super(dialogConf, dialogOptions);
this.col1_y = 30;
this.col2_y = 55;
this.cellh = 55;
this.cellw = 55;
this.actor = actor;
this.sort = sort;
this.pixiApp = new PIXI.Application( {width: 720, height: 860 } );
}
/* -------------------------------------------- */
async derober() {
await this.maximize();
let rencontre = duplicate(this.actor.data.data.reve.rencontre);
rencontre.list.push( {coord: this.actor.data.data.reve.tmrpos.coord, rencontre: this.currentRencontre} );
console.log("-> derober", this.currentRencontre);
}
/* -------------------------------------------- */
async refouler(data) {
let result = await this.actor.ajouterRefoulement(1);
if (result == "souffle") {
let souffle = TMRUtility.getSouffle();
}
await this.maximize();
console.log("-> refouler", this.currentRencontre)
this.updateValuesDisplay();
}
/* -------------------------------------------- */
async matriser(data) {
await this.maximize();
let draconic = this.actor.getBestDraconic();
let carac = this.actor.getCurrentReve();
let level = draconic.data.niveau - this.currentRencontre.force;
let scoreDef = CONFIG.RDD.resolutionTable[carac][level+10];
let myroll = new Roll("d100");
myroll.roll();
if ( myroll.total > scoreDef.score ) {
TMRUtility.processRencontreEchec( this.actor, this.rencontre);
this.close();
} else {
TMRUtility.processRencontreReussite( this.actor, this.rencontre);
}
console.log("-> matriser", this.currentRencontre);
this.updateValuesDisplay();
}
/* -------------------------------------------- */
async manageRencontre(coordTMR, cellDescr)
{
// Roll until diffent than '8'
this.currentRencontre = undefined;
let rencontre
let val = 8;
while (val == 8) {
let myroll = new Roll("d7");
myroll.roll();
val = myroll.total;
if ( val == 7 ) {
rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
}
}
if (rencontre) { // Manages it
let myroll = new Roll(rencontre.data.force);
myroll.roll();
rencontre.force = myroll.total;
this.currentRencontre = rencontre;
await this.minimize();
let diag = new Dialog( { title: "Rencontre en TMR!",
content: "Vous recontrez un " + rencontre.name + " de force " + myroll.total + "
",
buttons: {
derober: {
icon: '',
label: "Se dérober",
callback: () => this.derober()
},
refouler: {
icon: '',
label: "Refouler",
callback: () => this.refouler()
},
maitiser: {
icon: '',
label: "Maîtriser",
callback: () => this.matriser()
}
}
} );
diag.render(true);
}
}
/* -------------------------------------------- */
performRoll (html) {
this.actor.performRoll( this.rollData );
}
/* -------------------------------------------- */
updateValuesDisplay() {
let ptsreve = document.getElementById("pointsreve-value");
ptsreve.innerHTML = this.actor.data.data.reve.reve.value;
let tmrpos = document.getElementById("tmr-pos");
let tmr = TMRUtility.getTMRDescription( this.actor.data.data.reve.tmrpos.coord );
tmrpos.innerHTML = this.actor.data.data.reve.tmrpos.coord + " (" + tmr.label + ")";
let etat = document.getElementById("etatgeneral-value");
etat.innerHTML = this.actor.data.data.compteurs.etat.value;
let refoulement = document.getElementById("refoulement-value");
refoulement.innerHTML = this.actor.data.data.reve.refoulement.value;
let fatigueItem = document.getElementById("fatigue-table");
fatigueItem.innerHTML = "