(1.6.5) Item Drops Settings from Json
This commit is contained in:
@@ -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.4";
|
||||
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;
|
||||
|
||||
@@ -314,32 +316,34 @@ public class MxValheimMod : BaseUnityPlugin
|
||||
}
|
||||
}
|
||||
|
||||
private bool LoadJsonConfig()
|
||||
private void LoadJsonConfig()
|
||||
{
|
||||
try
|
||||
{
|
||||
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 = "";
|
||||
|
||||
string 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(WeightConfigPath))
|
||||
{
|
||||
Logger.LogWarning($"Could not read JSON (might be busy): {ex.Message}");
|
||||
return false;
|
||||
WeightSettings = new Dictionary<string, float> { { "Wood", 1.0f }, { "Stone", 1.0f } };
|
||||
File.WriteAllText(WeightConfigPath, JsonConvert.SerializeObject(WeightSettings, Newtonsoft.Json.Formatting.Indented));
|
||||
}
|
||||
|
||||
json = File.ReadAllText(WeightConfigPath);
|
||||
WeightSettings = JsonConvert.DeserializeObject<Dictionary<string, float>>(json);
|
||||
Logger.LogInfo($"Successfully parsed {WeightSettings.Count} items.");
|
||||
|
||||
if (!File.Exists(DropConfigPath))
|
||||
{
|
||||
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);
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user