Compare commits
2 commits
a41867fbb3
...
e5c033c9ed
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e5c033c9ed | ||
|
|
dcfa888f61 |
3 changed files with 84 additions and 10 deletions
|
|
@ -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}";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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<ChatTextInterceptEventArgs>(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<ChatTextInterceptEventArgs>(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: "<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)
|
||||
{
|
||||
MyHost.Actions.AddChatText("[Mosswart Massacre] " + message, 0, 1);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,10 @@
|
|||
<?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.StaticText" name="lblTotalKills" left="10" top="10" width="280" height="18" 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="lblKillsPerHour" left="10" top="50" width="280" height="18" text="Kills per Hour: 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="250" height="20" text="Kills per 5 Min: 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>
|
||||
</view>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue