Fix: deplacement aleatoire

Le déplacement aléatoire ne prenait pas compte de la différence
entre colonnes paires/impaires
This commit is contained in:
Vincent Vandemeulebrouck 2023-11-15 22:11:44 +01:00
parent 30d41861fa
commit c7e00749c9
7 changed files with 69 additions and 88 deletions

View File

@ -19,7 +19,6 @@ import { RdDTimestamp } from "./time/rdd-timestamp.js";
import { TYPES } from "./item.js"; import { TYPES } from "./item.js";
/* -------------------------------------------- */ /* -------------------------------------------- */
export class RdDTMRDialog extends Dialog { export class RdDTMRDialog extends Dialog {
static async create(actor, tmrData) { static async create(actor, tmrData) {
@ -188,36 +187,23 @@ export class RdDTMRDialog extends Dialog {
} }
forceDemiRevePositionView() { forceDemiRevePositionView() {
this.notifierResonanceSigneDraconique(this._getActorCoord()); this.notifierResonanceSigneDraconique(this._getCoordActor());
this._trackToken(this.demiReve); this._trackToken(this.demiReve);
} }
_getActorCoord() { _getCoordActor() {
return this.actor.system.reve.tmrpos.coord; return this.actor.system.reve.tmrpos.coord;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
async moveFromKey(move) { async deplacementTMR(move) {
if (this.subdialog) { if (this.subdialog) {
return this.forceTMRContinueAction(); return this.forceTMRContinueAction();
} }
let oddq = TMRUtility.coordTMRToOddq(this._getActorCoord()); const coordOrig = this._getCoordActor();
const coordTarget = TMRUtility.deplacement(coordOrig, move);
if (move == 'top') oddq.row -= 1; await this._deplacerDemiReve(coordTarget, 'normal');
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(); this.checkQuitterTMR();
} }
@ -238,36 +224,36 @@ export class RdDTMRDialog extends Dialog {
} }
HtmlUtility.showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionnelles.isUsing("appliquer-fatigue")); HtmlUtility.showControlWhen(this.html.find(".appliquerFatigue"), ReglesOptionnelles.isUsing("appliquer-fatigue"));
HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getActorCoord())); HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(this._getCoordActor()));
this.html.find('tr.tmr-row *').click(event => this.subdialog?.bringToTop()); this.html.find('tr.tmr-row *').click(event => this.subdialog?.bringToTop());
// Roll Sort // Roll Sort
this.html.find('.lancer-sort').click(event => this.actor.rollUnSort(this._getActorCoord())); this.html.find('.lancer-sort').click(event => this.actor.rollUnSort(this._getCoordActor()));
this.html.find('.lire-signe-draconique').click(event => this.actor.rollLireSigneDraconique(this._getActorCoord())); this.html.find('.lire-signe-draconique').click(event => this.actor.rollLireSigneDraconique(this._getCoordActor()));
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('img.tmr-move').click(event => this.deplacementTMR(this.html.find(event.currentTarget)?.data('move')));
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 // 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(); await this.actor.reveActuelIncDec(this.calculCoutMonteeTMR());
await this.actor.reveActuelIncDec(reveCout);
this.cumulFatigue += this.fatigueParCase; this.cumulFatigue += this.fatigueParCase;
// Le reste... // Le reste...
this.updateValuesDisplay(); this.updateValuesDisplay();
let tmr = TMRUtility.getTMR(this._getActorCoord()); let tmr = TMRUtility.getTMR(this._getCoordActor());
await this.manageRencontre(tmr); await this.manageRencontre(tmr);
} }
calculCoutMonteeTMR() {
return ((this.tmrdata.isRapide && !EffetsDraconiques.isDeplacementAccelere(this.actor)) ? -2 : -1) - this.actor.countMonteeLaborieuse();
}
/* -------------------------------------------- */ /* -------------------------------------------- */
async updateValuesDisplay() { async updateValuesDisplay() {
if (!this.rendered) { if (!this.rendered) {
return; return;
} }
const coord = this._getActorCoord(); const coord = this._getCoordActor();
HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(coord)); HtmlUtility.showControlWhen(this.html.find(".lire-signe-draconique"), this.actor.isResonanceSigneDraconique(coord));
@ -425,7 +411,7 @@ export class RdDTMRDialog extends Dialog {
nbRounds: 1, nbRounds: 1,
canClose: false, canClose: false,
selectedCarac: { label: "reve-actuel" }, selectedCarac: { label: "reve-actuel" },
tmr: TMRUtility.getTMR(this._getActorCoord()) tmr: TMRUtility.getTMR(this._getCoordActor())
} }
await this._tentativeMaitrise(rencontreData); await this._tentativeMaitrise(rencontreData);
@ -608,19 +594,18 @@ export class RdDTMRDialog extends Dialog {
if (rencontre) { if (rencontre) {
return game.system.rdd.rencontresTMR.calculRencontre(rencontre, tmr); return game.system.rdd.rencontresTMR.calculRencontre(rencontre, tmr);
} }
let locTMR = (this.isDemiReveCache() const coordTMR = (this.isDemiReveCache()
? TMRUtility.getTMRType(tmr.coord) + " ??" ? TMRUtility.getTMRType(tmr.coord) + " ??"
: tmr.label + " (" + tmr.coord + ")"); : tmr.label + " (" + tmr.coord + ")");
const fakeDialogRencontre = { bringToTop: () => { } }; this.setTMRPendingAction({ bringToTop: () => { } })
this.setTMRPendingAction(fakeDialogRencontre) const myRoll = await RdDDice.rollTotal("1dt", { showDice: SHOW_DICE });
let myRoll = await RdDDice.rollTotal("1dt", { showDice: SHOW_DICE });
this.restoreTMRAfterAction() this.restoreTMRAfterAction()
if (myRoll == 7) { if (myRoll == 7) {
this._tellToUser(myRoll + ": Rencontre en " + locTMR); this._tellToUser(myRoll + ": Rencontre en " + coordTMR);
return await game.system.rdd.rencontresTMR.getRencontreAleatoire(tmr, this.actor.isMauvaiseRencontre()) return await game.system.rdd.rencontresTMR.getRencontreAleatoire(tmr, this.actor.isMauvaiseRencontre())
} else { } else {
this._tellToUser(myRoll + ": Pas de rencontre en " + locTMR); this._tellToUser(myRoll + ": Pas de rencontre en " + coordTMR);
return undefined; return undefined;
} }
} }
@ -935,7 +920,7 @@ export class RdDTMRDialog extends Dialog {
return this.forceTMRContinueAction() return this.forceTMRContinueAction()
} }
let clickOddq = TMRUtility.computeEventOddq(event); let clickOddq = TMRUtility.computeEventOddq(event);
let currentOddq = TMRUtility.coordTMRToOddq(this._getActorCoord()); let currentOddq = TMRUtility.coordTMRToOddq(this._getCoordActor());
let targetCoord = TMRUtility.oddqToCoordTMR(clickOddq); let targetCoord = TMRUtility.oddqToCoordTMR(clickOddq);
let currentCoord = TMRUtility.oddqToCoordTMR(currentOddq); let currentCoord = TMRUtility.oddqToCoordTMR(currentOddq);

View File

@ -228,14 +228,15 @@ export const TMRType = {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
const tmrRandomMovePatten = const TMR_MOVE = {
[{ name: 'top', col: 0, row: -1 }, "top": { even: { row: -1, col: 0 }, odd: { row: -1, col: 0 }, },
{ name: 'topright', col: 1, row: -1 }, "topleft": { even: { row: -1, col: -1 }, odd: { row: 0, col: -1 }, },
{ name: 'botright', col: 1, row: 1 }, "topright": { even: { row: -1, col: 1 }, odd: { row: 0, col: 1 }, },
{ name: 'bot', col: 0, row: 1 }, "bottomleft": { even: { row: 0, col: -1 }, odd: { row: 1, col: -1 }, },
{ name: 'botleft', col: -1, row: 1 }, "bottomright": { even: { row: 0, col: 1 }, odd: { row: 1, col: 1 }, },
{ name: 'topleft', col: -1, row: -1 } "bottom": { even: { row: 1, col: 0 }, odd: { row: 1, col: 0 }, },
] }
/* -------------------------------------------- */ /* -------------------------------------------- */
export class TMRUtility { export class TMRUtility {
@ -313,16 +314,32 @@ export class TMRUtility {
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async getDirectionPattern() { static deplacement(coordOrig, moveName) {
return await RdDDice.rollOneOf(tmrRandomMovePatten); const tmrMove = TMR_MOVE[moveName];
if (! tmrMove) {
ui.notifications.error(`Le déplacement dans les TMR '${moveName}' est inconnu`)
return coordOrig
}
const fromOddq = TMRUtility.coordTMRToOddq(coordOrig);
const move = TMRUtility.getOddqMove(tmrMove, fromOddq);
const toOddq = TMRUtility.addOddq(fromOddq, move);
return TMRUtility.oddqToCoordTMR(toOddq);
}
static getOddqMove(tmrMove, oddq) {
return oddq.col % 2 == 1 ? tmrMove.odd : tmrMove.even;
}
static async getDirectionPattern(oddq) {
const tmrMove = await RdDDice.rollOneOf(Object.values(TMR_MOVE));
return TMRUtility.getOddqMove(tmrMove, oddq);
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static async deplaceTMRAleatoire(actor, coord) { static async deplaceTMRAleatoire(actor, coord) {
const currentOddq = TMRUtility.coordTMRToOddq(coord); const oddq = TMRUtility.coordTMRToOddq(coord);
const direction = await TMRUtility.getDirectionPattern(); const direction = await TMRUtility.getDirectionPattern(oddq);
currentOddq.col = currentOddq.col + direction.col; const currentOddq = TMRUtility.addOddq(oddq, direction)
currentOddq.row = currentOddq.row + direction.row;
if (this.isOddqInTMR(currentOddq)) { // Sortie de carte ! Ré-insertion aléatoire if (this.isOddqInTMR(currentOddq)) { // Sortie de carte ! Ré-insertion aléatoire
return TMRUtility.getTMR(TMRUtility.oddqToCoordTMR(currentOddq)); return TMRUtility.getTMR(TMRUtility.oddqToCoordTMR(currentOddq));
} else { } else {
@ -432,12 +449,8 @@ export class TMRUtility {
row >= 0 && row >= 0 &&
(row + col % 2 <= 14) (row + col % 2 <= 14)
); );
// if (x >= 0 && x < 13 && y >= 0 && y < 14) return true;
// if (x >= 0 && x < 13 && x % 2 == 0 && y == 14) return true;
// return false;
} }
/* -------------------------------------------- */ /* -------------------------------------------- */
static distanceCoordTMR(coord1, coord2) { static distanceCoordTMR(coord1, coord2) {
let oddq1 = this.coordTMRToOddq(coord1); let oddq1 = this.coordTMRToOddq(coord1);
@ -450,13 +463,13 @@ export class TMRUtility {
const axial1 = TMRUtility.oddqToAxial(oddq1); const axial1 = TMRUtility.oddqToAxial(oddq1);
const axial2 = TMRUtility.oddqToAxial(oddq2); const axial2 = TMRUtility.oddqToAxial(oddq2);
return TMRUtility.distanceAxial(axial1, axial2); return TMRUtility.distanceAxial(axial1, axial2);
}
// const dx = oddq2.col - oddq1.col; static addOddq(move, oddq) {
// const dy = oddq2.row - oddq1.row; return {
// const abs_dx = Math.abs(dx); row: oddq.row + move.row,
// const abs_dy = Math.abs(dy); col: oddq.col + move.col
// const distance = Math.sign(dx) == Math.sign(dy) ? Math.max(abs_dx, abs_dy) : (abs_dx + abs_dy); }
// return distance;
} }
static oddqToAxial(pos) { static oddqToAxial(pos) {
@ -480,20 +493,4 @@ export class TMRUtility {
}; };
} }
// function axial_to_cube(hex):
// var q = hex.q
// var r = hex.r
// var s = -q - r
// return Cube(q, r, s)
// }
// /* -------------------------------------------- */
// static computeRealPictureCoordinates(coordOddq) {
// let decallagePairImpair = (coordOddq.col % 2 == 0) ? tmrConstants.col1_y : tmrConstants.col2_y;
// return {
// x: tmrConstants.gridx + (coordOddq.col * tmrConstants.cellw),
// y: tmrConstants.gridy + (coordOddq.row * tmrConstants.cellh) + decallagePairImpair
// }
// }
} }

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

Before

Width:  |  Height:  |  Size: 4.9 KiB

After

Width:  |  Height:  |  Size: 4.9 KiB

View File

@ -1,5 +1,4 @@
<form class="tmr-dialog"> <form class="tmr-dialog">
<h2 class="comptmrdialog" id="tmrDialogTitle" style="visibility: hidden;"></h2>
<table> <table>
<tr class="tmr-row"> <tr class="tmr-row">
<td> <td>
@ -14,14 +13,14 @@
</div> </div>
{{/if}} {{/if}}
<div class="flex-group-center"> <div class="flex-group-center">
<img class="small-button-direction" id='dir-top-left' src='systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-top-left.svg'> <img class="small-button-direction tmr-move" data-move="topleft" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-topleft.svg">
<img class="small-button-direction" id='dir-top' src='systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-top.svg'> <img class="small-button-direction tmr-move" data-move="top" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-top.svg">
<img class="small-button-direction" id='dir-top-right' src='systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-top-right.svg'> <img class="small-button-direction tmr-move" data-move="topright" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-topright.svg">
</div> </div>
<div class="flex-group-center"> <div class="flex-group-center">
<img class="small-button-direction" id='dir-bottom-left' src='systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-bottom-left.svg'> <img class="small-button-direction tmr-move" data-move="bottomleft" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-bottomleft.svg">
<img class="small-button-direction" id='dir-bottom' src='systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-bottom.svg'> <img class="small-button-direction tmr-move" data-move="bottom" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-bottom.svg">
<img class="small-button-direction" id='dir-bottom-right' src='systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-bottom-right.svg'> <img class="small-button-direction tmr-move" data-move="bottomright" src="systems/foundryvtt-reve-de-dragon/styles/img/ui/dir-bottomright.svg">
</div> </div>
<div class="flex-group-center lire-signe-draconique"> <div class="flex-group-center lire-signe-draconique">
<a>Lire un signe draconique</a> <a>Lire un signe draconique</a>