-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
some reorgnaizing, fix contract difficulty persistence
- Loading branch information
Showing
5 changed files
with
195 additions
and
146 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
MapRandomizer/MapRandomizer/source/Patches/ContractPatch.cs
This file was deleted.
Oops, something went wrong.
66 changes: 66 additions & 0 deletions
66
MapRandomizer/MapRandomizer/source/Patches/DifficultyPersistancePatches.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Text; | ||
using System.Threading.Tasks; | ||
using BattleTech; | ||
using BattleTech.Save; | ||
using BattleTech.Save.Test; | ||
using Harmony; | ||
using MapRandomizer.Patches; | ||
using UnityEngine; | ||
|
||
namespace MapRandomizer.source.Patches | ||
{ | ||
internal class DifficultyPersistancePatches | ||
{ | ||
[HarmonyPatch(typeof(SimGameState), "Dehydrate", | ||
new Type[] {typeof(SimGameSave), typeof(SerializableReferenceContainer)})] | ||
public static class SGS_Dehydrate_Patch//MR_DIFFICULTY_ | ||
{ | ||
public static void Prefix(SimGameState __instance) | ||
{ | ||
foreach (var diffOverride in ModState.SavedDiffOverrides) | ||
{ | ||
__instance.CompanyStats.AddStatistic(diffOverride.Key, diffOverride.Value); | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(SimGameState), "Rehydrate", new Type[] {typeof(GameInstanceSave)})] | ||
public static class SGS_Rehydrate_Patch | ||
{ | ||
public static void Postfix(SimGameState __instance) | ||
{ | ||
foreach (var statistic in __instance.CompanyStats) | ||
{ | ||
if (statistic.Key.StartsWith("MR_DIFFICULTY_")) | ||
{ | ||
ModState.SavedDiffOverrides.Add(statistic.Key, statistic.Value.Value<int>()); | ||
} | ||
} | ||
|
||
foreach (var statOverride in ModState.SavedDiffOverrides) | ||
{ | ||
__instance.CompanyStats.RemoveStatistic(statOverride.Key); | ||
} | ||
} | ||
} | ||
|
||
[HarmonyPatch(typeof(Contract), "CompleteContract", new Type[] {typeof(MissionResult), typeof(bool)})] | ||
public static class Contract_CompleteContract_Patch | ||
{ | ||
public static void Prefix(Contract __instance, MissionResult result, bool isGoodFaithEffort) | ||
{ | ||
var sim = UnityGameInstance.BattleTechGame.Simulation; | ||
if (sim == null) return; | ||
var baseDiff = sim.CurSystem.Def.GetDifficulty(sim.SimGameMode) + Mathf.FloorToInt(sim.GlobalDifficulty); | ||
var quid = __instance.GenerateContractQuasiGUID(__instance.Override.employerTeam.FactionValue, __instance.Override.targetTeam.FactionValue, baseDiff, __instance.ContractBiome, sim.CurSystem); | ||
if (ModState.SavedDiffOverrides.ContainsKey(quid)) | ||
{ | ||
ModState.SavedDiffOverrides.Remove(quid); | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.