forked from public/foundryvtt-reve-de-dragon
Petites améliorations TMR
* afficher les points de rêve des sorts en réserve * davantage d'informations pour les jets de rencontres/cases humides * souffle ajouté dans le cas du refoulement * utilisation d'une image pour le demi-rêve * refacto TMR pour préparer à afficher un tooltip sur les sorts en réserve * extraction de méthodes pour séparer le lancement de sorts des autres actions
This commit is contained in:
@ -7,218 +7,187 @@ import { TMRUtility } from "./tmr-utility.js";
|
||||
import { RdDRollTables } from "./rdd-rolltables.js";
|
||||
import { RdDResolutionTable } from "./rdd-resolution-table.js";
|
||||
|
||||
/** Helper functions */
|
||||
const tmrConstants = {
|
||||
col1_y: 30,
|
||||
col2_y: 55,
|
||||
cellw: 55,
|
||||
cellh: 55,
|
||||
gridx: 28,
|
||||
gridy: 28
|
||||
}
|
||||
|
||||
export class RdDTMRDialog extends Dialog {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
constructor( html, actor, tmrData) {
|
||||
|
||||
// Common conf
|
||||
let dialogConf = {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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"
|
||||
}
|
||||
let dialogOptions = { classes: [ "tmrdialog"] }
|
||||
|
||||
dialogConf.title = "Terres Médianes de Rêve",
|
||||
dialogOptions.width = 920;
|
||||
dialogOptions.height = 960;
|
||||
dialogOptions['z-index'] = 20;
|
||||
|
||||
buttons: {
|
||||
closeButton: { label: "Fermer", callback: html => this.close(html) }
|
||||
},
|
||||
default: "closeButton"
|
||||
}
|
||||
|
||||
const dialogOptions = {
|
||||
classes: ["tmrdialog"],
|
||||
width: 920, height: 980,
|
||||
'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.tmrdata = duplicate(tmrData);
|
||||
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 } );
|
||||
this.allTokens = []
|
||||
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();
|
||||
this.actor.santeIncDec("fatigue", this.nbFatigue).then(super.close()); // moving 1 cell costs 1 fatigue
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateSortReserve() {
|
||||
for (let sortReserve of this.sortReserves) { //cleanup pixi icons
|
||||
this.pixiApp.stage.removeChild( sortReserve.circle );
|
||||
/* -------------------------------------------- */
|
||||
displaySortReserve() {
|
||||
console.debug("displaySortReserve", this.sortReserves);
|
||||
for (let sort of this.sortReserves) {
|
||||
this._trackToken(this._tokenSortEnReserve(sort));
|
||||
}
|
||||
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list); // Then do it again!
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
displayPreviousRencontres() {
|
||||
console.debug("displayPreviousRencontres", this.rencontresExistantes);
|
||||
for (let rencontre of this.rencontresExistantes) {
|
||||
this._trackToken(this._tokenRencontre(rencontre));
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updatePreviousRencontres() {
|
||||
this._removeTokens(t => t.rencontre != undefined);
|
||||
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
|
||||
this.displayPreviousRencontres();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateSortReserve() {
|
||||
this._removeTokens(t => t.sort != undefined);
|
||||
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list);
|
||||
this.displaySortReserve();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async derober() {
|
||||
await this.actor.addTMRRencontre( this.currentRencontre );
|
||||
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._tellToGM(this.actor.name + " s'est dérobé et quitte les TMR.");
|
||||
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
|
||||
this._tellToGM(this.actor.name + " a refoulé une rencontre.");
|
||||
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
|
||||
/* -------------------------------------------- */
|
||||
async maitriser(data) {
|
||||
this.actor.deleteTMRRencontreAtPosition(); // Remove the stored rencontre if necessary
|
||||
this.updatePreviousRencontres();
|
||||
|
||||
|
||||
const draconic = this.actor.getBestDraconic();
|
||||
const carac = this.actor.getCurrentReve();
|
||||
// TODO: ajouter l'état général?
|
||||
const etatGeneral = this.actor.data.data.compteurs.etat.value
|
||||
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 <strong>échoué</strong> à votre maîtrise d'un " . this.currentRencontre.name + " de force " +
|
||||
this.currentRencontre.force +
|
||||
"<br>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();
|
||||
let rolled = RdDResolutionTable.roll(carac, difficulte);
|
||||
let message = "<br><strong>Test : Rêve actuel / " + draconic.name + " / " + this.currentRencontre.name + "</strong>" + "<br>"
|
||||
+ "<br>Jet : " + carac + " / " + difficulte + " -> " + rolled.score + "%<br><strong>Résutat : </strong>" + rolled.roll;
|
||||
|
||||
|
||||
if (rolled.isEchec) {
|
||||
TMRUtility.processRencontreEchec(this.actor, this.currentRencontre);
|
||||
this._tellToUser("Vous avez <strong>échoué</strong> à maîtriser un " + this.currentRencontre.name + " de force " + this.currentRencontre.force
|
||||
+ "<br>Vous quittez brutalement les Terres Médianes !" + message);;
|
||||
this.close();
|
||||
} else {
|
||||
TMRUtility.processRencontreReussite( this.actor, this.rencontre);
|
||||
ChatMessage.create( { title: "TMR", content: "Vous avez <strong>réussi</strong> 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") } );
|
||||
TMRUtility.processRencontreReussite(this.actor, this.currentRencontre);
|
||||
this._tellToUser("Vous avez <strong>réussi</strong> à maîtriser un " + this.currentRencontre.name + " de force " + this.currentRencontre.force + message);
|
||||
}
|
||||
console.log("-> matriser", this.currentRencontre);
|
||||
this.updateValuesDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async manageRencontre(coordTMR, cellDescr)
|
||||
{
|
||||
// Roll until diffent than '8'
|
||||
this.currentRencontre = undefined;
|
||||
|
||||
_tellToUser(message) {
|
||||
ChatMessage.create({ title: "TMR", content: message, user: game.user._id, whisper: ChatMessage.getWhisperRecipients("GM") });
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async manageRencontre(coordTMR, cellDescr) {
|
||||
|
||||
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);
|
||||
let deRencontre = new Roll("d7").roll();
|
||||
console.log("manageRencontre", deRencontre, rencontre);
|
||||
if (rencontre == undefined) {
|
||||
if (deRencontre.total == 7) {
|
||||
rencontre = TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
|
||||
}
|
||||
}
|
||||
|
||||
if (rencontre) { // Manages it
|
||||
console.log("manageRencontre", rencontre)
|
||||
this.currentRencontre = duplicate(rencontre);
|
||||
let dialog = new Dialog( { title: "Rencontre en TMR!",
|
||||
content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "<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()
|
||||
}
|
||||
}
|
||||
} );
|
||||
let dialog = new Dialog({
|
||||
title: "Rencontre en TMR!",
|
||||
content: "Vous recontrez un " + rencontre.name + " de force " + rencontre.force + "<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.maitriser() }
|
||||
},
|
||||
default: "derober"
|
||||
});
|
||||
dialog.render(true);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
performRoll (html) {
|
||||
this.actor.performRoll( this.rollData );
|
||||
|
||||
/* -------------------------------------------- */
|
||||
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 tmr = TMRUtility.getTMRDescription(this.actor.data.data.reve.tmrpos.coord);
|
||||
console.log("updateValuesDisplay", this.actor.data.data.reve.tmrpos, tmr);
|
||||
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 = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix( this.actor.data.data.sante.fatigue.value, this.actor.data.data.sante.endurance.max ).html() + "</table>";
|
||||
fatigueItem.innerHTML = "<table class='table-fatigue'>" + RdDUtility.makeHTMLfatigueMatrix(this.actor.data.data.sante.fatigue.value, this.actor.data.data.sante.endurance.max).html() + "</table>";
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/* -------------------------------------------- */
|
||||
manageCaseHumideResult() {
|
||||
if ( this.toclose )
|
||||
if (this.toclose)
|
||||
this.close();
|
||||
}
|
||||
|
||||
@ -226,162 +195,226 @@ export class RdDTMRDialog extends Dialog {
|
||||
async manageCaseHumide(cellDescr) {
|
||||
if (cellDescr.type == "lac" || cellDescr.type == "fleuve" || cellDescr.type == "marais") {
|
||||
let draconic = this.actor.getBestDraconic();
|
||||
|
||||
let carac = this.actor.getCurrentReve();
|
||||
let level = draconic.data.niveau - 7;
|
||||
let rolled = RdDResolutionTable.roll(carac, level);//RdDResolutionTable.computeChances(carac, level);
|
||||
// TODO: ajouter l'état général?
|
||||
const etatGeneral = this.actor.data.data.compteurs.etat.value
|
||||
let difficulte = draconic.data.niveau - 7;
|
||||
let rolled = RdDResolutionTable.roll(carac, difficulte);
|
||||
|
||||
console.log("manageCaseHumide >>", rolled);
|
||||
|
||||
let content = "";
|
||||
let explication = "";
|
||||
this.toclose = rolled.isEchec;
|
||||
if (rolled.isEchec) {
|
||||
content += "Vous êtes entré sur une case humide, et vous avez <strong>raté</strong> votre maîtrise ! Vous <strong>quittez les Terres Médianes</strong> !"
|
||||
explication += "Vous êtes entré sur une case humide, et vous avez <strong>raté</strong> votre maîtrise ! Vous <strong>quittez les Terres Médianes</strong> !"
|
||||
}
|
||||
else {
|
||||
content += "Vous êtes entré sur une case humide, et vous avez <strong>réussi</strong> votre maîtrise !"
|
||||
explication += "Vous êtes entré sur une case humide, et vous avez <strong>réussi</strong> votre maîtrise !"
|
||||
}
|
||||
|
||||
content += " " + draconic.name + ": " + carac + " / " + level + " -> " + rolled.roll + " / " + rolled.score;
|
||||
explication += "<br><strong>Test : Rêve actuel / " + draconic.name + " / " + cellDescr.type + "</strong>"
|
||||
+ "<br>Jet : " + carac + " / " + difficulte + " -> " + rolled.score + "%<br><strong>Résutat : </strong>" + rolled.roll;
|
||||
|
||||
if (rolled.isETotal) {
|
||||
let souffle = RdDRollTables.getSouffle(true);
|
||||
content += "<br>Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle.name;
|
||||
let souffle = RdDRollTables.getSouffle();
|
||||
explication += "<br>Vous avez fait un Echec Total. Vous subissez un Souffle de Dragon : " + souffle.name;
|
||||
this.actor.createOwnedItem(souffle);
|
||||
}
|
||||
if (rolled.isPart) {
|
||||
content += "<br>Vous avez fait une Réussite Particulière";
|
||||
content += RdDResolutionTable.buildXpMessage(rolled, level)
|
||||
explication += "<br>Vous avez fait une Réussite Particulière";
|
||||
explication += RdDResolutionTable.buildXpMessage(rolled, difficulte)
|
||||
}
|
||||
|
||||
let humideDiag = new Dialog({
|
||||
title: "Case humide",
|
||||
content: content,
|
||||
content: explication,
|
||||
buttons: {
|
||||
choice: {
|
||||
icon: '<i class="fas fa-check"></i>',
|
||||
label: "Fermer",
|
||||
callback: () => this.manageCaseHumideResult()
|
||||
}
|
||||
choice: { icon: '<i class="fas fa-check"></i>', label: "Fermer", callback: () => this.manageCaseHumideResult() }
|
||||
}
|
||||
}
|
||||
);
|
||||
humideDiag.render(true);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
updateSprites( myself )
|
||||
{
|
||||
let coordTMR = myself.actor.data.data.reve.tmrpos.coord;
|
||||
let coordXY = TMRUtility.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 declencheSortEnReserve( coordTMR )
|
||||
{
|
||||
for (let sortReserve of this.sortReserves ) {
|
||||
if ( sortReserve.coord == coordTMR) {
|
||||
await this.actor.deleteSortReserve(coordTMR);
|
||||
this.updateSortReserve();
|
||||
ChatMessage.create( { title: "Sort en réserve", content: "Vous avez déclenché le sort en réserve " + sortReserve.sort.name, user: game.user._id } );
|
||||
this.close();
|
||||
}
|
||||
/* -------------------------------------------- */
|
||||
async declencheSortEnReserve(coordTMR) {
|
||||
let sortReserve = this.sortReserves.find(it => it.coord == coordTMR)
|
||||
if (sortReserve != undefined) {
|
||||
await this.actor.deleteSortReserve(sortReserve.coord);
|
||||
this.updateSortReserve();
|
||||
console.log("declencheSortEnReserve", sortReserve)
|
||||
const declenchementSort = "Vous avez déclenché le sort <strong>" + sortReserve.sort.name
|
||||
+ "</strong> en réserve en " + sortReserve.coord + " (" + TMRUtility.getTMRDescription(sortReserve.coord).label
|
||||
+ ") avec " + sortReserve.sort.ptreve_reel + " points de Rêve";
|
||||
this._tellToUser(declenchementSort);
|
||||
this.close();
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async getCursorPosition(event) {
|
||||
/* -------------------------------------------- */
|
||||
async deplacerDemiReve(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;
|
||||
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]
|
||||
|
||||
console.log(">>>>", cellx, celly );
|
||||
|
||||
let eventCoord = RdDTMRDialog._computeEventCoord(origEvent);
|
||||
let cellx = eventCoord.cellx;
|
||||
let celly = eventCoord.celly;
|
||||
console.log("deplacerDemiReve >>>>", cellx, celly);
|
||||
|
||||
let currentPos = TMRUtility.convertToCellCoord(myself.actor.data.data.reve.tmrpos.coord);
|
||||
if ( (Math.abs(cellx - currentPos.x) > 1 || Math.abs(celly - currentPos.y) > 1) ||
|
||||
(currentPos.y == 0 && celly > currentPos.y && cellx != currentPos.x && currentPos.x % 2 == 0) ||
|
||||
(celly == 0 && celly < currentPos.y && cellx != currentPos.x && currentPos.x % 2 == 1) ) {
|
||||
ui.notifications.error( "Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position, et pas en diagonale" );
|
||||
|
||||
if (RdDTMRDialog._horsDePortee(currentPos, cellx, celly)) {
|
||||
ui.notifications.error("Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position");
|
||||
} else {
|
||||
let coordTMR = TMRUtility.convertToTMRCoord(cellx, celly);
|
||||
let cellDescr = TMRUtility.getTMRDescription( coordTMR );
|
||||
console.log("TMR column is", coordTMR, cellx, celly, cellDescr, this);
|
||||
let coordTMR = TMRUtility.convertToTMRCoord(cellx, celly);
|
||||
let cellDescr = TMRUtility.getTMRDescription(coordTMR);
|
||||
|
||||
console.log("deplacerDemiReve: 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);
|
||||
|
||||
await myself.actor.update({ "data.reve.tmrpos": tmrPos });
|
||||
myself._updateDemiReve(myself);
|
||||
myself.nbFatigue += 1;
|
||||
myself.updateValuesDisplay();
|
||||
myself.manageRencontre(coordTMR, cellDescr);
|
||||
myself.manageCaseHumide( cellDescr );
|
||||
await myself.declencheSortEnReserve( coordTMR );
|
||||
myself.updateValuesDisplay();
|
||||
|
||||
myself.manageRencontre(coordTMR, cellDescr);
|
||||
myself.manageCaseHumide(cellDescr);
|
||||
await myself.declencheSortEnReserve(coordTMR);
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async activateListeners(html) {
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async activateListeners(html) {
|
||||
super.activateListeners(html);
|
||||
|
||||
|
||||
var row = document.getElementById("tmrrow1");
|
||||
var cell1 = row.insertCell(1);
|
||||
cell1.append( this.pixiApp.view );
|
||||
|
||||
cell1.append(this.pixiApp.view);
|
||||
|
||||
// Roll Sort
|
||||
html.find('#lancer-sort').click((event) => {
|
||||
this.actor.rollUnSort(this.actor.data.data.reve.tmrpos.coord);
|
||||
});
|
||||
|
||||
|
||||
// load the texture we need
|
||||
await 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 );
|
||||
await this.pixiApp.loader
|
||||
.add('tmr', 'systems/foundryvtt-reve-de-dragon/styles/ui/tmp_main_r1.webp')
|
||||
.add('demi-reve', "icons/svg/sun.svg")
|
||||
.load((loader, resources) => {
|
||||
|
||||
// Add the bunny to the scene we are building
|
||||
this.pixiApp.stage.addChild(mytmr);
|
||||
this.pixiApp.stage.addChild(this.circle);
|
||||
|
||||
this.displayPreviousRencontres();
|
||||
this.displaySortReserve();
|
||||
} );
|
||||
// This creates a texture from a TMR image
|
||||
const mytmr = new PIXI.Sprite(resources.tmr.texture);
|
||||
// Setup the position of the TMR
|
||||
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.deplacerDemiReve);
|
||||
this.pixiApp.stage.addChild(mytmr);
|
||||
|
||||
await this.actor.updatePointsDeReve( (this.tmrdata.isRapide) ? -2 : -1); // 1 point defatigue
|
||||
this._addDemiReve();
|
||||
this.displayPreviousRencontres();
|
||||
this.displaySortReserve();
|
||||
});
|
||||
|
||||
await this.actor.updatePointsDeReve((this.tmrdata.isRapide) ? -2 : -1); // 1 point defatigue
|
||||
this.updateValuesDisplay();
|
||||
let cellDescr = TMRUtility.getTMRDescription(this.actor.data.data.reve.tmrpos.coord);
|
||||
this.manageRencontre( this.actor.data.data.reve.tmrpos.coord,cellDescr );
|
||||
this.manageCaseHumide( cellDescr );
|
||||
this.manageRencontre(this.actor.data.data.reve.tmrpos.coord, cellDescr);
|
||||
this.manageCaseHumide(cellDescr);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
static _computeEventCoord(origEvent) {
|
||||
let canvasRect = origEvent.target.getBoundingClientRect();
|
||||
let x = origEvent.clientX - canvasRect.left;
|
||||
let y = origEvent.clientY - canvasRect.top;
|
||||
let cellx = Math.floor(x / tmrConstants.cellw); // [From 0 -> 12]
|
||||
y -= (cellx % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y;
|
||||
let celly = Math.floor(y / tmrConstants.cellh); // [From 0 -> 14]
|
||||
return { cellx, celly };
|
||||
}
|
||||
|
||||
static _horsDePortee(pos, cellx, celly) {
|
||||
return Math.abs(cellx - pos.x) > 1
|
||||
|| Math.abs(celly - pos.y) > 1
|
||||
|| (pos.y == 0 && celly > pos.y && cellx != pos.x && pos.x % 2 == 0)
|
||||
|| (celly == 0 && celly < pos.y && cellx != pos.x && pos.x % 2 == 1);
|
||||
}
|
||||
|
||||
_tokenRencontre(rencontre) {
|
||||
let sprite = new PIXI.Graphics();
|
||||
sprite.beginFill(0x767610, 0.6);
|
||||
sprite.drawCircle(0, 0, 6);
|
||||
sprite.endFill();
|
||||
sprite.decallage = {
|
||||
x: (tmrConstants.cellw / 2) - 16,
|
||||
y: 16 - (tmrConstants.cellh / 2)
|
||||
};
|
||||
return { sprite: sprite, rencontre: rencontre, coordTMR: () => rencontre.coord };
|
||||
}
|
||||
|
||||
_tokenSortEnReserve(sort) {
|
||||
let sprite = new PIXI.Graphics();
|
||||
sprite.beginFill(0x101010, 0.8);
|
||||
sprite.drawCircle(0, 0, 6);
|
||||
sprite.endFill();
|
||||
sprite.decallage = {
|
||||
x: 16 - (tmrConstants.cellw / 2),
|
||||
y: 16 - (tmrConstants.cellh / 2)
|
||||
}
|
||||
return { sprite: sprite, sort: sort, coordTMR: () => sort.coord}
|
||||
}
|
||||
|
||||
_tokenDemiReve() {
|
||||
let texture = PIXI.utils.TextureCache['demi-reve'];
|
||||
let sprite = new PIXI.Sprite(texture);
|
||||
sprite.width = tmrConstants.cellw * 0.7;
|
||||
sprite.height = tmrConstants.cellh * 0.7;
|
||||
sprite.anchor.set(0.5);
|
||||
sprite.tint = 0x00FFEE;
|
||||
return { sprite: sprite, actor: this.actor, coordTMR: () => this.actor.data.data.reve.tmrpos.coord }
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_addDemiReve() {
|
||||
this.demiReve = this._tokenDemiReve();
|
||||
this._setTokenPosition(this.demiReve);
|
||||
this.pixiApp.stage.addChild(this.demiReve.sprite);
|
||||
}
|
||||
|
||||
_updateDemiReve(myself) {
|
||||
myself._setTokenPosition(myself.demiReve);
|
||||
}
|
||||
|
||||
_setTokenPosition(token) {
|
||||
let coordXY = TMRUtility.convertToCellCoord(token.coordTMR());
|
||||
let decallagePairImpair = (coordXY.x % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y;
|
||||
let dx = (token.sprite.decallage == undefined) ? 0 : token.sprite.decallage.x;
|
||||
let dy = (token.sprite.decallage == undefined) ? 0 : token.sprite.decallage.y;
|
||||
token.sprite.x = tmrConstants.gridx + (coordXY.x * tmrConstants.cellw) + dx;
|
||||
token.sprite.y = tmrConstants.gridy + (coordXY.y * tmrConstants.cellh) + dy + decallagePairImpair;
|
||||
}
|
||||
|
||||
_removeTokens(filter) {
|
||||
const tokensToRemove = this.allTokens.filter(filter);
|
||||
for (let token of tokensToRemove) {
|
||||
this.pixiApp.stage.removeChild(token.sprite);
|
||||
}
|
||||
}
|
||||
|
||||
_trackToken(token) {
|
||||
this.allTokens.push(token)
|
||||
this._setTokenPosition(token);
|
||||
this.pixiApp.stage.addChild(token.sprite);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user