import { SHOW_DICE } from "./constants.js"; import { RollDataAjustements } from "./rolldata-ajustements.js"; import { RdDUtility } from "./rdd-utility.js"; import { TMRUtility } from "./tmr-utility.js"; import { tmrConstants } from "./tmr-constants.js"; import { RdDResolutionTable } from "./rdd-resolution-table.js"; import { RdDTMRRencontreDialog } from "./rdd-tmr-rencontre-dialog.js"; import { ChatUtility } from "./chat-utility.js"; import { RdDRoll } from "./rdd-roll.js"; import { Poetique } from "./poetique.js"; import { EffetsDraconiques } from "./tmr/effets-draconiques.js"; import { PixiTMR } from "./tmr/pixi-tmr.js"; import { Draconique } from "./tmr/draconique.js"; import { HtmlUtility } from "./html-utility.js"; import { ReglesOptionelles } from "./settings/regles-optionelles.js"; import { RdDDice } from "./rdd-dice.js"; import { STATUSES } from "./settings/status-effects.js"; import { RdDRencontre } from "./item/rencontre.js"; import { RdDCalendrier } from "./rdd-calendrier.js"; import { RdDTimestamp } from "./rdd-timestamp.js"; /* -------------------------------------------- */ export class RdDTMRDialog extends Dialog { static async create(actor, tmrData) { let html = await renderTemplate('systems/foundryvtt-reve-de-dragon/templates/dialog-tmr.html', tmrData); if (tmrData.mode != 'visu') { // Notification au MJ ChatMessage.create({ content: actor.name + " est monté dans les TMR en mode : " + tmrData.mode, whisper: ChatMessage.getWhisperRecipients("GM") }); } return new RdDTMRDialog(html, actor, tmrData); } /* -------------------------------------------- */ constructor(html, actor, tmrData) { const dialogConf = { title: "Terres Médianes de Rêve", content: html, buttons: { closeButton: { label: "Fermer", callback: html => this.close(html) } }, default: "closeButton" } const dialogOptions = { classes: ["tmrdialog"], width: 920, height: 980, 'z-index': 40 } super(dialogConf, dialogOptions); this.tmrdata = duplicate(tmrData); this.actor = actor; this.actor.tmrApp = this; // reference this app in the actor structure this.viewOnly = tmrData.mode == "visu" this.fatigueParCase = this.viewOnly || !ReglesOptionelles.isUsing("appliquer-fatigue") ? 0 : this.actor.getTMRFatigue(); this.cumulFatigue = 0; this.loadRencontres(); this.loadCasesSpeciales(); this.allTokens = []; this.rencontreState = 'aucune'; this.pixiApp = new PIXI.Application({ width: 720, height: 860 }); this.pixiTMR = new PixiTMR(this, this.pixiApp); this.callbacksOnAnimate = []; if (!this.viewOnly) { this._tellToGM(this.actor.name + " monte dans les terres médianes (" + tmrData.mode + ")"); } // load the texture we need this.pixiTMR.load((loader, resources) => this.createPixiSprites()); } isDemiReveCache() { return !game.user.isGM && this.actor.isTMRCache(); } /* -------------------------------------------- */ loadCasesSpeciales() { this.casesSpeciales = this.actor.items.filter(item => Draconique.isCaseTMR(item)); } get sortsReserve() { return this.actor.itemTypes['sortreserve']; } getSortsReserve(coord) { return this.actor.itemTypes['sortreserve'].filter(// Reserve sur une case fleuve ou normale TMRUtility.getTMR(coord).type == 'fleuve' ? it => TMRUtility.getTMR(it.system.coord).type == 'fleuve' : it => it.system.coord == coord ); } /* -------------------------------------------- */ loadRencontres() { this.rencontresExistantes = this.actor.getTMRRencontres(); } /* -------------------------------------------- */ createPixiSprites() { EffetsDraconiques.carteTmr.createSprite(this.pixiTMR); this.updateTokens(); this.forceDemiRevePositionView(); } /* -------------------------------------------- */ _createTokens() { if (!this.isDemiReveCache()) { this.demiReve = this._tokenDemiReve(); this._trackToken(this.demiReve); } let tokens = this._getTokensCasesTmr() .concat(this._getTokensRencontres()) .concat(this._getTokensSortsReserve()); for (let t of tokens) { this._trackToken(t); } } /* -------------------------------------------- */ updateTokens() { this._removeTokens(t => true); this.loadRencontres(); this.loadCasesSpeciales(); this._createTokens(); } /* -------------------------------------------- */ removeToken(tmr, casetmr) { this._removeTokens(t => t.coordTMR() == tmr.coord && t.caseSpeciale?._id == casetmr._id); this.updateTokens() } /* -------------------------------------------- */ _getTokensCasesTmr() { return this.casesSpeciales.map(c => this._tokenCaseSpeciale(c)).filter(token => token); } _getTokensRencontres() { return this.rencontresExistantes.map(it => this._tokenRencontre(it)); } _getTokensSortsReserve() { return this.actor.itemTypes['sortreserve'].map(it => this._tokenSortEnReserve(it)); } /* -------------------------------------------- */ _tokenRencontre(rencontre) { return EffetsDraconiques.rencontre.token(this.pixiTMR, rencontre, () => rencontre.system.coord); } _tokenCaseSpeciale(casetmr) { const caseData = casetmr; const draconique = Draconique.get(caseData.system.specific); return draconique?.token(this.pixiTMR, caseData, () => caseData.system.coord); } _tokenSortEnReserve(sortReserve) { return EffetsDraconiques.sortReserve.token(this.pixiTMR, sortReserve, () => sortReserve.system.coord); } _tokenDemiReve() { return EffetsDraconiques.demiReve.token(this.pixiTMR, this.actor, () => this.actor.system.reve.tmrpos.coord); } forceDemiRevePositionView() { this.notifierResonanceSigneDraconique(this._getActorCoord()); this._trackToken(this.demiReve); } _getActorCoord() { return this.actor.system.reve.tmrpos.coord; } /* -------------------------------------------- */ async moveFromKey(move) { let oddq = TMRUtility.coordTMRToOddq(this._getActorCoord()); if (move == 'top') oddq.row -= 1; if (move == 'bottom') oddq.row += 1; if (move.includes('left')) oddq.col -= 1; if (move.includes('right')) oddq.col += 1; if (oddq.col % 2 == 1) { if (move == 'top-left') oddq.row -= 1; if (move == 'top-right') oddq.row -= 1; } else { if (move == 'bottom-left') oddq.row += 1; if (move == 'bottom-right') oddq.row += 1; } let targetCoord = TMRUtility.oddqToCoordTMR(oddq); await this._deplacerDemiReve(targetCoord, 'normal'); this.checkQuitterTMR(); } /* -------------------------------------------- */ async activateListeners(html) { super.activateListeners(html); this.html = html; document.getElementById("tmrrow1").insertCell(0).append(this.pixiApp.view); if (this.viewOnly) { this.html.find('.lancer-sort').remove(); this.html.find('.lire-signe-draconique').remove(); return; } HtmlUtility.showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionelles.isUsing("appliquer-fatigue")); HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getActorCoord())); // Roll Sort this.html.find('.lancer-sort').click((event) => { this.actor.rollUnSort(this._getActorCoord()); }); this.html.find('.lire-signe-draconique').click((event) => { this.actor.rollLireSigneDraconique(this._getActorCoord()); }); this.html.find('#dir-top').click((event) => this.moveFromKey("top")); this.html.find('#dir-top-left').click((event) => this.moveFromKey("top-left")); this.html.find('#dir-top-right').click((event) => this.moveFromKey("top-right")); this.html.find('#dir-bottom-left').click((event) => this.moveFromKey("bottom-left")); this.html.find('#dir-bottom-right').click((event) => this.moveFromKey("bottom-right")); this.html.find('#dir-bottom').click((event) => this.moveFromKey("bottom")); // Gestion du cout de montée en points de rêve let reveCout = ((this.tmrdata.isRapide && !EffetsDraconiques.isDeplacementAccelere(this.actor)) ? -2 : -1) - this.actor.countMonteeLaborieuse(); if (ReglesOptionelles.isUsing("appliquer-fatigue")) { this.cumulFatigue += this.fatigueParCase; } await this.actor.reveActuelIncDec(reveCout); // Le reste... this.updateValuesDisplay(); let tmr = TMRUtility.getTMR(this._getActorCoord()); await this.manageRencontre(tmr); } /* -------------------------------------------- */ async updateValuesDisplay() { if (!this.rendered) { return; } const coord = this._getActorCoord(); HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(coord)); let ptsreve = document.getElementById("tmr-pointsreve-value"); ptsreve.innerHTML = this.actor.system.reve.reve.value; let tmrpos = document.getElementById("tmr-pos"); if (this.isDemiReveCache()) { tmrpos.innerHTML = `?? ( ${TMRUtility.getTMRType(coord)})`; } else { tmrpos.innerHTML = `${coord} ( ${TMRUtility.getTMRLabel(coord)})`; } let etat = document.getElementById("tmr-etatgeneral-value"); etat.innerHTML = this.actor.getEtatGeneral(); let refoulement = document.getElementById("tmr-refoulement-value"); refoulement.innerHTML = this.actor.system.reve.refoulement.value; if (ReglesOptionelles.isUsing("appliquer-fatigue")) { let fatigueItem = document.getElementById("tmr-fatigue-table"); fatigueItem.innerHTML = "