From 6b70c79af7db4c1f237828e2ae9f2b7f8f24eaf9 Mon Sep 17 00:00:00 2001 From: mikx Date: Wed, 18 Feb 2026 05:27:13 -0500 Subject: [PATCH] (1.6.4) Managed RandomEvent Message --- MxValheim/EventSystem/Patch.cs | 72 +++++++++++++++++++++++++--------- MxValheim/KillFeed/Patch.cs | 18 +++++++-- MxValheim/MxValheim.cs | 13 ++++-- MxValheim/Patch/HUD/Clock.cs | 28 ++++++++++++- 4 files changed, 106 insertions(+), 25 deletions(-) diff --git a/MxValheim/EventSystem/Patch.cs b/MxValheim/EventSystem/Patch.cs index 7f24e22..888437d 100644 --- a/MxValheim/EventSystem/Patch.cs +++ b/MxValheim/EventSystem/Patch.cs @@ -28,12 +28,15 @@ namespace MxValheim.EventSystem } } - [HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.FixedUpdate))] + [HarmonyPatch(typeof(RandEventSystem), nameof(RandEventSystem.StartRandomEvent))] public static class DebugRaidFrequency { static void Prefix(RandEventSystem __instance) { - + if (ZRoutedRpc.instance != null) + { + ZRoutedRpc.instance.InvokeRoutedRPC(ZRoutedRpc.Everybody, "RPC_MxKillMsg", "", "", "", "", -1); + } } } @@ -78,34 +81,35 @@ namespace MxValheim.EventSystem Reward.GiveItemRandom(Reward.GetRewardPrefab(Profiles.serverLevel, "metal"), rand.Next(5, 20)); } } - } + } } } - /* [HarmonyPatch(typeof(Hud), nameof(Hud.Update))] - public static class Hud_MonitorPatch + public static class Hud_Update_Patch { - private static RandomEvent _lastKnownEvent = null; - - static void Postfix() + static void Postfix(Hud __instance) { - // 1. Safety check: Ensure the system exists - if (RandEventSystem.instance == null) return; + if (Player.m_localPlayer == null || !Hud.instance) return; - RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent(); - - // 2. Logic: Detection - if (activeEvent != null && _lastKnownEvent == null) + if (RandEventSystem.instance != null) { - + RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent(); + + if (activeEvent != null) + { + eventName = Localization.instance.Localize(activeEvent.GetHudText()); + } } - else if (activeEvent == null && _lastKnownEvent != null) - { + // Hiding the yellow persistent text at the top center + if (RandEventSystem.instance != null && RandEventSystem.instance.GetActiveEvent() != null) + { + // We set the text to an empty string so it doesn't render + __instance.m_eventName.text = ""; } } - }*/ + } [HarmonyPatch(typeof(Character), nameof(Character.ApplyDamage))] public static class DeathNotifier @@ -127,6 +131,14 @@ namespace MxValheim.EventSystem Vector3 playerPos = Player.m_localPlayer.transform.position; float distance = Vector3.Distance(playerPos, activeEvent.m_pos); + MonsterAI mai = __instance.GetComponent(); + bool isEventCreature = false; + if (mai != null) + { + isEventCreature = Traverse.Create(mai).Field("m_eventCreature").Value; + } + Debug.Log($"EventSystem: Event Enemy {nview.GetZDO().GetBool(ZDOVars.s_eventCreature, isEventCreature)}"); + if (distance <= 96f) { int level = __instance.GetLevel(); @@ -143,5 +155,29 @@ namespace MxValheim.EventSystem } } } + + [HarmonyPatch(typeof(Character), nameof(Character.ApplyDamage))] + public static class DeathNotifierEvent + { + static void Postfix(Character __instance) + { + // Check if the character is dead or just died + if (__instance.GetHealth() <= 0f) + { + ZNetView nview = __instance.GetComponent(); + + // This check should now pass because ApplyDamage happens before the object is invalidated + if (nview == null || !nview.IsValid() || !nview.IsOwner()) return; + + MonsterAI mai = __instance.GetComponent(); + bool isEventCreature = false; + if (mai != null) + { + isEventCreature = Traverse.Create(mai).Field("m_eventCreature").Value; + } + Debug.Log($"EventSystem: Event Enemy {nview.GetZDO().GetBool(ZDOVars.s_eventCreature, isEventCreature)}"); + } + } + } } } diff --git a/MxValheim/KillFeed/Patch.cs b/MxValheim/KillFeed/Patch.cs index 682bc20..4dd6619 100644 --- a/MxValheim/KillFeed/Patch.cs +++ b/MxValheim/KillFeed/Patch.cs @@ -102,6 +102,8 @@ namespace MxValheim.KillFeed // Message Format Variables string type1Separator = Localization.instance.Localize("$killfeed_format_type1"); string type2Separator = Localization.instance.Localize("$killfeed_format_type2"); + string type3Separator = Localization.instance.Localize("$killfeed_format_type3"); + string eventFormat = $"{victim}"; string finalMsg = ""; string attackerFormat = ""; string victimFormat = ""; @@ -141,10 +143,16 @@ namespace MxValheim.KillFeed distanceFormat = $"{Localization.instance.Localize("$killfeed_format_distance_before")}{distance:F1}m{Localization.instance.Localize("$killfeed_format_distance_after")}"; finalMsg = - (type == 1) ? $"{victimFormat}{type1Separator}{attackerFormat}{distanceFormat}": // Player Death - (type == 2) ? $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}": // Player Killed Something + (type == 1) ? $"{victimFormat}{type1Separator}{attackerFormat}{distanceFormat}" : // Player Death + (type == 2) ? $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}" : // Player Killed Something $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}"; // Failsafe + if (encodedType == -1) + { + attacker = Player.m_localPlayer?.GetHoverName(); + finalMsg = $"{attacker.ToUpper()}{type3Separator}"; + } + Sprite weaponIcon = null; if (ObjectDB.instance != null && !string.IsNullOrEmpty(weaponPrefab)) @@ -178,8 +186,12 @@ namespace MxValheim.KillFeed { borderColor = new Color(0.141f, 0.141f, 0.153f); } + if (encodedType == -1) + { + borderColor = new Color(0.0196f, 0.250f, 0.00750f); + } - lock (_msgQueue) + lock (_msgQueue) { _msgQueue.Enqueue(finalMsg); _biomeIconQueue.Enqueue(biomeSprite); diff --git a/MxValheim/MxValheim.cs b/MxValheim/MxValheim.cs index 9f7a345..3d6ce4f 100644 --- a/MxValheim/MxValheim.cs +++ b/MxValheim/MxValheim.cs @@ -28,7 +28,7 @@ public class MxValheimMod : BaseUnityPlugin private const string ModGUID = "ovh.mxdev.mxvalheim"; private const string ModName = "MxValheim"; - private const string ModVersion = "1.6.3"; + private const string ModVersion = "1.6.4"; public static ConfigEntry Config_Locked; public static ConfigEntry Config_OreMultiplier; @@ -83,7 +83,7 @@ public class MxValheimMod : BaseUnityPlugin public static readonly Queue _doorQueueName = new Queue(); public static float _doorTimer; - public static readonly Queue _serverEvent = new Queue(); + public static string eventName; void Awake() { @@ -191,7 +191,14 @@ public class MxValheimMod : BaseUnityPlugin string timeString = clk.GetFormattedTime(); int day = EnvMan.instance.GetDay(); string pid = GetUserPlayerID(Player.m_localPlayer).ToString(); - Clock.m_textComponent.text = $"{Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel} | {Localization.instance.Localize("$clock_string_day")} {day} | {timeString}"; + RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent(); + if ((activeEvent == null)) + { + Clock.m_textComponent.text = $"{Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel} | {Localization.instance.Localize("$clock_string_day")} {day} | {timeString}"; + } else + { + Clock.m_textComponent.text = $"{eventName} | {Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel} | {Localization.instance.Localize("$clock_string_day")} {day} | {timeString}"; + } } } diff --git a/MxValheim/Patch/HUD/Clock.cs b/MxValheim/Patch/HUD/Clock.cs index bee2457..dbe84db 100644 --- a/MxValheim/Patch/HUD/Clock.cs +++ b/MxValheim/Patch/HUD/Clock.cs @@ -1,4 +1,5 @@ -using System; +using HarmonyLib; +using System; using System.Collections.Generic; using System.Linq; using System.Text; @@ -28,6 +29,31 @@ namespace MxValheim.Patch.HUD return $"{hours:00}:{minutes:00}"; } + [HarmonyPatch(typeof(MessageHud), nameof(MessageHud.ShowMessage))] + public static class HideEventMessage_Patch + { + // We use a Prefix to check the message before it is displayed + static bool Prefix(MessageHud.MessageType type, string text) + { + // Check if a raid is active + if (RandEventSystem.instance != null) + { + RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent(); + if (activeEvent != null) + { + // If the message text matches the start or end message of the raid, block it + if (text == activeEvent.GetHudText()) + { + Debug.Log("Reached msg logic!!!"); + // Returning false tells Harmony to skip the original method (don't show text) + return false; + } + } + } + return true; // Show all other messages (health, items, etc.) normally + } + } + public void CreateOverlay() { m_canvasObject = new GameObject("ModdedCanvas");