forked from public/foundryvtt-reve-de-dragon
#27 Gestion des rencontres
This commit is contained in:
@ -46,6 +46,7 @@ export class RdDTMRDialog extends Dialog {
|
||||
this.rencontresExistantes = duplicate(this.actor.data.data.reve.rencontre.list);
|
||||
this.sortReserves = duplicate(this.actor.data.data.reve.reserve.list);
|
||||
this.allTokens = [];
|
||||
this.rencontreState = "aucune";
|
||||
this.pixiApp = new PIXI.Application({ width: 720, height: 860 });
|
||||
}
|
||||
|
||||
@ -101,6 +102,44 @@ export class RdDTMRDialog extends Dialog {
|
||||
console.log("-> refouler", this.currentRencontre)
|
||||
this.updateValuesDisplay();
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
colorierZone( locList) {
|
||||
this.currentRencontre.graphics = []; // Keep track of rectangles to delete it
|
||||
this.currentRencontre.locList = duplicate(locList); // And track of allowed location
|
||||
for (let loc of locList) {
|
||||
let rect = this._getCaseRectangleCoord( loc);
|
||||
var rectDraw = new PIXI.Graphics();
|
||||
rectDraw.beginFill(0xFFFF00, 0.3);
|
||||
// set the line style to have a width of 5 and set the color to red
|
||||
rectDraw.lineStyle(5, 0xFF0000);
|
||||
// draw a rectangle
|
||||
rectDraw.drawRect(rect.x, rect.y, rect.w, rect.h);
|
||||
this.pixiApp.stage.addChild(rectDraw);
|
||||
this.currentRencontre.graphics.push(rectDraw); // garder les objets pour gestion post-click
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Gère les rencontres avec du post-processing graphique (passeur, messagers, tourbillons, ...) */
|
||||
rencontrePostProcess( rencontreData) {
|
||||
if (!rencontreData) return; // Sanity check
|
||||
this.rencontreState = rencontreData.state; // garder la trace de l'état en cours
|
||||
if ( this.rencontreState == "passeur") {
|
||||
console.log("Processing passeur");
|
||||
// Récupère la liste des cases à portées
|
||||
let locList = TMRUtility.getTMRArea(this.actor.data.data.reve.tmrpos.coord, this.currentRencontre.force, tmrConstants );
|
||||
this.colorierZone( locList );
|
||||
} else if ( this.rencontreState == "messager") {
|
||||
console.log("Processing messager");
|
||||
// Récupère la liste des cases à portées
|
||||
let locList = TMRUtility.getTMRArea(this.actor.data.data.reve.tmrpos.coord, this.currentRencontre.force, tmrConstants );
|
||||
this.colorierZone( locList );
|
||||
} else {
|
||||
this.currentRencontre = undefined; // Cleanup, not used anymore
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async maitriser(data) {
|
||||
this.actor.deleteTMRRencontreAtPosition(); // Remove the stored rencontre if necessary
|
||||
@ -117,16 +156,22 @@ export class RdDTMRDialog extends Dialog {
|
||||
let message = "<br><strong>Test : Rêve actuel / " + draconic.name + " / " + this.currentRencontre.name + "</strong>" + "<br>"
|
||||
+ RdDResolutionTable.explain(rolled);
|
||||
|
||||
let rencontreData
|
||||
if (rolled.isEchec) {
|
||||
message += await TMRUtility.processRencontreEchec(this.actor, this.currentRencontre, rolled, this);
|
||||
rencontreData = await TMRUtility.processRencontreEchec(this.actor, this.currentRencontre, rolled, this);
|
||||
message += rencontreData.message;
|
||||
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);
|
||||
if (this.currentRencontre.data.quitterTMR) // Selon les rencontres, quitter TMR ou pas
|
||||
this.close();
|
||||
} else {
|
||||
message += await TMRUtility.processRencontreReussite(this.actor, this.currentRencontre, rolled);
|
||||
rencontreData = await TMRUtility.processRencontreReussite(this.actor, this.currentRencontre, rolled);
|
||||
message += rencontreData.message;
|
||||
this._tellToUser("Vous avez <strong>réussi</strong> à maîtriser un " + this.currentRencontre.name + " de force " + this.currentRencontre.force + message);
|
||||
}
|
||||
|
||||
this.rencontrePostProcess( rencontreData );
|
||||
|
||||
console.log("-> matriser", this.currentRencontre);
|
||||
this.updateValuesDisplay();
|
||||
}
|
||||
@ -154,7 +199,7 @@ export class RdDTMRDialog extends Dialog {
|
||||
rencontre = await TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
|
||||
}
|
||||
}
|
||||
//rencontre = await TMRUtility.rencontreTMRRoll(coordTMR, cellDescr); To test
|
||||
rencontre = await TMRUtility.rencontreTMRRoll(coordTMR, cellDescr);
|
||||
|
||||
if (rencontre) { // Manages it
|
||||
if (rencontre.rencontre) rencontre = rencontre.rencontre; // Manage stored rencontres
|
||||
@ -276,6 +321,19 @@ export class RdDTMRDialog extends Dialog {
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
processClickPostRencontre( coord ) {
|
||||
let deplacementType = "erreur";
|
||||
if (this.rencontreState == "passeur" || this.rencontreState == "messager") {
|
||||
let isInArea = this.currentRencontre.locList.find(locCoord => locCoord == coord );
|
||||
if ( isInArea ) { // OK !
|
||||
deplacementType = "saut";
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
async deplacerDemiReve(event) {
|
||||
if (this.viewOnly) {
|
||||
@ -288,12 +346,19 @@ export class RdDTMRDialog extends Dialog {
|
||||
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 (RdDTMRDialog._horsDePortee(currentPos, cellx, celly)) {
|
||||
ui.notifications.error("Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position");
|
||||
|
||||
// Validation de la case de destination (gestion du cas des rencontres qui peuvent téléporter)
|
||||
let deplacementType = "erreur";
|
||||
if ( this.rencontreState == "aucune") { // Pas de recontre en post-processing, donc deplacement normal
|
||||
if ( !RdDTMRDialog._horsDePortee(currentPos, cellx, celly)) {
|
||||
deplacementType = "normal";
|
||||
}
|
||||
} else {
|
||||
deplacementType = this.processClickPostRencontre( currentPos );
|
||||
}
|
||||
// Si le deplacement est valide
|
||||
if ( deplacementType == "normal" || deplacementType == "saut") {
|
||||
let coordTMR = TMRUtility.convertToTMRCoord(cellx, celly);
|
||||
let cellDescr = TMRUtility.getTMRDescription(coordTMR);
|
||||
|
||||
@ -306,9 +371,13 @@ export class RdDTMRDialog extends Dialog {
|
||||
myself.nbFatigue += 1;
|
||||
myself.updateValuesDisplay();
|
||||
|
||||
myself.manageRencontre(coordTMR, cellDescr);
|
||||
if ( deplacementType == "normal") { // Pas de rencontres après un saut de type passeur/changeur/...
|
||||
myself.manageRencontre(coordTMR, cellDescr);
|
||||
}
|
||||
myself.manageCaseHumide(cellDescr);
|
||||
await myself.declencheSortEnReserve(coordTMR);
|
||||
} else {
|
||||
ui.notifications.error("Vous ne pouvez vous déplacer que sur des cases adjacentes à votre position ou valides dans le cas d'une rencontre");
|
||||
}
|
||||
}
|
||||
|
||||
@ -448,6 +517,16 @@ export class RdDTMRDialog extends Dialog {
|
||||
myself._setTokenPosition(myself.demiReve);
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
/** Retourne les coordonnées x, h, w, h du rectangle d'une case donnée */
|
||||
_getCaseRectangleCoord( coord ) {
|
||||
let coordXY = TMRUtility.convertToCellCoord( coord );
|
||||
let decallagePairImpair = (coordXY.x % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y;
|
||||
let x = tmrConstants.gridx + (coordXY.x * tmrConstants.cellw) - (tmrConstants.cellw /2);
|
||||
let y = tmrConstants.gridy + (coordXY.y * tmrConstants.cellh) - (tmrConstants.cellh /2) + decallagePairImpair;
|
||||
return {x: x, y: y, w: tmrConstants.cellw, h: tmrConstants.cellh}
|
||||
}
|
||||
|
||||
/* -------------------------------------------- */
|
||||
_setTokenPosition(token) {
|
||||
let coordXY = TMRUtility.convertToCellCoord(token.coordTMR());
|
||||
|
Reference in New Issue
Block a user