diff --git a/MosswartMassacre/MainView.cs b/MosswartMassacre/MainView.cs index 2877688..b3808b2 100644 --- a/MosswartMassacre/MainView.cs +++ b/MosswartMassacre/MainView.cs @@ -9,6 +9,8 @@ namespace MosswartMassacre private static IStaticText lblTotalKills; private static IStaticText lblKillsPer5Min; private static IStaticText lblKillsPerHour; + private static IStaticText lblElapsedTime; + private static IStaticText lblRareCount; public static void ViewInit() { @@ -22,6 +24,8 @@ namespace MosswartMassacre lblTotalKills = (IStaticText)View["lblTotalKills"]; lblKillsPer5Min = (IStaticText)View["lblKillsPer5Min"]; lblKillsPerHour = (IStaticText)View["lblKillsPerHour"]; + lblElapsedTime = (IStaticText)View["lblElapsedTime"]; + lblRareCount = (IStaticText)View["lblRareCount"]; PluginCore.WriteToChat("View initialized."); } @@ -50,5 +54,14 @@ namespace MosswartMassacre lblKillsPer5Min.Text = $"Kills per 5 Min: {killsPer5Min:F2}"; lblKillsPerHour.Text = $"Kills per Hour: {killsPerHour:F2}"; } + + public static void UpdateElapsedTime(TimeSpan elapsed) + { + lblElapsedTime.Text = $"Elapsed Time: {elapsed:hh\\:mm\\:ss}"; + } + public static void UpdateRareCount(int rareCount) + { + lblRareCount.Text = $"💎 Rare Count: {rareCount}"; + } } } diff --git a/MosswartMassacre/PluginCore.cs b/MosswartMassacre/PluginCore.cs index 4761a3b..4cfcfa1 100644 --- a/MosswartMassacre/PluginCore.cs +++ b/MosswartMassacre/PluginCore.cs @@ -1,5 +1,6 @@ using System; using System.Text.RegularExpressions; +using System.Timers; using Decal.Adapter; using Decal.Adapter.Wrappers; @@ -10,10 +11,12 @@ namespace MosswartMassacre { internal static PluginHost MyHost; internal static int totalKills = 0; + internal static int rareCount = 0; internal static DateTime lastKillTime = DateTime.Now; internal static double killsPer5Min = 0; internal static double killsPerHour = 0; internal static DateTime statsStartTime = DateTime.Now; + internal static Timer updateTimer; protected override void Startup() { @@ -25,6 +28,11 @@ namespace MosswartMassacre // Subscribe to chat message event CoreManager.Current.ChatBoxMessage += new EventHandler(OnChatText); + // Initialize the timer + updateTimer = new Timer(1000); // Update every second + updateTimer.Elapsed += UpdateStats; + updateTimer.Start(); + // Initialize the view (UI) MainView.ViewInit(); } @@ -43,6 +51,14 @@ namespace MosswartMassacre // Unsubscribe from chat message event CoreManager.Current.ChatBoxMessage -= new EventHandler(OnChatText); + // Stop and dispose of the timer + if (updateTimer != null) + { + updateTimer.Stop(); + updateTimer.Dispose(); + updateTimer = null; + } + // Clean up the view MainView.ViewDestroy(); MyHost = null; @@ -60,9 +76,16 @@ namespace MosswartMassacre if (IsKilledByMeMessage(e.Text)) { totalKills++; + lastKillTime = DateTime.Now; CalculateKillsPerInterval(); MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour); } + + if (IsRareDiscoveryMessage(e.Text)) + { + rareCount++; + MainView.UpdateRareCount(rareCount); + } } catch (Exception ex) { @@ -70,16 +93,33 @@ namespace MosswartMassacre } } + private void UpdateStats(object sender, ElapsedEventArgs e) + { + try + { + // Update the elapsed time + TimeSpan elapsed = DateTime.Now - statsStartTime; + MainView.UpdateElapsedTime(elapsed); + + // Recalculate kill rates + CalculateKillsPerInterval(); + MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour); + } + catch (Exception ex) + { + WriteToChat("Error updating stats: " + ex.Message); + } + } + private void CalculateKillsPerInterval() { - // Calculate kills per 5 minutes - var timeSinceLastKill = DateTime.Now - lastKillTime; - if (timeSinceLastKill.TotalMinutes > 0) + double minutesElapsed = (DateTime.Now - statsStartTime).TotalMinutes; + + if (minutesElapsed > 0) { - killsPer5Min = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 5; - killsPerHour = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 60; + killsPer5Min = (totalKills / minutesElapsed) * 5; + killsPerHour = (totalKills / minutesElapsed) * 60; } - lastKillTime = DateTime.Now; } private bool IsKilledByMeMessage(string text) @@ -132,7 +172,26 @@ namespace MosswartMassacre return false; } + private bool IsRareDiscoveryMessage(string text) + { + // Match pattern: " has discovered the !" + string pattern = @"^(?['A-Za-z ]+)\s(?has discovered the .*!$)"; + Match match = Regex.Match(text, pattern); + if (match.Success) + { + // Capture the name from the matched text + string name = match.Groups["name"].Value; + + // Compare the captured name to the player's name + if (name == CoreManager.Current.CharacterFilter.Name) + { + return true; + } + } + + return false; + } public static void WriteToChat(string message) { MyHost.Actions.AddChatText("[Mosswart Massacre] " + message, 0, 1); diff --git a/MosswartMassacre/ViewXML/mainView.xml b/MosswartMassacre/ViewXML/mainView.xml index 3f46a6c..def6358 100644 --- a/MosswartMassacre/ViewXML/mainView.xml +++ b/MosswartMassacre/ViewXML/mainView.xml @@ -1,8 +1,10 @@ - + - - - + + + + +