diff --git a/MosswartMassacre/MainView.cs b/MosswartMassacre/MainView.cs index b3808b2..2877688 100644 --- a/MosswartMassacre/MainView.cs +++ b/MosswartMassacre/MainView.cs @@ -9,8 +9,6 @@ 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() { @@ -24,8 +22,6 @@ 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."); } @@ -54,14 +50,5 @@ 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 4cfcfa1..4761a3b 100644 --- a/MosswartMassacre/PluginCore.cs +++ b/MosswartMassacre/PluginCore.cs @@ -1,6 +1,5 @@ using System; using System.Text.RegularExpressions; -using System.Timers; using Decal.Adapter; using Decal.Adapter.Wrappers; @@ -11,12 +10,10 @@ 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() { @@ -28,11 +25,6 @@ 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(); } @@ -51,14 +43,6 @@ 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; @@ -76,16 +60,9 @@ 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) { @@ -93,33 +70,16 @@ 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() { - double minutesElapsed = (DateTime.Now - statsStartTime).TotalMinutes; - - if (minutesElapsed > 0) + // Calculate kills per 5 minutes + var timeSinceLastKill = DateTime.Now - lastKillTime; + if (timeSinceLastKill.TotalMinutes > 0) { - killsPer5Min = (totalKills / minutesElapsed) * 5; - killsPerHour = (totalKills / minutesElapsed) * 60; + killsPer5Min = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 5; + killsPerHour = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 60; } + lastKillTime = DateTime.Now; } private bool IsKilledByMeMessage(string text) @@ -172,26 +132,7 @@ 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 def6358..3f46a6c 100644 --- a/MosswartMassacre/ViewXML/mainView.xml +++ b/MosswartMassacre/ViewXML/mainView.xml @@ -1,10 +1,8 @@ - + - - - - - + + +