added z coords for portal discovery and minster disovery

This commit is contained in:
erik 2025-06-21 10:48:53 +02:00
parent 91cd934878
commit bb493febb4
7 changed files with 168 additions and 1573 deletions

View file

@ -108,6 +108,7 @@ namespace MosswartMassacre
CoreManager.Current.CharacterFilter.LoginComplete += CharacterFilter_LoginComplete;
CoreManager.Current.CharacterFilter.Death += OnCharacterDeath;
CoreManager.Current.WorldFilter.CreateObject += OnSpawn;
CoreManager.Current.WorldFilter.CreateObject += OnPortalDetected;
CoreManager.Current.WorldFilter.ReleaseObject += OnDespawn;
// Subscribe to inventory change events for taper tracking
CoreManager.Current.WorldFilter.CreateObject += OnInventoryCreate;
@ -172,6 +173,7 @@ namespace MosswartMassacre
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(AllChatText);
CoreManager.Current.CharacterFilter.Death -= OnCharacterDeath;
CoreManager.Current.WorldFilter.CreateObject -= OnSpawn;
CoreManager.Current.WorldFilter.CreateObject -= OnPortalDetected;
CoreManager.Current.WorldFilter.ReleaseObject -= OnDespawn;
// Unsubscribe from inventory change events
CoreManager.Current.WorldFilter.CreateObject -= OnInventoryCreate;
@ -454,12 +456,51 @@ namespace MosswartMassacre
try
{
var coords = mob.Coordinates();
// Get DECAL coordinates
var decalCoords = mob.Coordinates();
if (decalCoords == null) return;
const string fmt = "F7";
string ns = coords.NorthSouth.ToString(fmt, CultureInfo.InvariantCulture);
string ew = coords.EastWest.ToString(fmt, CultureInfo.InvariantCulture);
string ns = decalCoords.NorthSouth.ToString(fmt, CultureInfo.InvariantCulture);
string ew = decalCoords.EastWest.ToString(fmt, CultureInfo.InvariantCulture);
await WebSocket.SendSpawnAsync(ns, ew, mob.Name);
// Get Z coordinate using RawCoordinates() for accurate world Z position
string zCoord = "0";
try
{
var rawCoords = mob.RawCoordinates();
if (rawCoords != null)
{
zCoord = rawCoords.Z.ToString("F2", CultureInfo.InvariantCulture);
}
else
{
// Fallback to player Z approximation if RawCoordinates fails
var playerCoords = Coordinates.Me;
if (Math.Abs(playerCoords.Z) > 0.1)
{
zCoord = playerCoords.Z.ToString("F2", CultureInfo.InvariantCulture);
}
}
}
catch
{
// Fallback to player Z approximation on error
try
{
var playerCoords = Coordinates.Me;
if (Math.Abs(playerCoords.Z) > 0.1)
{
zCoord = playerCoords.Z.ToString("F2", CultureInfo.InvariantCulture);
}
}
catch
{
zCoord = "0";
}
}
await WebSocket.SendSpawnAsync(ns, ew, zCoord, mob.Name);
}
catch (Exception ex)
{
@ -467,6 +508,66 @@ namespace MosswartMassacre
}
}
private async void OnPortalDetected(object sender, CreateObjectEventArgs e)
{
var portal = e.New;
if (portal.ObjectClass != ObjectClass.Portal) return;
try
{
// Get portal coordinates from DECAL
var decalCoords = portal.Coordinates();
if (decalCoords == null) return;
const string fmt = "F7";
string ns = decalCoords.NorthSouth.ToString(fmt, CultureInfo.InvariantCulture);
string ew = decalCoords.EastWest.ToString(fmt, CultureInfo.InvariantCulture);
// Get Z coordinate using RawCoordinates() for accurate world Z position
string zCoord = "0";
try
{
var rawCoords = portal.RawCoordinates();
if (rawCoords != null)
{
zCoord = rawCoords.Z.ToString("F2", CultureInfo.InvariantCulture);
}
else
{
// Fallback to player Z approximation if RawCoordinates fails
var playerCoords = Coordinates.Me;
if (Math.Abs(playerCoords.Z) > 0.1)
{
zCoord = playerCoords.Z.ToString("F2", CultureInfo.InvariantCulture);
}
}
}
catch
{
// Fallback to player Z approximation on error
try
{
var playerCoords = Coordinates.Me;
if (Math.Abs(playerCoords.Z) > 0.1)
{
zCoord = playerCoords.Z.ToString("F2", CultureInfo.InvariantCulture);
}
}
catch
{
zCoord = "0";
}
}
await WebSocket.SendPortalAsync(ns, ew, zCoord, portal.Name);
}
catch (Exception ex)
{
PluginCore.WriteToChat($"[PORTAL ERROR] {ex.Message}");
PluginCore.WriteToChat($"[WS] Portal send failed: {ex}");
}
}
private void OnDespawn(object sender, ReleaseObjectEventArgs e)
{
@ -775,12 +876,12 @@ namespace MosswartMassacre
rareTextOnly = null;
// Match pattern: "<name> has discovered the <something>!"
string pattern = @"^(?<name>['A-Za-z ]+)\s(?<text>has discovered the .*!$)";
string pattern = @"^(?<name>['A-Za-z ]+)\shas discovered the (?<item>.*?)!$";
Match match = Regex.Match(text, pattern);
if (match.Success && match.Groups["name"].Value == CoreManager.Current.CharacterFilter.Name)
{
rareTextOnly = match.Groups["text"].Value; // just "has discovered the Ancient Pickle!"
rareTextOnly = match.Groups["item"].Value; // just "Ancient Pickle"
return true;
}