From 532889f2110036e3ab9484794347436972d31af1 Mon Sep 17 00:00:00 2001 From: Liza Carvelli Date: Thu, 2 Feb 2023 17:16:03 +0100 Subject: [PATCH] /pal near as debug command --- Pal.Client/Plugin.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/Pal.Client/Plugin.cs b/Pal.Client/Plugin.cs index 6a9e26b..a7ec563 100644 --- a/Pal.Client/Plugin.cs +++ b/Pal.Client/Plugin.cs @@ -162,6 +162,18 @@ namespace Pal.Client Service.WindowSystem.GetWindow()?.Toggle(); break; + case "near": + DebugNearest(m => true); + break; + + case "tnear": + DebugNearest(m => m.Type == Marker.EType.Trap); + break; + + case "hnear": + DebugNearest(m => m.Type == Marker.EType.Hoard); + break; + default: Service.Chat.PrintError($"[Palace Pal] Unknown sub-command '{arguments}' for '{command}'."); break; @@ -483,6 +495,7 @@ namespace Pal.Client } } + #region Up-/Download private async Task DownloadMarkersForTerritory(ushort territoryId) { try @@ -539,7 +552,9 @@ namespace Pal.Client DebugMessage = $"{DateTime.Now}\n{e}"; } } + #endregion + #region Command Handling private async Task FetchFloorStatistics() { if (!Service.RemoteApi.HasRoleOnCurrentServer("statistics:view")) @@ -572,6 +587,29 @@ namespace Pal.Client } } + private void DebugNearest(Predicate predicate) + { + if (!IsInDeepDungeon()) + return; + + var state = GetFloorMarkers(Service.ClientState.TerritoryType); + var playerPosition = Service.ClientState.LocalPlayer?.Position; + if (playerPosition == null) + return; + Service.Chat.Print($"[Pal] {playerPosition}"); + + var nearbyMarkers = state.Markers + .Where(m => predicate(m)) + .Where(m => m.SplatoonElement != null && m.SplatoonElement.color != COLOR_INVISIBLE) + .Select(m => new { m = m, distance = (playerPosition - m.Position)?.Length() ?? float.MaxValue }) + .OrderBy(m => m.distance) + .Take(5) + .ToList(); + foreach (var nearbyMarker in nearbyMarkers) + Service.Chat.Print($"{nearbyMarker.distance:F2} - {nearbyMarker.m.Type} {nearbyMarker.m.NetworkId?.ToString()?.Substring(0, 8)} - {nearbyMarker.m.Position}"); + } + #endregion + private IList GetRelevantGameObjects() { List result = new();