Fixed time reporting, added /mm
This commit is contained in:
parent
360a8365d2
commit
201cf96629
4 changed files with 109 additions and 34 deletions
|
|
@ -19,7 +19,7 @@ namespace MosswartMassacre
|
|||
internal static double killsPerHour = 0;
|
||||
internal static DateTime statsStartTime = DateTime.Now;
|
||||
internal static Timer updateTimer;
|
||||
internal static bool rareMetaEnabled = true;
|
||||
public static bool RareMetaEnabled { get; private set; } = true;
|
||||
private static Queue<string> rareMessageQueue = new Queue<string>();
|
||||
private static DateTime _lastSent = DateTime.MinValue;
|
||||
private static readonly Queue<string> _chatQueue = new Queue<string>();
|
||||
|
|
@ -33,6 +33,7 @@ namespace MosswartMassacre
|
|||
|
||||
// Subscribe to chat message event
|
||||
CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
|
||||
CoreManager.Current.CommandLineText += OnChatCommand;
|
||||
|
||||
// Initialize the timer
|
||||
updateTimer = new Timer(1000); // Update every second
|
||||
|
|
@ -56,6 +57,7 @@ namespace MosswartMassacre
|
|||
|
||||
// Unsubscribe from chat message event
|
||||
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
|
||||
CoreManager.Current.CommandLineText -= OnChatCommand;
|
||||
|
||||
// Stop and dispose of the timer
|
||||
if (updateTimer != null)
|
||||
|
|
@ -94,36 +96,36 @@ namespace MosswartMassacre
|
|||
rareCount++;
|
||||
MainView.UpdateRareCount(rareCount);
|
||||
|
||||
if (rareMetaEnabled)
|
||||
if (RareMetaEnabled)
|
||||
{
|
||||
Decal_DispatchOnChatCommand("/vt setmetastate loot_rare");
|
||||
}
|
||||
|
||||
DelayedCommandManager.AddDelayedCommand($"/a {rareText}", 3000);
|
||||
}
|
||||
if (e.Text.EndsWith("!testrare\""))
|
||||
{
|
||||
string simulatedText = $"{CoreManager.Current.CharacterFilter.Name} has discovered the Ancient Pickle!";
|
||||
|
||||
if (IsRareDiscoveryMessage(simulatedText, out string simulatedRareText))
|
||||
{
|
||||
rareCount++;
|
||||
MainView.UpdateRareCount(rareCount);
|
||||
|
||||
if (rareMetaEnabled)
|
||||
{
|
||||
Decal_DispatchOnChatCommand("/vt setmetastate loot_rare");
|
||||
}
|
||||
|
||||
DelayedCommandManager.AddDelayedCommand($"/a {simulatedRareText}", 3000);
|
||||
}
|
||||
else
|
||||
{
|
||||
WriteToChat("[Test] Simulated rare message didn't match the regex.");
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
// if (e.Text.EndsWith("!testrare\""))
|
||||
// {
|
||||
// string simulatedText = $"{CoreManager.Current.CharacterFilter.Name} has discovered the Ancient Pickle!";
|
||||
//
|
||||
// if (IsRareDiscoveryMessage(simulatedText, out string simulatedRareText))
|
||||
// {
|
||||
// rareCount++;
|
||||
// MainView.UpdateRareCount(rareCount);
|
||||
//
|
||||
// if (RareMetaEnabled)
|
||||
// {
|
||||
// Decal_DispatchOnChatCommand("/vt setmetastate loot_rare");
|
||||
// }
|
||||
//
|
||||
// DelayedCommandManager.AddDelayedCommand($"/a {simulatedRareText}", 3000);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// WriteToChat("[Test] Simulated rare message didn't match the regex.");
|
||||
// }
|
||||
//
|
||||
// return;
|
||||
// }
|
||||
if (e.Color == 18 && e.Text.EndsWith("!report\""))
|
||||
{
|
||||
TimeSpan elapsed = DateTime.Now - statsStartTime;
|
||||
|
|
@ -137,6 +139,21 @@ namespace MosswartMassacre
|
|||
WriteToChat("Error processing chat message: " + ex.Message);
|
||||
}
|
||||
}
|
||||
private void OnChatCommand(object sender, ChatParserInterceptEventArgs e)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (e.Text.StartsWith("/mm", StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
e.Eat = true; // Prevent the message from showing in chat
|
||||
HandleMmCommand(e.Text);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
PluginCore.WriteToChat($"[Error] Failed to process /mm command: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateStats(object sender, ElapsedEventArgs e)
|
||||
{
|
||||
|
|
@ -249,6 +266,12 @@ namespace MosswartMassacre
|
|||
MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour);
|
||||
MainView.UpdateRareCount(rareCount);
|
||||
}
|
||||
public static void ToggleRareMeta()
|
||||
{
|
||||
RareMetaEnabled = !RareMetaEnabled;
|
||||
MainView.SetRareMetaToggleState(RareMetaEnabled);
|
||||
}
|
||||
|
||||
[DllImport("Decal.dll")]
|
||||
private static extern int DispatchOnChatCommand(ref IntPtr str, [MarshalAs(UnmanagedType.U4)] int target);
|
||||
|
||||
|
|
@ -271,6 +294,50 @@ namespace MosswartMassacre
|
|||
if (!Decal_DispatchOnChatCommand(cmd))
|
||||
CoreManager.Current.Actions.InvokeChatParser(cmd);
|
||||
}
|
||||
private void HandleMmCommand(string text)
|
||||
{
|
||||
// Remove the /mm prefix and trim extra whitespace
|
||||
string[] args = text.Substring(3).Trim().Split(' ');
|
||||
|
||||
if (args.Length == 0 || string.IsNullOrEmpty(args[0]))
|
||||
{
|
||||
WriteToChat("Usage: /mm <command>. Try /mm help");
|
||||
return;
|
||||
}
|
||||
|
||||
string subCommand = args[0].ToLower();
|
||||
|
||||
switch (subCommand)
|
||||
{
|
||||
case "help":
|
||||
WriteToChat("Mosswart Massacre Commands:");
|
||||
WriteToChat("/mm report - Show current stats");
|
||||
WriteToChat("/mm reset - Reset all counters");
|
||||
WriteToChat("/mm meta - Toggle rare meta state");
|
||||
break;
|
||||
|
||||
case "report":
|
||||
TimeSpan elapsed = DateTime.Now - statsStartTime;
|
||||
string reportMessage = $"Total Kills: {totalKills}, Kills per Hour: {killsPerHour:F2}, Elapsed Time: {elapsed:dd\\.hh\\:mm\\:ss}, Rares Found: {rareCount}";
|
||||
WriteToChat(reportMessage);
|
||||
break;
|
||||
|
||||
case "reset":
|
||||
RestartStats();
|
||||
break;
|
||||
|
||||
case "meta":
|
||||
RareMetaEnabled = !RareMetaEnabled;
|
||||
WriteToChat($"Rare meta state is now {(RareMetaEnabled ? "ON" : "OFF")}");
|
||||
MainView.SetRareMetaToggleState(RareMetaEnabled); // <-- sync the UI
|
||||
break;
|
||||
|
||||
default:
|
||||
WriteToChat($"Unknown /mm command: {subCommand}. Try /mm help");
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue