This commit is contained in:
Anna 2022-09-03 22:23:35 -04:00
parent 619d41838f
commit 7956a7b420
3 changed files with 34 additions and 2 deletions

View File

@ -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);
}

View File

@ -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<Message>();
private Queue<Message> SpawnQueue { get; } = new();
private Queue<Message> 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<Message[]>(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<Message>();
}
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();
}
}

View File

@ -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();
}