From 56b09f509a5b0fbc167787b24ee376b270155c1c Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 8 May 2025 20:21:40 +0200 Subject: [PATCH] Now with spaws detection --- MosswartMassacre/PluginCore.cs | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/MosswartMassacre/PluginCore.cs b/MosswartMassacre/PluginCore.cs index b12285f..9128333 100644 --- a/MosswartMassacre/PluginCore.cs +++ b/MosswartMassacre/PluginCore.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Linq; using System.Net; using System.Runtime.InteropServices; using System.Text.RegularExpressions; @@ -43,6 +44,8 @@ namespace MosswartMassacre CoreManager.Current.ChatBoxMessage += new EventHandler(AllChatText); CoreManager.Current.CommandLineText += OnChatCommand; CoreManager.Current.CharacterFilter.LoginComplete += CharacterFilter_LoginComplete; + CoreManager.Current.WorldFilter.CreateObject += OnSpawn; + CoreManager.Current.WorldFilter.ReleaseObject += OnDespawn; // Initialize the timer updateTimer = new Timer(1000); // Update every second @@ -78,6 +81,8 @@ namespace MosswartMassacre CoreManager.Current.ChatBoxMessage -= new EventHandler(OnChatText); CoreManager.Current.CommandLineText -= OnChatCommand; CoreManager.Current.ChatBoxMessage -= new EventHandler(AllChatText); + CoreManager.Current.WorldFilter.CreateObject -= OnSpawn; + CoreManager.Current.WorldFilter.ReleaseObject -= OnDespawn; // Stop and dispose of the timer if (updateTimer != null) @@ -123,6 +128,33 @@ namespace MosswartMassacre } + private 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; + + WriteToChat($"[Spawn] {mob.Name} @ (NS={ns:F1}, EW={ew:F1})"); + // TODO: record (ew, ns) for your heatmap + } + + 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; + + WriteToChat($"[Despawn] {mob.Name} @ (NS={ns:F1}, EW={ew:F1})"); + } + private static string NormalizeChatLine(string raw) { if (string.IsNullOrEmpty(raw))