From f4ec57a44d0bb7cab7ea916e096d2a375b83cda1 Mon Sep 17 00:00:00 2001 From: erik Date: Thu, 15 May 2025 21:34:20 +0200 Subject: [PATCH] Fixed inventory, spawn and settings --- MosswartMassacre/MosswartMassacre.csproj | 15 +++++++++- MosswartMassacre/MossyInventory.cs | 18 +++++++----- MosswartMassacre/PluginCore.cs | 36 ++++++------------------ MosswartMassacre/PluginSettings.cs | 15 ++++++++-- MosswartMassacre/app.config | 4 +++ 5 files changed, 51 insertions(+), 37 deletions(-) diff --git a/MosswartMassacre/MosswartMassacre.csproj b/MosswartMassacre/MosswartMassacre.csproj index f64cbb0..9dca846 100644 --- a/MosswartMassacre/MosswartMassacre.csproj +++ b/MosswartMassacre/MosswartMassacre.csproj @@ -41,6 +41,18 @@ ..\..\..\..\..\..\Program Files (x86)\Decal 3.0\Decal.FileService.dll + + False + False + ..\..\..\..\..\..\Program Files (x86)\Decal 3.0\.NET 4.0 PIA\Decal.Interop.Core.DLL + False + + + False + False + ..\..\..\..\..\..\Program Files (x86)\Decal 3.0\.NET 4.0 PIA\Decal.Interop.Filters.DLL + False + False False @@ -53,6 +65,7 @@ + @@ -181,7 +194,7 @@ 0 primary False - True + False {572B87C4-93BD-46B3-A291-CD58181D25DC} diff --git a/MosswartMassacre/MossyInventory.cs b/MosswartMassacre/MossyInventory.cs index f29d13d..f217cb9 100644 --- a/MosswartMassacre/MossyInventory.cs +++ b/MosswartMassacre/MossyInventory.cs @@ -19,21 +19,25 @@ namespace MosswartMassacre { get { - // 1) grab your character name + // 1) Character name var characterName = CoreManager.Current.CharacterFilter.Name; - // 2) grab the folder where your plugin dll is running + // 2) Plugin folder var pluginFolder = Path.GetDirectoryName( System.Reflection.Assembly .GetExecutingAssembly() .Location ); - // 3) combine into a full path with .json - return Path.Combine( - pluginFolder, - $"{characterName}.json" - ); + // 3) Character-specific folder path + var characterFolder = Path.Combine(pluginFolder, characterName); + + // 4) Ensure directory exists (can do it here, thread-safe for most single-user plugin cases) + if (!Directory.Exists(characterFolder)) + Directory.CreateDirectory(characterFolder); + + // 5) Return full path to the .json file inside the character folder + return Path.Combine(characterFolder, $"{characterName}.json"); } } diff --git a/MosswartMassacre/PluginCore.cs b/MosswartMassacre/PluginCore.cs index cbc3c57..5c1b254 100644 --- a/MosswartMassacre/PluginCore.cs +++ b/MosswartMassacre/PluginCore.cs @@ -1,11 +1,13 @@ using System; using System.Collections.Generic; +using System.Drawing; using System.Globalization; using System.Linq; using System.Net; using System.Runtime.InteropServices; using System.Text; using System.Text.RegularExpressions; +using System.Threading.Tasks; using System.Timers; using Decal.Adapter; using Decal.Adapter.Wrappers; @@ -30,7 +32,6 @@ namespace MosswartMassacre public static bool TelemetryEnabled { get; set; } = false; public bool WebSocketEnabled { get; set; } = false; public bool InventoryLogEnabled { get; set; } = false; - private MossyInventory _inventoryLogger; private static Queue rareMessageQueue = new Queue(); @@ -44,7 +45,6 @@ namespace MosswartMassacre MyHost = Host; WriteToChat("Mosswart Massacre has started!"); - // Subscribe to chat message event CoreManager.Current.ChatBoxMessage += new EventHandler(OnChatText); CoreManager.Current.ChatBoxMessage += new EventHandler(AllChatText); @@ -53,6 +53,7 @@ namespace MosswartMassacre CoreManager.Current.WorldFilter.CreateObject += OnSpawn; CoreManager.Current.WorldFilter.ReleaseObject += OnDespawn; + // Initialize the timer updateTimer = new Timer(1000); // Update every second updateTimer.Elapsed += UpdateStats; @@ -94,6 +95,7 @@ namespace MosswartMassacre CoreManager.Current.ChatBoxMessage -= new EventHandler(AllChatText); CoreManager.Current.WorldFilter.CreateObject -= OnSpawn; CoreManager.Current.WorldFilter.ReleaseObject -= OnDespawn; + // Stop and dispose of the timer if (updateTimer != null) @@ -138,10 +140,11 @@ namespace MosswartMassacre Telemetry.Start(); if (WebSocketEnabled) WebSocket.Start(); - - + } + + private async void OnSpawn(object sender, CreateObjectEventArgs e) { var mob = e.New; @@ -235,29 +238,7 @@ namespace MosswartMassacre 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\"")) { TimeSpan elapsed = DateTime.Now - statsStartTime; @@ -540,6 +521,7 @@ namespace MosswartMassacre WriteToChat("/mm http - Local http-command server enable|disable"); WriteToChat("/mm remotecommand - Listen to allegiance !do/!dot enable|disable"); WriteToChat("/mm getmetastate - Gets the current metastate"); + break; case "report": diff --git a/MosswartMassacre/PluginSettings.cs b/MosswartMassacre/PluginSettings.cs index 327dedc..0a7a9e5 100644 --- a/MosswartMassacre/PluginSettings.cs +++ b/MosswartMassacre/PluginSettings.cs @@ -26,10 +26,21 @@ namespace MosswartMassacre public static void Initialize() { - // determine settings file path + // determine plugin folder and character-specific folder string characterName = CoreManager.Current.CharacterFilter.Name; string pluginFolder = Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); - _filePath = Path.Combine(pluginFolder, $"{characterName}.yaml"); + + // Path for character-specific folder + string characterFolder = Path.Combine(pluginFolder, characterName); + + // Create the character folder if it doesn't exist + if (!Directory.Exists(characterFolder)) + { + Directory.CreateDirectory(characterFolder); + } + + // YAML file is now in the character-specific folder + _filePath = Path.Combine(characterFolder, $"{characterName}.yaml"); // build serializer/deserializer once var builder = new DeserializerBuilder() diff --git a/MosswartMassacre/app.config b/MosswartMassacre/app.config index 7237d3b..57fee1b 100644 --- a/MosswartMassacre/app.config +++ b/MosswartMassacre/app.config @@ -14,6 +14,10 @@ + + + + \ No newline at end of file