diff --git a/client/Message.cs b/client/Message.cs index 67722d4..77b9802 100644 --- a/client/Message.cs +++ b/client/Message.cs @@ -1,3 +1,4 @@ +using System.Numerics; using Newtonsoft.Json; using Newtonsoft.Json.Serialization; @@ -13,7 +14,9 @@ internal class Message { [JsonProperty("message")] public string Text { get; init; } - + public int PositiveVotes { get; init; } public int NegativeVotes { get; init; } + + internal Vector3 Position => new(this.X, this.Y, this.Z); } diff --git a/client/Messages.cs b/client/Messages.cs index adf2517..a3788d8 100644 --- a/client/Messages.cs +++ b/client/Messages.cs @@ -9,7 +9,10 @@ internal class Messages : IDisposable { private Plugin Plugin { get; } + private SemaphoreSlim CurrentMutex { get; } = new(1, 1); + private Message[] Current { get; set; } = Array.Empty(); private Queue SpawnQueue { get; } = new(); + private Queue RemoveQueue { get; } = new(); internal Messages(Plugin plugin) { this.Plugin = plugin; @@ -36,7 +39,7 @@ internal class Messages : IDisposable { return; } - this.Plugin.Vfx.SpawnStatic(VfxPath, new Vector3(message.X, message.Y, message.Z)); + this.Plugin.Vfx.SpawnStatic(VfxPath, message.Position); } private void SpawnVfx(object? sender, EventArgs e) { @@ -59,6 +62,11 @@ internal class Messages : IDisposable { var resp = await new HttpClient().GetAsync($"https://tryfingerbuthole.anna.lgbt/messages/{territory}"); var json = await resp.Content.ReadAsStringAsync(); var messages = JsonConvert.DeserializeObject(json)!; + + await this.CurrentMutex.WaitAsync(); + this.Current = messages; + this.CurrentMutex.Release(); + foreach (var message in messages) { this.SpawnQueue.Enqueue(message); } @@ -68,4 +76,17 @@ internal class Messages : IDisposable { private void RemoveVfx(object? sender, EventArgs? e) { this.Plugin.Vfx.RemoveAll(); } + + internal Message[] Nearby() { + if (this.Plugin.ClientState.LocalPlayer is not { } player) { + return Array.Empty(); + } + + var position = player.Position; + + return this.Current + .Where(msg => Math.Abs(msg.Position.Y - position.Y) < 1f) + .Where(msg => Vector3.Distance(msg.Position, position) < 5f) + .ToArray(); + } } diff --git a/client/PluginUi.cs b/client/PluginUi.cs index 4999ed2..9e7e672 100644 --- a/client/PluginUi.cs +++ b/client/PluginUi.cs @@ -1,5 +1,7 @@ using System.Net.Http.Headers; +using System.Numerics; using System.Text; +using Dalamud.Logging; using ImGuiNET; using Newtonsoft.Json; @@ -187,6 +189,12 @@ public class PluginUi : IDisposable { ImGui.EndDisabled(); } + if (this.Plugin.ClientState.LocalPlayer is { } player2) { + foreach (var msg in this.Plugin.Messages.Nearby()) { + PluginLog.Log($"{msg.Text}: {Vector3.Distance(msg.Position, player2.Position):N2}"); + } + } + ImGui.End(); }