From bb7e46cf4b226048b3f26f26383f18070d762ab0 Mon Sep 17 00:00:00 2001 From: mudabbir-ahmad Date: Thu, 9 Apr 2026 22:46:27 +0100 Subject: [PATCH] global claim fix attempt #2 --- src/hooks/usePlayerGame.js | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/hooks/usePlayerGame.js b/src/hooks/usePlayerGame.js index 85b5370..6a90b9c 100644 --- a/src/hooks/usePlayerGame.js +++ b/src/hooks/usePlayerGame.js @@ -16,8 +16,15 @@ const usePlayerGame = (playerLocation, playerHeading, activeCaches, claimDistanc return; } - const selected = (activeCaches || []).find((c) => c.id === selectedCacheId); - const visible = selected && isInClaimCone(playerHeading, playerLocation, selected.coordinates, claimDistance); + const caches = activeCaches || []; + let selected = selectedCacheId ? caches.find((c) => c.id === selectedCacheId) : null; + let visible = selected && isInClaimCone(playerHeading, playerLocation, selected.coordinates, claimDistance); + + if (!visible) { + selected = caches.find((c) => isInClaimCone(playerHeading, playerLocation, c.coordinates, claimDistance)) || null; + visible = Boolean(selected); + } + const newId = visible ? String(selected.id) : ''; if (newId !== prevIdRef.current) {