From b36d7717ebb1ecfaf4bc8ec3631631d2551b2a8c Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 28 Sep 2024 00:59:29 +0200 Subject: [PATCH] Add work speed and gather multipliers --- .../InfectionFreeZone/InfectionFreeZone.cs | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs index af96147..2e54188 100644 --- a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs +++ b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs @@ -3,6 +3,9 @@ using System.Linq; using BepInEx; using BepInEx.Configuration; using GameCustomization; +using Gameplay.GameResources; +using Gameplay.Units.Player.Workers.WorkSystem; +using Gameplay.Units.Workers; using HarmonyLib; using HarmonyLib.Tools; @@ -16,11 +19,15 @@ namespace InfectionFreeZone { public static ConfigEntry debug; public static ConfigEntry resourceMultiplier; + public static ConfigEntry resourceGatheringMultiplier; + public static ConfigEntry workSpeedMultiplier; public void Awake() { debug = Config.Bind("General", "Debug", false); resourceMultiplier = Config.Bind("General", "ResourceMultiplier", 1f); + resourceGatheringMultiplier = Config.Bind("General", "ResourceGatheringMultiplier", 1f); + workSpeedMultiplier = Config.Bind("General", "WorkSpeedMultiplier", 1f); Logger.LogInfo("Cyka mod loaded"); HarmonyFileLog.Enabled = true; @@ -47,6 +54,53 @@ namespace InfectionFreeZone { Console.WriteLine($"Resource multiplier modified to {multiplier}"); } } + + [HarmonyPrefix] + [HarmonyPatch(typeof(Work), "AddProfit")] + public static void PostfixGatheredResource(ref ResourceID resourceID, ref float amount) { + if (Main.debug.Value) + Console.WriteLine($"Gathered resource {resourceID} x {amount}"); + if (amount > 0) { + amount *= Main.resourceGatheringMultiplier.Value; + if (Main.debug.Value) + Console.WriteLine($"Gathered resource modified to {resourceID} x {amount}"); + } + } + + [HarmonyPrefix] + [HarmonyPatch(typeof(WorkBase), "SetProgress")] + public static void PostfixSetProgress(WorkBase __instance, ref float progress) { + if (Main.debug.Value) + Console.WriteLine($"Progress is {progress}"); + if (progress > 0) { + var traversed = Traverse.Create(__instance); + var _previousProgress = traversed.Field("_previousProgress"); + var delta = progress - _previousProgress.Value; + + if (Main.debug.Value) + Console.WriteLine($"Delta is {delta}"); + + progress += delta * Main.workSpeedMultiplier.Value; + if (Main.debug.Value) + Console.WriteLine($"Progress modified to {progress}"); + } + } + + // Maybe prefix this with __instance + // And then calculate the delta and update progress with progress+delta + // Or like progress+delta*multiplier + // public void SetProgress(float progress) + // { + // this._previousProgress = this._progress; + // this._progress = progress; + // this.ProgressDelta = this._progress - this._previousProgress; + // Action onProgressUpdated = this.OnProgressUpdated; + // if (onProgressUpdated != null) + // { + // onProgressUpdated(this._progress); + // } + // this.ProgressUpdated(this._progress); + // } // // [HarmonyPrefix] // [HarmonyPatch(typeof(UiController), "ChangeGameSpeed")]