From f84a18aa951c0bc17b73f74477c72383627f2944 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bruno=20Jurkovi=C4=87?= Date: Sat, 1 Mar 2025 00:20:31 +0100 Subject: [PATCH] prevent selecting other players' warships --- src/client/graphics/layers/UnitLayer.ts | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/client/graphics/layers/UnitLayer.ts b/src/client/graphics/layers/UnitLayer.ts index a0bd2d385..5cae90c36 100644 --- a/src/client/graphics/layers/UnitLayer.ts +++ b/src/client/graphics/layers/UnitLayer.ts @@ -77,18 +77,25 @@ export class UnitLayer implements Layer { } /** - * Find warships near the given cell within a configurable radius + * Find player-owned warships near the given cell within a configurable radius * @param cell The cell to check - * @returns Array of warships in range, sorted by distance (closest first) + * @returns Array of player's warships in range, sorted by distance (closest first) */ private findWarshipsNearCell(cell: { x: number; y: number }): UnitView[] { const clickRef = this.game.ref(cell.x, cell.y); + // Make sure we have the current player + if (this.myPlayer == null) { + this.myPlayer = this.game.playerByClientID(this.clientID); + } + + // Only select warships owned by the player return this.game .units(UnitType.Warship) .filter( (unit) => unit.isActive() && + unit.owner() === this.myPlayer && // Only allow selecting own warships this.game.manhattanDist(unit.tile(), clickRef) <= this.WARSHIP_SELECTION_RADIUS, )