diff --git a/mod.json b/mod.json index 09e86ed8..a4a7c973 100644 --- a/mod.json +++ b/mod.json @@ -1,7 +1,7 @@ { "Name": "Mission Control", "Enabled": true, - "Version": "1.2.0", + "Version": "1.2.1", "Description": "A HBS BattleTech mod that adds custom contract types and varies the encounter specifics such as encounter boundary size, spawn locations, lance numbers and objectives", "Author": "CWolf", "Contact": "cwolfs@gmail.com", diff --git a/settings.json b/settings.json index 98e6b6e2..cfccffce 100644 --- a/settings.json +++ b/settings.json @@ -128,5 +128,11 @@ "MinBuffer": 100, "MaxBuffer": 200 } + }, + "Misc": { + "LanceSelectionDivergenceOverride": { + "Enable": true, + "Divergence": 20 + } } } diff --git a/src/Core/MissionControl.cs b/src/Core/MissionControl.cs index 4d0e981c..9fc08b3f 100644 --- a/src/Core/MissionControl.cs +++ b/src/Core/MissionControl.cs @@ -267,6 +267,8 @@ public void SetContractSettingsOverride() { string contractId = CurrentContract.Override.ID; string type = IsAnyFlashpointContract() ? "flashpoint" : "contract"; + if (contractId == null || contractId == "") Main.Logger.LogError($"[MissionControl] [SetContractSettingsOverride] 'contractId' is null or empty string. This indicates a badly created or corrupt contract override."); + if (Main.Settings.ContractSettingsOverrides.ContainsKey(contractId)) { Main.Logger.Log($"[MissionControl] Setting a {type} MC settings override for '{contractId}'."); Main.Settings.ActiveContractSettings = Main.Settings.ContractSettingsOverrides[contractId]; @@ -481,8 +483,13 @@ public bool IsAnyFlashpointContract() { public bool IsInActiveFlashpointContract() { if (IsSkirmish()) return false; + if (CurrentContract == null) { + Main.Logger.LogError("[IsInActiveFlashpointContract] MC's CurrentContract is null. This is a possible mod conflict or a cascade error causing the CurrentContract never to be assigned in MC."); + return false; + } - return UnityGameInstance.BattleTechGame.Simulation.ActiveFlashpoint?.ActiveContract.encounterObjectGuid == this.CurrentContract.encounterObjectGuid; + Flashpoint activeFlashpoint = UnityGameInstance.BattleTechGame.Simulation.ActiveFlashpoint; + return activeFlashpoint?.ActiveContract?.encounterObjectGuid == this.CurrentContract.encounterObjectGuid; } public bool IsAnyStoryContract() { diff --git a/src/Core/Settings/Ai/FollowAiSettings.cs b/src/Core/Settings/Ai/FollowAiSettings.cs index 748a850d..a2d2878f 100644 --- a/src/Core/Settings/Ai/FollowAiSettings.cs +++ b/src/Core/Settings/Ai/FollowAiSettings.cs @@ -8,7 +8,7 @@ public class FollowAiSettings { public string Pathfinding { get; set; } = "Alternative"; // Original, Alternative [JsonProperty("Target")] - public string Target { get; set; } = "HeaviestMech"; // HeaviestMech, FirstLanceMember + public string Target { get; set; } = "HeaviestMech"; // HeaviestMech, LanceOrder [JsonProperty("StopWhen")] public string StopWhen { get; set; } = "OnEnemyDetected"; // OnEnemyDetected, OnEnemyVisible, WhenNotNeeded diff --git a/src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs b/src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs new file mode 100644 index 00000000..f5bb9999 --- /dev/null +++ b/src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs @@ -0,0 +1,11 @@ +using Newtonsoft.Json; + +namespace MissionControl.Config { + public class LanceSelectionDivergenceOverride { + [JsonProperty("Enable")] + public bool Enable { get; set; } = true; + + [JsonProperty("Divergence")] + public int Divergence { get; set; } = 20; + } +} \ No newline at end of file diff --git a/src/Core/Settings/MiscSettings.cs b/src/Core/Settings/MiscSettings.cs new file mode 100644 index 00000000..965e384f --- /dev/null +++ b/src/Core/Settings/MiscSettings.cs @@ -0,0 +1,8 @@ +using Newtonsoft.Json; + +namespace MissionControl.Config { + public class MiscSettings { + [JsonProperty("LanceSelectionDivergenceOverride")] + public LanceSelectionDivergenceOverride LanceSelectionDivergenceOverride { get; set; } = new LanceSelectionDivergenceOverride(); + } +} \ No newline at end of file diff --git a/src/Core/Settings/Settings.cs b/src/Core/Settings/Settings.cs index 4597649a..f444c459 100644 --- a/src/Core/Settings/Settings.cs +++ b/src/Core/Settings/Settings.cs @@ -36,7 +36,7 @@ public class Settings { [JsonProperty("NeverFailSimGameInFlashpoints")] public bool NeverFailSimGameInFlashpoints { get; set; } = true; - + [JsonProperty("EnableStoryOverrides")] public bool EnableStoryOverrides { get; set; } = false; @@ -75,6 +75,9 @@ public class Settings { [JsonProperty("Spawners")] public SpawnerSettings Spawners { get; set; } = new SpawnerSettings(); + [JsonProperty("Misc")] + public MiscSettings Misc { get; set; } = new MiscSettings(); + public Dictionary ContractSettingsOverrides = new Dictionary(); public ContractSettingsOverrides ActiveContractSettings { get; set; } diff --git a/src/Core/Settings/SettingsOverride.cs b/src/Core/Settings/SettingsOverride.cs index f2568a6b..f607b6c5 100644 --- a/src/Core/Settings/SettingsOverride.cs +++ b/src/Core/Settings/SettingsOverride.cs @@ -107,6 +107,9 @@ public class SettingsOverride { public static string Spawners_SpawnLanceAtEdgeBoundary_MinBuffer = "Spawners.SpawnLanceAtEdgeBoundary.MinBuffer"; public static string Spawners_SpawnLanceAtEdgeBoundary_MaxBuffer = "Spawners.SpawnLanceAtEdgeBoundary.MaxBuffer"; + public static string Misc_LanceSelectionDivergenceOverride_Enable = "Misc.LanceSelectionDivergenceOverride.Enable"; + public static string Misc_LanceSelectionDivergenceOverride_Divergence = "Misc.LanceSelectionDivergenceOverride.Divergence"; + public static string AdditionalPlayerMechs_Enable = "AdditionalPlayerMechs"; JsonSerializerSettings serialiserSettings = new JsonSerializerSettings() { @@ -177,6 +180,7 @@ public Settings LoadOverrides(Settings settings) { LoadDynamicWithdraw(settings); LoadAI(settings); LoadSpawners(settings); + LoadMisc(settings); } return settings; @@ -310,5 +314,10 @@ public void LoadSpawners(Settings settings) { if (Has(Spawners_SpawnLanceAtEdgeBoundary_MinBuffer)) settings.Spawners.SpawnLanceAtBoundary.MinBuffer = GetInt(Spawners_SpawnLanceAtEdgeBoundary_MinBuffer); if (Has(Spawners_SpawnLanceAtEdgeBoundary_MaxBuffer)) settings.Spawners.SpawnLanceAtBoundary.MaxBuffer = GetInt(Spawners_SpawnLanceAtEdgeBoundary_MaxBuffer); } + + public void LoadMisc(Settings settings) { + if (Has(Misc_LanceSelectionDivergenceOverride_Enable)) settings.Misc.LanceSelectionDivergenceOverride.Enable = GetBool(Misc_LanceSelectionDivergenceOverride_Enable); + if (Has(Misc_LanceSelectionDivergenceOverride_Divergence)) settings.Misc.LanceSelectionDivergenceOverride.Divergence = GetInt(Misc_LanceSelectionDivergenceOverride_Divergence); + } } } \ No newline at end of file diff --git a/src/MissionControl.csproj b/src/MissionControl.csproj index a47df4eb..95bfb0c0 100644 --- a/src/MissionControl.csproj +++ b/src/MissionControl.csproj @@ -1,6 +1,6 @@ - 1.2.0 + 1.2.1 Library net471 diff --git a/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs b/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs index 4353d436..50cb5877 100644 --- a/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs +++ b/src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs @@ -7,17 +7,16 @@ using BattleTech; using BattleTech.Framework; -namespace MissionControl.Patches -{ - // Under weird circumstances it can ask for a lance at too high difficulty and for unknown reasons it only wants to grab lances within 10 difficulty. - // Allowing over 10 difference in difficulty in it's search in this method should fix the issue. This isn't a Mission Control specific fix as other - // mod set ups could cause this but Mission Control with certain settings could induce this issue in of itself so worth fixing here. - [HarmonyPatch(typeof(LanceOverride), "SelectLanceDefFromList")] - public static class LanceOverrideSelectLanceDefFromListPatch - { - public static void Prefix(ref int ___MAX_DIFF_DIVERGENCE) - { - ___MAX_DIFF_DIVERGENCE = 20; - } +namespace MissionControl.Patches { + // Under weird circumstances it can ask for a lance at too high difficulty and for unknown reasons it only wants to grab lances within 10 difficulty. + // Allowing over 10 difference in difficulty in it's search in this method should fix the issue. This isn't a Mission Control specific fix as other + // mod set ups could cause this but Mission Control with certain settings could induce this issue in of itself so worth fixing here. + [HarmonyPatch(typeof(LanceOverride), "SelectLanceDefFromList")] + public static class LanceOverrideSelectLanceDefFromListPatch { + public static void Prefix(ref int ___MAX_DIFF_DIVERGENCE) { + if (Main.Settings.Misc.LanceSelectionDivergenceOverride.Enable) { + ___MAX_DIFF_DIVERGENCE = Main.Settings.Misc.LanceSelectionDivergenceOverride.Divergence; + } } + } }