Add work speed and gather multipliers

This commit is contained in:
2024-09-28 00:59:29 +02:00
parent 2e4fe4e7e3
commit b36d7717eb

View File

@@ -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<bool> debug;
public static ConfigEntry<float> resourceMultiplier;
public static ConfigEntry<float> resourceGatheringMultiplier;
public static ConfigEntry<float> 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<float>("_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<float> onProgressUpdated = this.OnProgressUpdated;
// if (onProgressUpdated != null)
// {
// onProgressUpdated(this._progress);
// }
// this.ProgressUpdated(this._progress);
// }
//
// [HarmonyPrefix]
// [HarmonyPatch(typeof(UiController), "ChangeGameSpeed")]