/**
* Extend the base Dialog entity by defining a custom window to perform spell.
* @extends {Dialog}
*/
import { RdDUtility } from "./rdd-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(data) {
await this.maximize();
console.log("-> derober", this.currentRencontre)
}
/* -------------------------------------------- */
async refouler(data) {
await this.maximize();
console.log("-> refouler", this.currentRencontre)
}
/* -------------------------------------------- */
async matriser(data) {
await this.maximize();
console.log("-> matriser", this.currentRencontre)
}
/* -------------------------------------------- */
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 = RdDUtility.rencontreTMRRoll(coordTMR, cellDescr);
}
}
if (rencontre) { // Manages it
this.currentRencontre = rencontre;
let myroll = new Roll(rencontre.data.force);
myroll.roll();
await this.minimize();
console.log("Dialog !!!!");
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 );
}
/* -------------------------------------------- */
updateSprites( myself )
{
let coordTMR = myself.actor.data.data.reve.tmrpos.coord;
let coordXY = RdDUtility.convertToCellCoord( coordTMR );
let basey = (coordXY.x % 2 == 0) ? myself.col1_y : myself.col2_y;
let myx = 28+(coordXY.x * myself.cellw);
let myy = basey+28+(coordXY.y * myself.cellh);
myself.circle.x = myx;
myself.circle.y = myy;
}
/* -------------------------------------------- */
async getCursorPosition(event) {
let origEvent = event.data.originalEvent;
let myself = event.target.tmrObject;
//console.log("EVENT:", event);
let canvasRect = origEvent.target.getBoundingClientRect();
let x = origEvent.clientX - canvasRect.left;
let y = origEvent.clientY - canvasRect.top;
//console.log(">>>>", x, y );
let cellx = Math.floor( x / myself.cellw);// [From 0 -> 12]
if (cellx % 2 == 0)
y -= myself.col1_y;
else
y -= myself.col2_y;
let celly = Math.floor( y / myself.cellh);// [From 0 -> 14]
let currentPos = RdDUtility.convertToCellCoord(myself.actor.data.data.reve.tmrpos.coord);
if ( Math.abs(cellx - currentPos.x) > 1 || Math.abs(celly - currentPos.y) > 1 ) { // Check if the coord is reachable !
ui.notifications.error( "Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position" );
} else {
let coordTMR = RdDUtility.convertToTMRCoord(cellx, celly);
let cellDescr = RdDUtility.getTMRDescription( coordTMR );
console.log("TMR column is", coordTMR, cellx, celly, cellDescr, this);
let tmrPos = duplicate(myself.actor.data.data.reve.tmrpos);
tmrPos.coord = coordTMR;
await myself.actor.update( { "data.reve.tmrpos": tmrPos } );
myself.updateSprites(myself);
myself.actor.santeIncDec("fatigue", 1); // moving 1 cell costs 1 fatigue
let fatigueItem = document.getElementById("fatigue-table");
fatigueItem.innerHTML = "