thonk
This commit is contained in:
parent
619d41838f
commit
7956a7b420
|
@ -1,3 +1,4 @@
|
||||||
|
using System.Numerics;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
using Newtonsoft.Json.Serialization;
|
using Newtonsoft.Json.Serialization;
|
||||||
|
|
||||||
|
@ -16,4 +17,6 @@ internal class Message {
|
||||||
|
|
||||||
public int PositiveVotes { get; init; }
|
public int PositiveVotes { get; init; }
|
||||||
public int NegativeVotes { get; init; }
|
public int NegativeVotes { get; init; }
|
||||||
|
|
||||||
|
internal Vector3 Position => new(this.X, this.Y, this.Z);
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,7 +9,10 @@ internal class Messages : IDisposable {
|
||||||
|
|
||||||
private Plugin Plugin { get; }
|
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> SpawnQueue { get; } = new();
|
||||||
|
private Queue<Message> RemoveQueue { get; } = new();
|
||||||
|
|
||||||
internal Messages(Plugin plugin) {
|
internal Messages(Plugin plugin) {
|
||||||
this.Plugin = plugin;
|
this.Plugin = plugin;
|
||||||
|
@ -36,7 +39,7 @@ internal class Messages : IDisposable {
|
||||||
return;
|
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) {
|
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 resp = await new HttpClient().GetAsync($"https://tryfingerbuthole.anna.lgbt/messages/{territory}");
|
||||||
var json = await resp.Content.ReadAsStringAsync();
|
var json = await resp.Content.ReadAsStringAsync();
|
||||||
var messages = JsonConvert.DeserializeObject<Message[]>(json)!;
|
var messages = JsonConvert.DeserializeObject<Message[]>(json)!;
|
||||||
|
|
||||||
|
await this.CurrentMutex.WaitAsync();
|
||||||
|
this.Current = messages;
|
||||||
|
this.CurrentMutex.Release();
|
||||||
|
|
||||||
foreach (var message in messages) {
|
foreach (var message in messages) {
|
||||||
this.SpawnQueue.Enqueue(message);
|
this.SpawnQueue.Enqueue(message);
|
||||||
}
|
}
|
||||||
|
@ -68,4 +76,17 @@ internal class Messages : IDisposable {
|
||||||
private void RemoveVfx(object? sender, EventArgs? e) {
|
private void RemoveVfx(object? sender, EventArgs? e) {
|
||||||
this.Plugin.Vfx.RemoveAll();
|
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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
|
using System.Numerics;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Dalamud.Logging;
|
||||||
using ImGuiNET;
|
using ImGuiNET;
|
||||||
using Newtonsoft.Json;
|
using Newtonsoft.Json;
|
||||||
|
|
||||||
|
@ -187,6 +189,12 @@ public class PluginUi : IDisposable {
|
||||||
ImGui.EndDisabled();
|
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();
|
ImGui.End();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user