Added setting metastate from plugin as well as !report
This commit is contained in:
parent
dceefc3335
commit
f66b15ac57
19 changed files with 1262 additions and 16 deletions
|
|
@ -1,4 +1,6 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Timers;
|
||||
using Decal.Adapter;
|
||||
|
|
@ -17,6 +19,10 @@ namespace MosswartMassacre
|
|||
internal static double killsPerHour = 0;
|
||||
internal static DateTime statsStartTime = DateTime.Now;
|
||||
internal static Timer updateTimer;
|
||||
internal static bool rareMetaEnabled = true;
|
||||
private static Queue<string> rareMessageQueue = new Queue<string>();
|
||||
private static DateTime _lastSent = DateTime.MinValue;
|
||||
private static readonly Queue<string> _chatQueue = new Queue<string>();
|
||||
|
||||
protected override void Startup()
|
||||
{
|
||||
|
|
@ -73,7 +79,7 @@ namespace MosswartMassacre
|
|||
{
|
||||
try
|
||||
{
|
||||
// WriteToChat($"[Debug] Chat Color: {e.Color}, Message: {e.Text}");
|
||||
// WriteToChat($"[Debug] Chat Color: {e.Color}, Message: {e.Text}");
|
||||
|
||||
if (IsKilledByMeMessage(e.Text))
|
||||
{
|
||||
|
|
@ -83,10 +89,40 @@ namespace MosswartMassacre
|
|||
MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour);
|
||||
}
|
||||
|
||||
if (IsRareDiscoveryMessage(e.Text))
|
||||
if (IsRareDiscoveryMessage(e.Text, out string rareText))
|
||||
{
|
||||
rareCount++;
|
||||
MainView.UpdateRareCount(rareCount);
|
||||
MainView.UpdateRareCount(rareCount);
|
||||
|
||||
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.Color == 18 && e.Text.EndsWith("!report\""))
|
||||
{
|
||||
|
|
@ -181,22 +217,18 @@ namespace MosswartMassacre
|
|||
|
||||
return false;
|
||||
}
|
||||
private bool IsRareDiscoveryMessage(string text)
|
||||
private bool IsRareDiscoveryMessage(string text, out string rareTextOnly)
|
||||
{
|
||||
rareTextOnly = null;
|
||||
|
||||
// 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)
|
||||
if (match.Success && match.Groups["name"].Value == CoreManager.Current.CharacterFilter.Name)
|
||||
{
|
||||
// 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;
|
||||
}
|
||||
rareTextOnly = match.Groups["text"].Value; // just "has discovered the Ancient Pickle!"
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
|
|
@ -217,5 +249,30 @@ namespace MosswartMassacre
|
|||
MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour);
|
||||
MainView.UpdateRareCount(rareCount);
|
||||
}
|
||||
[DllImport("Decal.dll")]
|
||||
private static extern int DispatchOnChatCommand(ref IntPtr str, [MarshalAs(UnmanagedType.U4)] int target);
|
||||
|
||||
public static bool Decal_DispatchOnChatCommand(string cmd)
|
||||
{
|
||||
IntPtr bstr = Marshal.StringToBSTR(cmd);
|
||||
|
||||
try
|
||||
{
|
||||
bool eaten = (DispatchOnChatCommand(ref bstr, 1) & 0x1) > 0;
|
||||
return eaten;
|
||||
}
|
||||
finally
|
||||
{
|
||||
Marshal.FreeBSTR(bstr);
|
||||
}
|
||||
}
|
||||
public static void DispatchChatToBoxWithPluginIntercept(string cmd)
|
||||
{
|
||||
if (!Decal_DispatchOnChatCommand(cmd))
|
||||
CoreManager.Current.Actions.InvokeChatParser(cmd);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue