2 Commits
1.6.3 ... 1.6.5

Author SHA1 Message Date
mikx
90bb020a44 (1.6.5) Item Drops Settings from Json 2026-02-18 17:20:30 -05:00
mikx
6b70c79af7 (1.6.4) Managed RandomEvent Message 2026-02-18 05:27:13 -05:00
5 changed files with 130 additions and 49 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 = "";
@@ -141,10 +143,16 @@ namespace MxValheim.KillFeed
distanceFormat = $"{Localization.instance.Localize("$killfeed_format_distance_before")}<color=#9402f5>{distance:F1}m</color>{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 = $"<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.5";
public static ConfigEntry<bool> Config_Locked;
public static ConfigEntry<int> Config_OreMultiplier;
@@ -43,10 +43,12 @@ public class MxValheimMod : BaseUnityPlugin
public static string internalConfigsPath = Path.Combine(modPath, "Configs");
public static string internalDataPath = Path.Combine(modPath, "Data");
public static string internalDataEventSystem = Path.Combine(internalDataPath, "EventSystem.json");
public static string DropConfigPath => Path.Combine(internalConfigsPath, "items_drop.json");
public static string WeightConfigPath => Path.Combine(internalConfigsPath, "items_weight.json");
public static string AutoDoorConfigPath => Path.Combine(internalConfigsPath, "auto_doors.json");
public static DoorRoot CachedConfig;
public static Dictionary<string, float> WeightSettings = new Dictionary<string, float>();
public static Dictionary<string, int> DropSettings = new Dictionary<string, int>();
public static bool initExpBar = true;
@@ -83,7 +85,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 +193,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>";
}
}
}
@@ -307,32 +316,34 @@ public class MxValheimMod : BaseUnityPlugin
}
}
private bool LoadJsonConfig()
{
try
private void LoadJsonConfig()
{
string json = "";
if (!File.Exists(WeightConfigPath))
{
WeightSettings = new Dictionary<string, float> { { "Wood", 1.0f }, { "Stone", 1.0f } };
File.WriteAllText(WeightConfigPath, JsonConvert.SerializeObject(WeightSettings, Newtonsoft.Json.Formatting.Indented));
return true;
}
string json = File.ReadAllText(WeightConfigPath);
json = File.ReadAllText(WeightConfigPath);
WeightSettings = JsonConvert.DeserializeObject<Dictionary<string, float>>(json);
Logger.LogInfo($"Successfully parsed {WeightSettings.Count} items.");
return true;
}
catch (Exception ex)
if (!File.Exists(DropConfigPath))
{
Logger.LogWarning($"Could not read JSON (might be busy): {ex.Message}");
return false;
DropSettings = new Dictionary<string, int> { { "Wood", 3 }, { "CopperOre", 3 }, { "TinOre", 3 }, { "IronScrap", 3 }, { "SilverOre", 3 }, { "Obsidian", 3 }, { "BlackMetalScrap", 3 }, { "BlackMarble", 3 }, { "FlametalOreNew", 3 } };
File.WriteAllText(DropConfigPath, JsonConvert.SerializeObject(DropSettings, Newtonsoft.Json.Formatting.Indented));
}
json = File.ReadAllText(DropConfigPath);
DropSettings = JsonConvert.DeserializeObject<Dictionary<string, int>>(json);
Logger.LogInfo($"Successfully parsed {DropSettings.Count} items.");
}
public void LoadDoorConfig()
{
if (System.IO.File.Exists(AutoDoorConfigPath))
if (File.Exists(AutoDoorConfigPath))
{
string json = System.IO.File.ReadAllText(AutoDoorConfigPath);
CachedConfig = JsonConvert.DeserializeObject<DoorRoot>(json);

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

View File

@@ -14,17 +14,13 @@ namespace MxValheim.Patch
{
if (__result == null || __result.Count == 0) return;
int countToAdd = MxValheimMod.Config_OreMultiplier.Value - 1;
if (countToAdd <= 0) return;
List<GameObject> extraDrops = new List<GameObject>();
foreach (var item in __result)
{
string name = item.name.ToLower();
if (name.Contains("ore") || name.Contains("scrap"))
if (item != null && MxValheimMod.DropSettings.TryGetValue(item.name, out int newDropMulti))
{
for (int i = 0; i < countToAdd; i++)
for (int i = 0; i < newDropMulti; i++)
{
extraDrops.Add(item);
}