prevent selecting other players' warships

This commit is contained in:
Bruno Jurković
2025-03-02 23:31:25 +01:00
parent 3d4ea515de
commit f84a18aa95
+9 -2
View File
@@ -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,
)