Now with spaws detection

This commit is contained in:
erik 2025-05-08 20:21:40 +02:00
parent d2e9988bdd
commit 56b09f509a

View file

@ -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<ChatTextInterceptEventArgs>(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<ChatTextInterceptEventArgs>(OnChatText);
CoreManager.Current.CommandLineText -= OnChatCommand;
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(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))