(1.6.4) Managed RandomEvent Message

This commit is contained in:
mikx
2026-02-18 05:27:13 -05:00
parent ad5387d6eb
commit 6b70c79af7
4 changed files with 106 additions and 25 deletions

View File

@@ -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);
}
}
}
@@ -82,30 +85,31 @@ namespace MxValheim.EventSystem
}
}
/*
[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;
if (RandEventSystem.instance != null)
{
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
// 2. Logic: Detection
if (activeEvent != null && _lastKnownEvent == null)
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<MonsterAI>();
bool isEventCreature = false;
if (mai != null)
{
isEventCreature = Traverse.Create(mai).Field<bool>("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<ZNetView>();
// 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<MonsterAI>();
bool isEventCreature = false;
if (mai != null)
{
isEventCreature = Traverse.Create(mai).Field<bool>("m_eventCreature").Value;
}
Debug.Log($"EventSystem: Event Enemy {nview.GetZDO().GetBool(ZDOVars.s_eventCreature, isEventCreature)}");
}
}
}
}
}

View File

@@ -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 = $"<color=#00ff06>{victim}</color>";
string finalMsg = "";
string attackerFormat = "";
string victimFormat = "";
@@ -145,6 +147,12 @@ namespace MxValheim.KillFeed
(type == 2) ? $"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}" : // Player Killed Something
$"{attackerFormat}{type2Separator}{victimFormat}{distanceFormat}"; // Failsafe
if (encodedType == -1)
{
attacker = Player.m_localPlayer?.GetHoverName();
finalMsg = $"<color=#00ff06>{attacker.ToUpper()}</color><color=#ffd000>{type3Separator}</color>";
}
Sprite weaponIcon = null;
if (ObjectDB.instance != null && !string.IsNullOrEmpty(weaponPrefab))
@@ -178,6 +186,10 @@ 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)
{

View File

@@ -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<bool> Config_Locked;
public static ConfigEntry<int> Config_OreMultiplier;
@@ -83,7 +83,7 @@ public class MxValheimMod : BaseUnityPlugin
public static readonly Queue<string> _doorQueueName = new Queue<string>();
public static float _doorTimer;
public static readonly Queue<RandomEvent> _serverEvent = new Queue<RandomEvent>();
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();
RandomEvent activeEvent = RandEventSystem.instance.GetActiveEvent();
if ((activeEvent == null))
{
Clock.m_textComponent.text = $"<color=#32a852>{Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_day")} {day}</color> <color=#677074>|</color> <color=#d1954a>{timeString}</color>";
} else
{
Clock.m_textComponent.text = $"<color=#ffd000>{eventName}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_rank")} {Profiles.serverLevel}</color> <color=#677074>|</color> <color=#32a852>{Localization.instance.Localize("$clock_string_day")} {day}</color> <color=#677074>|</color> <color=#d1954a>{timeString}</color>";
}
}
}

View File

@@ -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");