diff --git a/MosswartMassacre/PluginCore.cs b/MosswartMassacre/PluginCore.cs index 9128333..9fe72b8 100644 --- a/MosswartMassacre/PluginCore.cs +++ b/MosswartMassacre/PluginCore.cs @@ -1,8 +1,10 @@ using System; using System.Collections.Generic; +using System.Globalization; using System.Linq; using System.Net; using System.Runtime.InteropServices; +using System.Text; using System.Text.RegularExpressions; using System.Timers; using Decal.Adapter; @@ -128,31 +130,49 @@ namespace MosswartMassacre } - private void OnSpawn(object sender, CreateObjectEventArgs e) + private async void OnSpawn(object sender, CreateObjectEventArgs e) { - // e.New is the wrapped WorldObject that just appeared var mob = e.New; if (mob.ObjectClass != ObjectClass.Monster) return; - var coords = mob.Coordinates(); - float ns = (float)coords.NorthSouth; - float ew = (float)coords.EastWest; + try + { + var coords = mob.Coordinates(); + const string fmt = "F7"; + string ns = coords.NorthSouth.ToString(fmt, CultureInfo.InvariantCulture); + string ew = coords.EastWest.ToString(fmt, CultureInfo.InvariantCulture); - WriteToChat($"[Spawn] {mob.Name} @ (NS={ns:F1}, EW={ew:F1})"); - // TODO: record (ew, ns) for your heatmap + await WebSocket.SendSpawnAsync(ns, ew, mob.Name); + } + catch (Exception ex) + { + PluginCore.WriteToChat($"[WS] Spawn send failed: {ex}"); + } } + private void OnDespawn(object sender, ReleaseObjectEventArgs e) { - // e.Released is the wrapped WorldObject that just disappeared var mob = e.Released; if (mob.ObjectClass != ObjectClass.Monster) return; - var coords = mob.Coordinates(); - float ns = (float)coords.NorthSouth; - float ew = (float)coords.EastWest; + + // var c = mob.Coordinates(); + // PluginCore.WriteToChat( + // $"[Despawn] {mob.Name} @ (NS={c.NorthSouth:F1}, EW={c.EastWest:F1})"); + } - WriteToChat($"[Despawn] {mob.Name} @ (NS={ns:F1}, EW={ew:F1})"); + private async void AllChatText(object sender, ChatTextInterceptEventArgs e) + { + try + { + string cleaned = NormalizeChatLine(e.Text); + await WebSocket.SendChatTextAsync(e.Color, cleaned); + } + catch (Exception ex) + { + PluginCore.WriteToChat($"[WS] Chat send failed: {ex}"); + } } private static string NormalizeChatLine(string raw) @@ -171,20 +191,6 @@ namespace MosswartMassacre return collapsed; } - private void AllChatText(object sender, ChatTextInterceptEventArgs e) - { - try - { - - var cleaned = NormalizeChatLine(e.Text); - - _ = WebSocket.SendChatTextAsync(e.Color, cleaned); - } - catch (Exception ex) - { - PluginCore.WriteToChat("Error sending chat over WS: " + ex.Message); - } - } private void HandleServerCommand(CommandEnvelope env) { // Skicka commands diff --git a/MosswartMassacre/WebSocket.cs b/MosswartMassacre/WebSocket.cs index fd641cf..f13a069 100644 --- a/MosswartMassacre/WebSocket.cs +++ b/MosswartMassacre/WebSocket.cs @@ -193,6 +193,19 @@ namespace MosswartMassacre var json = JsonConvert.SerializeObject(envelope); await SendEncodedAsync(json, CancellationToken.None); } + public static async Task SendSpawnAsync(string nsCoord, string ewCoord, string monster) + { + var envelope = new + { + type = "spawn", + mob = monster, + ns = nsCoord, + ew = ewCoord + + }; + var json = JsonConvert.SerializeObject(envelope); + await SendEncodedAsync(json, CancellationToken.None); + } // ─── shared send helper with locking ───────────────