* Build getHexMap for a creature on a given grid. * Replicates the logic in creature.getHexMap + hexgrid.getHexMap.
(
hexes: any[][],
creatureX: number,
creatureY: number,
flipped: boolean,
invertFlipped: boolean,
mapDef: { origin: number[]; [key: string]: any },
)
| 79 | * Replicates the logic in creature.getHexMap + hexgrid.getHexMap. |
| 80 | */ |
| 81 | function getHexMap( |
| 82 | hexes: any[][], |
| 83 | creatureX: number, |
| 84 | creatureY: number, |
| 85 | flipped: boolean, |
| 86 | invertFlipped: boolean, |
| 87 | mapDef: { origin: number[]; [key: string]: any }, |
| 88 | ) { |
| 89 | const array = (mapDef as any).slice(0).map((row: number[]) => [...row]); |
| 90 | const size = 1; // Snow Bunny is size 1 |
| 91 | |
| 92 | const x = (flipped ? !invertFlipped : invertFlipped) ? creatureX + 1 - size : creatureX; |
| 93 | |
| 94 | let originx = x; |
| 95 | const originy = creatureY - mapDef.origin[1]; |
| 96 | const offsetx = 0 - mapDef.origin[0]; |
| 97 | |
| 98 | originx += flipped ? 1 - array[0].length - offsetx : -1 + offsetx; |
| 99 | |
| 100 | const result: any[] = []; |
| 101 | for (let y = 0; y < array.length; y++) { |
| 102 | if (flipped && y % 2 !== 0) array[y].push(0); |
| 103 | array[y].unshift(0); |
| 104 | if (originy % 2 !== 0 && y % 2 !== 0) { |
| 105 | if (flipped) array[y].pop(); |
| 106 | else array[y].splice(0, 1); |
| 107 | } |
| 108 | for (let xi = 0; xi < array[y].length; xi++) { |
| 109 | if (array[y][xi]) { |
| 110 | const xfinal = flipped ? array[y].length - 1 - xi : xi; |
| 111 | const fy = originy + y; |
| 112 | const fx = originx + xfinal; |
| 113 | if (fy >= 0 && fy < hexes.length && fx >= 0 && fx < hexes[fy].length) { |
| 114 | result.push(hexes[fy][fx]); |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | return result; |
| 120 | } |
| 121 | |
| 122 | // ---- Helper to build a minimal creature mock ---- |
| 123 | function makeBunny(hexGrid: any[][], x: number, y: number, team = 0) { |