1 Commits
1.6.4 ... 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
2 changed files with 25 additions and 25 deletions

View File

@@ -28,7 +28,7 @@ public class MxValheimMod : BaseUnityPlugin
private const string ModGUID = "ovh.mxdev.mxvalheim"; private const string ModGUID = "ovh.mxdev.mxvalheim";
private const string ModName = "MxValheim"; private const string ModName = "MxValheim";
private const string ModVersion = "1.6.4"; private const string ModVersion = "1.6.5";
public static ConfigEntry<bool> Config_Locked; public static ConfigEntry<bool> Config_Locked;
public static ConfigEntry<int> Config_OreMultiplier; 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 internalConfigsPath = Path.Combine(modPath, "Configs");
public static string internalDataPath = Path.Combine(modPath, "Data"); public static string internalDataPath = Path.Combine(modPath, "Data");
public static string internalDataEventSystem = Path.Combine(internalDataPath, "EventSystem.json"); 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 WeightConfigPath => Path.Combine(internalConfigsPath, "items_weight.json");
public static string AutoDoorConfigPath => Path.Combine(internalConfigsPath, "auto_doors.json"); public static string AutoDoorConfigPath => Path.Combine(internalConfigsPath, "auto_doors.json");
public static DoorRoot CachedConfig; public static DoorRoot CachedConfig;
public static Dictionary<string, float> WeightSettings = new Dictionary<string, float>(); 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; public static bool initExpBar = true;
@@ -314,32 +316,34 @@ public class MxValheimMod : BaseUnityPlugin
} }
} }
private bool LoadJsonConfig() private void LoadJsonConfig()
{
try
{ {
string json = "";
if (!File.Exists(WeightConfigPath)) if (!File.Exists(WeightConfigPath))
{ {
WeightSettings = new Dictionary<string, float> { { "Wood", 1.0f }, { "Stone", 1.0f } }; WeightSettings = new Dictionary<string, float> { { "Wood", 1.0f }, { "Stone", 1.0f } };
File.WriteAllText(WeightConfigPath, JsonConvert.SerializeObject(WeightSettings, Newtonsoft.Json.Formatting.Indented)); 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); WeightSettings = JsonConvert.DeserializeObject<Dictionary<string, float>>(json);
Logger.LogInfo($"Successfully parsed {WeightSettings.Count} items."); Logger.LogInfo($"Successfully parsed {WeightSettings.Count} items.");
return true;
} if (!File.Exists(DropConfigPath))
catch (Exception ex)
{ {
Logger.LogWarning($"Could not read JSON (might be busy): {ex.Message}"); DropSettings = new Dictionary<string, int> { { "Wood", 3 }, { "CopperOre", 3 }, { "TinOre", 3 }, { "IronScrap", 3 }, { "SilverOre", 3 }, { "Obsidian", 3 }, { "BlackMetalScrap", 3 }, { "BlackMarble", 3 }, { "FlametalOreNew", 3 } };
return false; 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() public void LoadDoorConfig()
{ {
if (System.IO.File.Exists(AutoDoorConfigPath)) if (File.Exists(AutoDoorConfigPath))
{ {
string json = System.IO.File.ReadAllText(AutoDoorConfigPath); string json = System.IO.File.ReadAllText(AutoDoorConfigPath);
CachedConfig = JsonConvert.DeserializeObject<DoorRoot>(json); CachedConfig = JsonConvert.DeserializeObject<DoorRoot>(json);

View File

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