diff --git a/apps/api/src/game/Game.ts b/apps/api/src/game/Game.ts index f5abe38..6fdf61e 100644 --- a/apps/api/src/game/Game.ts +++ b/apps/api/src/game/Game.ts @@ -76,6 +76,7 @@ export class Game { } shootInDirection(directionHex: Hex, shooter: Player) { + if (shooter.pos.equals(directionHex)) return false; let shotCard = false; shooter.previousPos = shooter.pos; const RANGE = 3; @@ -95,7 +96,6 @@ export class Game { if (position.equals(this.cardPos!)) { shooter.lastBulletHex = this.cardPos; this.previousCardPos = this.cardPos; - // this.spawnCard(); shotCard = true; return shotCard; } diff --git a/apps/api/src/game/game-utils.ts b/apps/api/src/game/game-utils.ts index e22374c..532543f 100644 --- a/apps/api/src/game/game-utils.ts +++ b/apps/api/src/game/game-utils.ts @@ -7,3 +7,7 @@ export const MOVE_DURATION_IN_SECONDS = 15; export function isNeighbor(hex: Hex, other: Hex) { return hex.neighbors().some((n) => n.equals(other)); } + +export function isSameMove(move: Hex, pos: Hex | null) { + return move.q === pos?.q && move.r === pos?.r; +} diff --git a/apps/api/src/game/game.service.ts b/apps/api/src/game/game.service.ts index d5495f2..bbb02bf 100644 --- a/apps/api/src/game/game.service.ts +++ b/apps/api/src/game/game.service.ts @@ -239,10 +239,16 @@ export class GameService { if (p.pendingMove !== null) { console.log("pending move wasn't null", p.playerType); } - - if (p.pendingMove === null) { - if (p.pos.equals(data.move)) return; - if (!isNeighbor(p.pos, data.move)) return; + if (!data.isShooting) { + if ( + p.pendingMove === null && + !(isNeighbor(p.pos, data.move) || p.pos.equals(data.move)) + ) + return; + } else { + if (p.pendingMove === null && !isNeighbor(p.pos, data.move)) { + return; + } } p.pendingMove = new Hex(data.move.q, data.move.r); } diff --git a/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx b/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx index 9e88ac1..427ac7a 100644 --- a/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx +++ b/apps/web/src/components/AnimatedPopup/AnimatedPopup.tsx @@ -32,7 +32,7 @@ const AnimatedPopup: React.FC = ({ return (
{events.map((e) => ( - + ))}
); diff --git a/apps/web/src/components/Game/Game.tsx b/apps/web/src/components/Game/Game.tsx index 6c4a4bb..e00f3e4 100644 --- a/apps/web/src/components/Game/Game.tsx +++ b/apps/web/src/components/Game/Game.tsx @@ -151,13 +151,24 @@ const Game = () => { (p) => p.walletId === walletId?.toString(), )!; - if ( - currentPlayer && - (!isNeighbor(move, currentPlayer.pos) || + if (!isShooting) { + if ( + !( + isNeighbor(move, currentPlayer.pos) || + isSameMove(move, currentPlayer.pos) + ) || + !isInGrid(move, gameState.grid, gameState.disappearedHexes) + ) { + return; + } + } else { + if ( + !isNeighbor(move, currentPlayer.pos) || !isInGrid(move, gameState.grid, gameState.disappearedHexes) || - isSameMove(move, currentPlayer.pos)) - ) { - return; + isSameMove(move, currentPlayer.pos) + ) { + return; + } } setClickedHex(hoveredHex); setMadeMove(true); diff --git a/apps/web/src/utils/calculation-utils.ts b/apps/web/src/utils/calculation-utils.ts index 60951f4..d5caa89 100644 --- a/apps/web/src/utils/calculation-utils.ts +++ b/apps/web/src/utils/calculation-utils.ts @@ -60,10 +60,7 @@ export function isInGrid(hex: Hex, grid: Hex[], disappearedHexes: Hex[]) { } export function isSameMove(move: Hex, pos: Hex | null) { - if (move.q === pos?.q && move.r === pos?.r) { - return true; - } - return false; + return move.q === pos?.q && move.r === pos?.r; } export function inverseIsometricTransformation(