Skip to content

Commit

Permalink
Merge pull request #441 from CWolfs/develop
Browse files Browse the repository at this point in the history
v1.2.1
  • Loading branch information
CWolfs authored Jun 23, 2021
2 parents 7730be4 + 93847f7 commit d079ea0
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 17 deletions.
2 changes: 1 addition & 1 deletion mod.json
Original file line number Diff line number Diff line change
@@ -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": "[email protected]",
Expand Down
6 changes: 6 additions & 0 deletions settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,5 +128,11 @@
"MinBuffer": 100,
"MaxBuffer": 200
}
},
"Misc": {
"LanceSelectionDivergenceOverride": {
"Enable": true,
"Divergence": 20
}
}
}
9 changes: 8 additions & 1 deletion src/Core/MissionControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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() {
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Settings/Ai/FollowAiSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions src/Core/Settings/Misc/LanceSelectionDivergenceOverride.cs
Original file line number Diff line number Diff line change
@@ -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;
}
}
8 changes: 8 additions & 0 deletions src/Core/Settings/MiscSettings.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
using Newtonsoft.Json;

namespace MissionControl.Config {
public class MiscSettings {
[JsonProperty("LanceSelectionDivergenceOverride")]
public LanceSelectionDivergenceOverride LanceSelectionDivergenceOverride { get; set; } = new LanceSelectionDivergenceOverride();
}
}
5 changes: 4 additions & 1 deletion src/Core/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public class Settings {

[JsonProperty("NeverFailSimGameInFlashpoints")]
public bool NeverFailSimGameInFlashpoints { get; set; } = true;

[JsonProperty("EnableStoryOverrides")]
public bool EnableStoryOverrides { get; set; } = false;

Expand Down Expand Up @@ -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<string, ContractSettingsOverrides> ContractSettingsOverrides = new Dictionary<string, ContractSettingsOverrides>();

public ContractSettingsOverrides ActiveContractSettings { get; set; }
Expand Down
9 changes: 9 additions & 0 deletions src/Core/Settings/SettingsOverride.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -177,6 +180,7 @@ public Settings LoadOverrides(Settings settings) {
LoadDynamicWithdraw(settings);
LoadAI(settings);
LoadSpawners(settings);
LoadMisc(settings);
}

return settings;
Expand Down Expand Up @@ -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);
}
}
}
2 changes: 1 addition & 1 deletion src/MissionControl.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>1.2.0</Version>
<Version>1.2.1</Version>
<OutputType>Library</OutputType>
<TargetFramework>net471</TargetFramework>
</PropertyGroup>
Expand Down
23 changes: 11 additions & 12 deletions src/Patches/Bug Fixes/LanceOverrideSelectLanceDefFromListPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
}
}

0 comments on commit d079ea0

Please sign in to comment.