diff --git a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs index fe32832..766535e 100644 --- a/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs +++ b/Projects/InfectionFreeZone/InfectionFreeZone/InfectionFreeZone.cs @@ -6,15 +6,14 @@ using BepInEx.Configuration; using GameCustomization; using Gameplay.GameResources; using Gameplay.Scavenge; -using Gameplay.Units.Player.Workers.WorkSystem; -using Gameplay.Units.Workers; +using Gameplay.Units.Workers.WorkSystem.Works; using HarmonyLib; using HarmonyLib.Tools; // See: // ConstructableWork // ProductionWork -// GatherResourceWork +// GatherResourcesWork // GatherableObject // AreaWork @@ -67,25 +66,13 @@ namespace InfectionFreeZone { } } - [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}"); - } - } - [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) { + if (Main.resourceGatheringMultiplier.Value > 0) { for (int i = 0; i < __instance.ResourcesToFind.Count; i++) { var resource = __instance.ResourcesToFind[i]; if (Main.debug.Value) @@ -94,7 +81,7 @@ namespace InfectionFreeZone { var resourceCount = rtraverse.Field($"_quantity"); if (Main.debug.Value) Console.WriteLine($"Resource count is {resourceCount}"); - resourceCount.Value *= Main.resourceScavengingMultiplier.Value; + resourceCount.Value *= Main.resourceGatheringMultiplier.Value; if (Main.debug.Value) Console.WriteLine($"Resource count modified to {resourceCount}"); rtraverse.Field($"_quantity").Value = resourceCount.Value; @@ -102,6 +89,40 @@ namespace InfectionFreeZone { } } + [HarmonyPrefix] + [HarmonyPatch(typeof(GatherResourcesWork), "InstantiateResources", new Type[] { })] + public static void PrefixGatheredResource(ref ScavengeWork __instance) { + var trav = Traverse.Create(__instance); + var resourcesToDropNew = new Dictionary(); + var resourcesToDrop = trav.Field>("_resourcesToDrop"); + if (Main.debug.Value) + Console.WriteLine($"Resources to drop: {resourcesToDrop}"); + if (resourcesToDrop.Value.Count > 0) { + foreach (KeyValuePair resource in resourcesToDrop.Value) { + if (Main.debug.Value) + Console.WriteLine($"Resource {resource.Key} to drop: {resource.Value}"); + var newResourceValue = (int)(resource.Value * Main.resourceScavengingMultiplier.Value); + resourcesToDropNew.Add(resource.Key, newResourceValue); + if (Main.debug.Value) + Console.WriteLine($"Resource {resource.Key} to drop modified to: {newResourceValue}"); + } + } + resourcesToDrop.Value = resourcesToDropNew; + if (Main.debug.Value) + Console.WriteLine($"Resources to drop modified: {resourcesToDrop}"); + } + // private void InstantiateResources() + // { + // foreach (KeyValuePair generatedResource in this._resourcesToDrop) + // { + // for (int i = 0; i < generatedResource.Value; i++) + // { + // this.InstantiateResource(generatedResource.Key); + // } + // } + // this._resourcesCreated = true; + // } + // [HarmonyPrefix] // [HarmonyPatch(typeof(WorkBase), "SetProgress")] // public static void PostfixSetProgress(WorkBase __instance, ref float progress) {