Compare commits

...

2 commits

Author SHA1 Message Date
erikn
e5c033c9ed Merge branch 'master' of git.snakedesert.se:SawatoMosswartsEnjoyersClub/MosswartMassacre 2025-03-29 00:48:16 +01:00
erikn
dcfa888f61 More mossawarts 2025-03-29 00:47:36 +01:00
3 changed files with 84 additions and 10 deletions

View file

@ -9,6 +9,8 @@ namespace MosswartMassacre
private static IStaticText lblTotalKills; private static IStaticText lblTotalKills;
private static IStaticText lblKillsPer5Min; private static IStaticText lblKillsPer5Min;
private static IStaticText lblKillsPerHour; private static IStaticText lblKillsPerHour;
private static IStaticText lblElapsedTime;
private static IStaticText lblRareCount;
public static void ViewInit() public static void ViewInit()
{ {
@ -22,6 +24,8 @@ namespace MosswartMassacre
lblTotalKills = (IStaticText)View["lblTotalKills"]; lblTotalKills = (IStaticText)View["lblTotalKills"];
lblKillsPer5Min = (IStaticText)View["lblKillsPer5Min"]; lblKillsPer5Min = (IStaticText)View["lblKillsPer5Min"];
lblKillsPerHour = (IStaticText)View["lblKillsPerHour"]; lblKillsPerHour = (IStaticText)View["lblKillsPerHour"];
lblElapsedTime = (IStaticText)View["lblElapsedTime"];
lblRareCount = (IStaticText)View["lblRareCount"];
PluginCore.WriteToChat("View initialized."); PluginCore.WriteToChat("View initialized.");
} }
@ -50,5 +54,14 @@ namespace MosswartMassacre
lblKillsPer5Min.Text = $"Kills per 5 Min: {killsPer5Min:F2}"; lblKillsPer5Min.Text = $"Kills per 5 Min: {killsPer5Min:F2}";
lblKillsPerHour.Text = $"Kills per Hour: {killsPerHour: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}";
}
} }
} }

View file

@ -1,5 +1,6 @@
using System; using System;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Timers;
using Decal.Adapter; using Decal.Adapter;
using Decal.Adapter.Wrappers; using Decal.Adapter.Wrappers;
@ -10,10 +11,12 @@ namespace MosswartMassacre
{ {
internal static PluginHost MyHost; internal static PluginHost MyHost;
internal static int totalKills = 0; internal static int totalKills = 0;
internal static int rareCount = 0;
internal static DateTime lastKillTime = DateTime.Now; internal static DateTime lastKillTime = DateTime.Now;
internal static double killsPer5Min = 0; internal static double killsPer5Min = 0;
internal static double killsPerHour = 0; internal static double killsPerHour = 0;
internal static DateTime statsStartTime = DateTime.Now; internal static DateTime statsStartTime = DateTime.Now;
internal static Timer updateTimer;
protected override void Startup() protected override void Startup()
{ {
@ -25,6 +28,11 @@ namespace MosswartMassacre
// Subscribe to chat message event // Subscribe to chat message event
CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(OnChatText); CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
// Initialize the timer
updateTimer = new Timer(1000); // Update every second
updateTimer.Elapsed += UpdateStats;
updateTimer.Start();
// Initialize the view (UI) // Initialize the view (UI)
MainView.ViewInit(); MainView.ViewInit();
} }
@ -43,6 +51,14 @@ namespace MosswartMassacre
// Unsubscribe from chat message event // Unsubscribe from chat message event
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(OnChatText); CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
// Stop and dispose of the timer
if (updateTimer != null)
{
updateTimer.Stop();
updateTimer.Dispose();
updateTimer = null;
}
// Clean up the view // Clean up the view
MainView.ViewDestroy(); MainView.ViewDestroy();
MyHost = null; MyHost = null;
@ -60,9 +76,16 @@ namespace MosswartMassacre
if (IsKilledByMeMessage(e.Text)) if (IsKilledByMeMessage(e.Text))
{ {
totalKills++; totalKills++;
lastKillTime = DateTime.Now;
CalculateKillsPerInterval(); CalculateKillsPerInterval();
MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour); MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour);
} }
if (IsRareDiscoveryMessage(e.Text))
{
rareCount++;
MainView.UpdateRareCount(rareCount);
}
} }
catch (Exception ex) 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() private void CalculateKillsPerInterval()
{ {
// Calculate kills per 5 minutes double minutesElapsed = (DateTime.Now - statsStartTime).TotalMinutes;
var timeSinceLastKill = DateTime.Now - lastKillTime;
if (timeSinceLastKill.TotalMinutes > 0) if (minutesElapsed > 0)
{ {
killsPer5Min = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 5; killsPer5Min = (totalKills / minutesElapsed) * 5;
killsPerHour = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 60; killsPerHour = (totalKills / minutesElapsed) * 60;
} }
lastKillTime = DateTime.Now;
} }
private bool IsKilledByMeMessage(string text) private bool IsKilledByMeMessage(string text)
@ -132,7 +172,26 @@ namespace MosswartMassacre
return false; return false;
} }
private bool IsRareDiscoveryMessage(string text)
{
// Match pattern: "<name> has discovered the <something>!"
string pattern = @"^(?<name>['A-Za-z ]+)\s(?<text>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) public static void WriteToChat(string message)
{ {
MyHost.Actions.AddChatText("[Mosswart Massacre] " + message, 0, 1); MyHost.Actions.AddChatText("[Mosswart Massacre] " + message, 0, 1);

View file

@ -1,8 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<view icon="7735" title="Mosswart Massacre" width="300" height="270"> <view icon="7735" title="Mosswart Massacre" width="270" height="140">
<control progid="DecalControls.FixedLayout" clipped=""> <control progid="DecalControls.FixedLayout" clipped="">
<control progid="DecalControls.StaticText" name="lblTotalKills" left="10" top="10" width="280" height="18" text="Total Kills: 0"/> <control progid="DecalControls.StaticText" name="lblTotalKills" left="10" top="10" width="250" height="20" text="Total Kills: 0"/>
<control progid="DecalControls.StaticText" name="lblKillsPer5Min" left="10" top="30" width="280" height="18" text="Kills per 5 Min: 0"/> <control progid="DecalControls.StaticText" name="lblKillsPer5Min" left="10" top="30" width="250" height="20" text="Kills per 5 Min: 0"/>
<control progid="DecalControls.StaticText" name="lblKillsPerHour" left="10" top="50" width="280" height="18" text="Kills per Hour: 0"/> <control progid="DecalControls.StaticText" name="lblKillsPerHour" left="10" top="50" width="250" height="20" text="Kills per Hour: 0"/>
<control progid="DecalControls.StaticText" name="lblElapsedTime" left="10" top="70" width="250" height="20" text="Elapsed Time: 00:00:00"/>
<control progid="DecalControls.StaticText" name="lblRareCount" left="10" top="90" width="250" height="20" text="Rare Count: 0"/>
</control> </control>
</view> </view>