2020-07-05 21:45:25 +02:00
|
|
|
/**
|
|
|
|
* Extend the base Dialog entity by defining a custom window to perform spell.
|
|
|
|
* @extends {Dialog}
|
|
|
|
*/
|
2020-07-06 09:03:21 +02:00
|
|
|
import { RdDUtility } from "./rdd-utility.js";
|
2020-07-05 21:45:25 +02:00
|
|
|
|
|
|
|
export class RdDTMRDialog extends Dialog {
|
|
|
|
|
|
|
|
/* -------------------------------------------- */
|
|
|
|
constructor(sort, html, actor) {
|
|
|
|
|
|
|
|
// Common conf
|
|
|
|
let dialogConf = {
|
|
|
|
content: html,
|
|
|
|
buttons:
|
|
|
|
{
|
|
|
|
rollButton:
|
|
|
|
{
|
2020-07-14 22:19:29 +02:00
|
|
|
label: "Fermer",
|
2020-07-05 21:45:25 +02:00
|
|
|
callback: html => this.performRoll(html)
|
|
|
|
}
|
|
|
|
},
|
|
|
|
default: "rollButton"
|
|
|
|
}
|
|
|
|
let dialogOptions = { classes: [ "tmrdialog"] }
|
|
|
|
|
|
|
|
dialogConf.title = "Terres Médianes de Rêve",
|
2020-07-14 22:19:29 +02:00
|
|
|
dialogOptions.width = 920;
|
2020-07-05 22:35:18 +02:00
|
|
|
dialogOptions.height = 960;
|
2020-07-14 22:19:29 +02:00
|
|
|
|
2020-07-05 21:45:25 +02:00
|
|
|
super(dialogConf, dialogOptions);
|
2020-07-05 22:35:18 +02:00
|
|
|
|
2020-07-06 09:03:21 +02:00
|
|
|
this.col1_y = 30;
|
|
|
|
this.col2_y = 55;
|
|
|
|
this.cellh = 55;
|
|
|
|
this.cellw = 55;
|
2020-07-14 22:19:29 +02:00
|
|
|
this.actor = actor;
|
|
|
|
this.sort = sort;
|
|
|
|
this.pixiApp = new PIXI.Application( {width: 720, height: 860 } );
|
|
|
|
}
|
2020-07-05 21:45:25 +02:00
|
|
|
|
2020-07-14 22:19:29 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
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 + "<br>",
|
|
|
|
buttons: {
|
|
|
|
derober: {
|
|
|
|
icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Se dérober",
|
|
|
|
callback: () => this.derober()
|
|
|
|
},
|
|
|
|
refouler: {
|
|
|
|
icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Refouler",
|
|
|
|
callback: () => this.refouler()
|
|
|
|
},
|
|
|
|
maitiser: {
|
|
|
|
icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Maîtriser",
|
|
|
|
callback: () => this.matriser()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} );
|
|
|
|
diag.render(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-05 21:45:25 +02:00
|
|
|
/* -------------------------------------------- */
|
|
|
|
performRoll (html) {
|
|
|
|
this.actor.performRoll( this.rollData );
|
|
|
|
}
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-05 21:45:25 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-07-14 22:19:29 +02:00
|
|
|
updateSprites( myself )
|
|
|
|
{
|
2020-07-06 09:03:21 +02:00
|
|
|
let coordTMR = myself.actor.data.data.reve.tmrpos.coord;
|
|
|
|
let coordXY = RdDUtility.convertToCellCoord( coordTMR );
|
2020-07-14 22:19:29 +02:00
|
|
|
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);
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-14 22:19:29 +02:00
|
|
|
myself.circle.x = myx;
|
|
|
|
myself.circle.y = myy;
|
|
|
|
|
2020-07-05 22:35:18 +02:00
|
|
|
}
|
2020-07-14 22:19:29 +02:00
|
|
|
|
2020-07-05 22:35:18 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-07-14 22:19:29 +02:00
|
|
|
async getCursorPosition(event) {
|
|
|
|
let origEvent = event.data.originalEvent;
|
|
|
|
let myself = event.target.tmrObject;
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-14 22:19:29 +02:00
|
|
|
//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]
|
2020-07-06 09:03:21 +02:00
|
|
|
if (cellx % 2 == 0)
|
2020-07-14 22:19:29 +02:00
|
|
|
y -= myself.col1_y;
|
2020-07-06 09:03:21 +02:00
|
|
|
else
|
2020-07-14 22:19:29 +02:00
|
|
|
y -= myself.col2_y;
|
|
|
|
let celly = Math.floor( y / myself.cellh);// [From 0 -> 14]
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-14 22:19:29 +02:00
|
|
|
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 = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( myself.actor.data.data.sante.fatigue.value, myself.actor.data.data.sante.endurance.max ).html() + "</table>";
|
|
|
|
myself.manageRencontre(coordTMR, cellDescr);
|
|
|
|
|
|
|
|
if ( cellDescr.type == "lac" || cellDescr.type == "fleuve" || cellDescr.type == "marais" ) {
|
|
|
|
let draconic = myself.actor.getBestDraconic();
|
|
|
|
let carac = myself.actor.getCurrentReve();
|
|
|
|
let level = draconic.data.niveau - 7;
|
|
|
|
let scoreDef = CONFIG.RDD.resolutionTable[carac][draconic.niveau+10];
|
|
|
|
let myroll = new Roll("d100");
|
|
|
|
myroll.roll();
|
|
|
|
let humideDiag = new Dialog( {title: "Case humide",
|
|
|
|
content: "Vous êtes entré sur une case humide, et vous avez tenté une matrise ("+ draconic.name +") :" + carac + " / " + level + " -> " + myroll.total,
|
|
|
|
buttons: {
|
|
|
|
choice: { icon: '<i class="fas fa-check"></i>',
|
|
|
|
label: "Fermer",
|
|
|
|
callback: () => myself.maximize()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
|
|
|
await myself.minimize();
|
|
|
|
humideDiag.render(true);
|
|
|
|
}
|
|
|
|
}
|
2020-07-05 22:35:18 +02:00
|
|
|
}
|
2020-07-06 09:03:21 +02:00
|
|
|
|
2020-07-05 22:35:18 +02:00
|
|
|
/* -------------------------------------------- */
|
2020-07-06 09:03:21 +02:00
|
|
|
async activateListeners(html) {
|
2020-07-05 21:45:25 +02:00
|
|
|
super.activateListeners(html);
|
2020-07-14 22:19:29 +02:00
|
|
|
|
|
|
|
var row = document.getElementById("tmrrow1");
|
|
|
|
var cell1 = row.insertCell(1);
|
|
|
|
cell1.append( this.pixiApp.view );
|
2020-07-05 22:35:18 +02:00
|
|
|
|
2020-07-14 22:19:29 +02:00
|
|
|
// load the texture we need
|
|
|
|
this.pixiApp.loader.add('tmr', 'systems/foundryvtt-reve-de-dragon/styles/ui/tmp_main_r1.webp').load((loader, resources) => {
|
|
|
|
// This creates a texture from a 'bunny.png' image
|
|
|
|
const mytmr = new PIXI.Sprite(resources.tmr.texture);
|
|
|
|
// Setup the position of the bunny
|
|
|
|
mytmr.x = 0;
|
|
|
|
mytmr.y = 0;
|
|
|
|
mytmr.width = 720;
|
|
|
|
mytmr.height = 860;
|
|
|
|
// Rotate around the center
|
|
|
|
mytmr.anchor.x = 0;
|
|
|
|
mytmr.anchor.y = 0;
|
|
|
|
mytmr.interactive = true;
|
|
|
|
mytmr.buttonMode = true;
|
|
|
|
mytmr.tmrObject = this;
|
|
|
|
mytmr.on('pointerdown', this.getCursorPosition);
|
|
|
|
|
|
|
|
this.circle = new PIXI.Graphics();
|
|
|
|
this.circle.beginFill(0x9966FF, 0.6);
|
|
|
|
this.circle.drawCircle(0, 0, 15);
|
|
|
|
this.circle.endFill();
|
|
|
|
this.updateSprites( this );
|
|
|
|
|
|
|
|
// Add the bunny to the scene we are building
|
|
|
|
this.pixiApp.stage.addChild(mytmr);
|
|
|
|
this.pixiApp.stage.addChild(this.circle);
|
|
|
|
//this.updateSprites();
|
2020-07-06 09:03:21 +02:00
|
|
|
} );
|
2020-07-14 22:19:29 +02:00
|
|
|
|
2020-07-05 21:45:25 +02:00
|
|
|
}
|
|
|
|
}
|