From 8f8f3a1969dc672039533f2d26fc5c048bc197ed Mon Sep 17 00:00:00 2001 From: PhatPhuckDave Date: Sat, 28 Sep 2024 01:26:47 +0200 Subject: [PATCH] Add scavenge multiplier item --- .../InfectionFreeZone/InfectionFreeZone.cs | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs index 5ee568f..fe32832 100644 --- a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs +++ b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs @@ -1,14 +1,24 @@ using System; +using System.Collections.Generic; using System.Linq; using BepInEx; using BepInEx.Configuration; using GameCustomization; using Gameplay.GameResources; +using Gameplay.Scavenge; using Gameplay.Units.Player.Workers.WorkSystem; using Gameplay.Units.Workers; using HarmonyLib; using HarmonyLib.Tools; +// See: +// ConstructableWork +// ProductionWork +// GatherResourceWork +// GatherableObject +// AreaWork + + namespace InfectionFreeZone { [BepInPlugin(pluginGuid, pluginName, pluginVersion)] public class Main : BaseUnityPlugin { @@ -20,6 +30,7 @@ namespace InfectionFreeZone { public static ConfigEntry resourceMultiplier; public static ConfigEntry resourceGatheringMultiplier; + public static ConfigEntry resourceScavengingMultiplier; // public static ConfigEntry workSpeedMultiplier; public void Awake() { @@ -27,6 +38,7 @@ namespace InfectionFreeZone { resourceMultiplier = Config.Bind("General", "ResourceMultiplier", 1f); resourceGatheringMultiplier = Config.Bind("General", "ResourceGatheringMultiplier", 1f); + resourceScavengingMultiplier = Config.Bind("General", "ResourceScavengingMultiplier", 1f); // workSpeedMultiplier = Config.Bind("General", "WorkSpeedMultiplier", 1f); Logger.LogInfo("Cyka mod loaded"); @@ -67,6 +79,29 @@ namespace InfectionFreeZone { } } + [HarmonyPostfix] + [HarmonyPatch(typeof(ScavengeWork), MethodType.Constructor, + typeof(float), typeof(List))] + public static void PostfixScavengeWork(ref ScavengeWork __instance) { + if (Main.debug.Value) + Console.WriteLine($"Scavenge work created"); + if (Main.resourceScavengingMultiplier.Value > 0) { + for (int i = 0; i < __instance.ResourcesToFind.Count; i++) { + var resource = __instance.ResourcesToFind[i]; + if (Main.debug.Value) + Console.WriteLine($"Resource {resource} to find"); + var rtraverse = Traverse.Create(resource); + var resourceCount = rtraverse.Field($"_quantity"); + if (Main.debug.Value) + Console.WriteLine($"Resource count is {resourceCount}"); + resourceCount.Value *= Main.resourceScavengingMultiplier.Value; + if (Main.debug.Value) + Console.WriteLine($"Resource count modified to {resourceCount}"); + rtraverse.Field($"_quantity").Value = resourceCount.Value; + } + } + } + // [HarmonyPrefix] // [HarmonyPatch(typeof(WorkBase), "SetProgress")] // public static void PostfixSetProgress(WorkBase __instance, ref float progress) {