Add project files.

This commit is contained in:
erikn 2025-03-28 22:11:17 +01:00
parent 7e4909f545
commit b533681978
23 changed files with 7246 additions and 0 deletions

View file

@ -0,0 +1,141 @@
using System;
using System.Text.RegularExpressions;
using Decal.Adapter;
using Decal.Adapter.Wrappers;
namespace MosswartMassacre
{
[FriendlyName("Mosswart Massacre")]
public class PluginCore : PluginBase
{
internal static PluginHost MyHost;
internal static int totalKills = 0;
internal static DateTime lastKillTime = DateTime.Now;
internal static double killsPer5Min = 0;
internal static double killsPerHour = 0;
internal static DateTime statsStartTime = DateTime.Now;
protected override void Startup()
{
try
{
MyHost = Host;
WriteToChat("Mosswart Massacre has started!");
// Subscribe to chat message event
CoreManager.Current.ChatBoxMessage += new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
// Initialize the view (UI)
MainView.ViewInit();
}
catch (Exception ex)
{
WriteToChat("Error during startup: " + ex.Message);
}
}
protected override void Shutdown()
{
try
{
WriteToChat("Mosswart Massacre is shutting down...");
// Unsubscribe from chat message event
CoreManager.Current.ChatBoxMessage -= new EventHandler<ChatTextInterceptEventArgs>(OnChatText);
// Clean up the view
MainView.ViewDestroy();
MyHost = null;
}
catch (Exception ex)
{
WriteToChat("Error during shutdown: " + ex.Message);
}
}
private void OnChatText(object sender, ChatTextInterceptEventArgs e)
{
try
{
if (IsKilledByMeMessage(e.Text))
{
totalKills++;
CalculateKillsPerInterval();
MainView.UpdateKillStats(totalKills, killsPer5Min, killsPerHour);
}
}
catch (Exception ex)
{
WriteToChat("Error processing chat message: " + ex.Message);
}
}
private void CalculateKillsPerInterval()
{
// Calculate kills per 5 minutes
var timeSinceLastKill = DateTime.Now - lastKillTime;
if (timeSinceLastKill.TotalMinutes > 0)
{
killsPer5Min = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 5;
killsPerHour = (totalKills / (DateTime.Now - statsStartTime).TotalMinutes) * 60;
}
lastKillTime = DateTime.Now;
}
private bool IsKilledByMeMessage(string text)
{
string[] killPatterns = new string[]
{
@"^You flatten (?<targetname>.+)'s body with the force of your assault!$",
@"^You bring (?<targetname>.+) to a fiery end!$",
@"^You beat (?<targetname>.+) to a lifeless pulp!$",
@"^You smite (?<targetname>.+) mightily!$",
@"^You obliterate (?<targetname>.+)!$",
@"^You run (?<targetname>.+) through!$",
@"^You reduce (?<targetname>.+) to a sizzling, oozing mass!$",
@"^You knock (?<targetname>.+) into next Morningthaw!$",
@"^You split (?<targetname>.+) apart!$",
@"^You cleave (?<targetname>.+) in twain!$",
@"^You slay (?<targetname>.+) viciously enough to impart death several times over!$",
@"^You reduce (?<targetname>.+) to a drained, twisted corpse!$",
@"^Your killing blow nearly turns (?<targetname>.+) inside-out!$",
@"^Your attack stops (?<targetname>.+) cold!$",
@"^Your lightning coruscates over (?<targetname>.+)'s mortal remains!$",
@"^Your assault sends (?<targetname>.+) to an icy death!$",
@"^You killed (?<targetname>.+)!$",
@"^The thunder of crushing (?<targetname>.+) is followed by the deafening silence of death!$",
@"^The deadly force of your attack is so strong that (?<targetname>.+)'s ancestors feel it!$",
@"^(?<targetname>.+)'s seared corpse smolders before you!$",
@"^(?<targetname>.+) is reduced to cinders!$",
@"^(?<targetname>.+) is shattered by your assault!$",
@"^(?<targetname>.+) catches your attack, with dire consequences!$",
@"^(?<targetname>.+) is utterly destroyed by your attack!$",
@"^(?<targetname>.+) suffers a frozen fate!$",
@"^(?<targetname>.+)'s perforated corpse falls before you!$",
@"^(?<targetname>.+) is fatally punctured!$",
@"^(?<targetname>.+)'s death is preceded by a sharp, stabbing pain!$",
@"^(?<targetname>.+) is torn to ribbons by your assault!$",
@"^(?<targetname>.+) is liquified by your attack!$",
@"^(?<targetname>.+)'s last strength dissolves before you!$",
@"^Electricity tears (?<targetname>.+) apart!$",
@"^Blistered by lightning, (?<targetname>.+) falls!$",
@"^(?<targetname>.+)'s last strength withers before you!$",
@"^(?<targetname>.+) is dessicated by your attack!$",
@"^(?<targetname>.+) is incinerated by your assault!$"
};
foreach (string pattern in killPatterns)
{
if (Regex.IsMatch(text, pattern))
return true;
}
return false;
}
public static void WriteToChat(string message)
{
MyHost.Actions.AddChatText("[Mosswart Massacre] " + message, 0, 1);
}
}
}