More mossawarts
This commit is contained in:
parent
b533681978
commit
dcfa888f61
3 changed files with 84 additions and 10 deletions
|
|
@ -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);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue