/**
* 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";
import { RdDRollTables } from "./rdd-rolltables.js";
import { RdDResolutionTable } from "./rdd-resolution-table.js";
/** Helper functions */
export class RdDTMRDialog extends Dialog {
/* -------------------------------------------- */
constructor( html, actor, tmrData) {
// Common conf
let dialogConf = {
content: html,
buttons:
{
closeButton:
{
label: "Fermer",
callback: html => this.close(html)
}
},
default: "closeButton"
}
let dialogOptions = { classes: [ "tmrdialog"] }
dialogConf.title = "Terres Médianes de Rêve",
dialogOptions.width = 920;
dialogOptions.height = 960;
dialogOptions['z-index'] = 20;
super(dialogConf, dialogOptions);
this.tmrdata = duplicate(tmrData);
this.col1_y = 30;
this.col2_y = 55;
this.cellh = 55;
this.cellw = 55;
this.actor = actor;
this.nbFatigue = 1; // 1 premier point de fatigue du à la montée
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list);
//console.log(this.rencontresExistantes);
this.pixiApp = new PIXI.Application( {width: 720, height: 860 } );
}
/* -------------------------------------------- */
close() {
this.actor.santeIncDec("fatigue", this.nbFatigue).then( super.close() ); // moving 1 cell costs 1 fatigue
}
/* -------------------------------------------- */
displaySortReserve() {
console.log(this.sortReserves);
for (let sortReserve of this.sortReserves) {
sortReserve.circle = new PIXI.Graphics();
sortReserve.circle.beginFill(0x767610, 0.6);
sortReserve.circle.drawCircle(0, 0, 6);
sortReserve.circle.endFill();
let coordXY = TMRUtility.convertToCellCoord( sortReserve.coord );
let basey = (coordXY.x % 2 == 0) ? this.col1_y : this.col2_y;
let myx = 28+(coordXY.x * this.cellw);
let myy = basey+28+(coordXY.y * this.cellh);
sortReserve.circle.x = myx - (this.cellw/2)+16;
sortReserve.circle.y = myy - (this.cellh/2)+16;
this.pixiApp.stage.addChild(sortReserve.circle);
}
}
/* -------------------------------------------- */
displayPreviousRencontres() {
for (let rencontre of this.rencontresExistantes) {
rencontre.circle = new PIXI.Graphics();
rencontre.circle.beginFill(0x101010, 0.8);
rencontre.circle.drawCircle(0, 0, 6);
rencontre.circle.endFill();
let coordXY = TMRUtility.convertToCellCoord( rencontre.coord );
let basey = (coordXY.x % 2 == 0) ? this.col1_y : this.col2_y;
let myx = 28+(coordXY.x * this.cellw);
let myy = basey+28+(coordXY.y * this.cellh);
rencontre.circle.x = myx - (this.cellw/2)+16;
rencontre.circle.y = myy - (this.cellh/2)+16;
this.pixiApp.stage.addChild(rencontre.circle);
}
}
/* -------------------------------------------- */
updatePreviousRencontres() {
for (let rencontre of this.rencontresExistantes) {
this.pixiApp.stage.removeChild( rencontre.circle );
}
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
this.displayPreviousRencontres();
}
/* -------------------------------------------- */
updateSortReserve() {
for (let sortReserve of this.sortReserves) { //cleanup pixi icons
this.pixiApp.stage.removeChild( sortReserve.circle );
}
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list); // Then do it again!
this.displaySortReserve();
}
/* -------------------------------------------- */
async derober() {
await this.actor.addTMRRencontre( this.currentRencontre );
console.log("-> derober", this.currentRencontre);
ChatMessage.create( { title: "TMR", content: game.user.name + " s'est dérobé et quitte les TMR.", user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
this.close();
}
/* -------------------------------------------- */
async refouler(data) {
ChatMessage.create( { title: "TMR", content: game.user.name + " a refoulé une rencontre.", user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
await this.actor.deleteTMRRencontreAtPosition( ); // Remove the stored rencontre if necessary
let result = await this.actor.ajouterRefoulement(1);
this.updatePreviousRencontres();
if (result == "souffle") {
let souffle = RdDRollTables.getSouffle();
}
console.log("-> refouler", this.currentRencontre)
this.updateValuesDisplay();
}
/* -------------------------------------------- */
async matriser(data) {
this.actor.deleteTMRRencontreAtPosition( ); // Remove the stored rencontre if necessary
this.updatePreviousRencontres();
const draconic = this.actor.getBestDraconic();
const carac = this.actor.getCurrentReve();
const difficulte = draconic.data.niveau - this.currentRencontre.force;
console.log("Maitriser", carac, draconic.data.niveau, this.currentRencontre.force);
const roll = RdDResolutionTable.roll(carac, difficulte);
if (roll.isEchec) {
TMRUtility.processRencontreEchec( this.actor, this.currentRencontre);
ChatMessage.create( { title: "TMR", content: "Vous avez échoué à votre maîtrise d'un " . this.currentRencontre.name + " de force " +
this.currentRencontre.force +
"
Vous quittez brutalement les Terres Médianes !",
user: game.user._id, whisper: [ game.user ] } );
ChatMessage.create( { title: "TMR", content: game.user.name + " a perdu sa rencontre contre : " + this.currentRencontre.name + " de force " + this.currentRencontre.force, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
this.close();
} else {
TMRUtility.processRencontreReussite( this.actor, this.rencontre);
ChatMessage.create( { title: "TMR", content: "Vous avez réussi votre maîtrise d'un " + this.currentRencontre.name + " de force " + this.currentRencontre.force, user: game.user._id, whisper: [ game.user ] } );
ChatMessage.create( { title: "TMR", content: game.user.name + " a gagné sa rencontre contre : " + this.currentRencontre.name + " de force " + this.currentRencontre.force, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") } );
}
console.log("-> matriser", this.currentRencontre);
this.updateValuesDisplay();
}
/* -------------------------------------------- */
async manageRencontre(coordTMR, cellDescr)
{
// Roll until diffent than '8'
this.currentRencontre = undefined;
let rencontre = this.rencontresExistantes.find(prev => prev.coord == coordTMR);
if (rencontre == undefined && new Roll("d7").roll().total == 7) {
rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
}
if (rencontre) { // Manages it
this.currentRencontre = duplicate(rencontre);
let dialog = new Dialog( { title: "Rencontre en TMR!",
content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "
",
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()
}
}
} );
dialog.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 = "