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:
2023-11-15 22:11:44 +01:00
parent 30d41861fa
commit c7e00749c9
7 changed files with 69 additions and 88 deletions

View File

@ -228,14 +228,15 @@ export const TMRType = {
}
/* -------------------------------------------- */
const tmrRandomMovePatten =
[{ name: 'top', col: 0, row: -1 },
{ name: 'topright', col: 1, row: -1 },
{ name: 'botright', col: 1, row: 1 },
{ name: 'bot', col: 0, row: 1 },
{ name: 'botleft', col: -1, row: 1 },
{ name: 'topleft', col: -1, row: -1 }
]
const TMR_MOVE = {
"top": { even: { row: -1, col: 0 }, odd: { row: -1, col: 0 }, },
"topleft": { even: { row: -1, col: -1 }, odd: { row: 0, col: -1 }, },
"topright": { even: { row: -1, col: 1 }, odd: { row: 0, col: 1 }, },
"bottomleft": { even: { row: 0, col: -1 }, odd: { row: 1, col: -1 }, },
"bottomright": { even: { row: 0, col: 1 }, odd: { row: 1, col: 1 }, },
"bottom": { even: { row: 1, col: 0 }, odd: { row: 1, col: 0 }, },
}
/* -------------------------------------------- */
export class TMRUtility {
@ -313,16 +314,32 @@ export class TMRUtility {
}
/* -------------------------------------------- */
static async getDirectionPattern() {
return await RdDDice.rollOneOf(tmrRandomMovePatten);
static deplacement(coordOrig, moveName) {
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) {
const currentOddq = TMRUtility.coordTMRToOddq(coord);
const direction = await TMRUtility.getDirectionPattern();
currentOddq.col = currentOddq.col + direction.col;
currentOddq.row = currentOddq.row + direction.row;
const oddq = TMRUtility.coordTMRToOddq(coord);
const direction = await TMRUtility.getDirectionPattern(oddq);
const currentOddq = TMRUtility.addOddq(oddq, direction)
if (this.isOddqInTMR(currentOddq)) { // Sortie de carte ! Ré-insertion aléatoire
return TMRUtility.getTMR(TMRUtility.oddqToCoordTMR(currentOddq));
} else {
@ -432,12 +449,8 @@ export class TMRUtility {
row >= 0 &&
(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) {
let oddq1 = this.coordTMRToOddq(coord1);
@ -450,13 +463,13 @@ export class TMRUtility {
const axial1 = TMRUtility.oddqToAxial(oddq1);
const axial2 = TMRUtility.oddqToAxial(oddq2);
return TMRUtility.distanceAxial(axial1, axial2);
}
// const dx = oddq2.col - oddq1.col;
// const dy = oddq2.row - oddq1.row;
// const abs_dx = Math.abs(dx);
// const abs_dy = Math.abs(dy);
// const distance = Math.sign(dx) == Math.sign(dy) ? Math.max(abs_dx, abs_dy) : (abs_dx + abs_dy);
// return distance;
static addOddq(move, oddq) {
return {
row: oddq.row + move.row,
col: oddq.col + move.col
}
}
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
// }
// }
}