Rework gathering multiplier

This commit is contained in:
2024-09-28 01:43:19 +02:00
parent 8f8f3a1969
commit a4ac6d63cd

View File

@@ -6,15 +6,14 @@ using BepInEx.Configuration;
using GameCustomization; using GameCustomization;
using Gameplay.GameResources; using Gameplay.GameResources;
using Gameplay.Scavenge; using Gameplay.Scavenge;
using Gameplay.Units.Player.Workers.WorkSystem; using Gameplay.Units.Workers.WorkSystem.Works;
using Gameplay.Units.Workers;
using HarmonyLib; using HarmonyLib;
using HarmonyLib.Tools; using HarmonyLib.Tools;
// See: // See:
// ConstructableWork // ConstructableWork
// ProductionWork // ProductionWork
// GatherResourceWork // GatherResourcesWork
// GatherableObject // GatherableObject
// AreaWork // 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] [HarmonyPostfix]
[HarmonyPatch(typeof(ScavengeWork), MethodType.Constructor, [HarmonyPatch(typeof(ScavengeWork), MethodType.Constructor,
typeof(float), typeof(List<ResourceCrate>))] typeof(float), typeof(List<ResourceCrate>))]
public static void PostfixScavengeWork(ref ScavengeWork __instance) { public static void PostfixScavengeWork(ref ScavengeWork __instance) {
if (Main.debug.Value) if (Main.debug.Value)
Console.WriteLine($"Scavenge work created"); Console.WriteLine($"Scavenge work created");
if (Main.resourceScavengingMultiplier.Value > 0) { if (Main.resourceGatheringMultiplier.Value > 0) {
for (int i = 0; i < __instance.ResourcesToFind.Count; i++) { for (int i = 0; i < __instance.ResourcesToFind.Count; i++) {
var resource = __instance.ResourcesToFind[i]; var resource = __instance.ResourcesToFind[i];
if (Main.debug.Value) if (Main.debug.Value)
@@ -94,7 +81,7 @@ namespace InfectionFreeZone {
var resourceCount = rtraverse.Field<float>($"_quantity"); var resourceCount = rtraverse.Field<float>($"_quantity");
if (Main.debug.Value) if (Main.debug.Value)
Console.WriteLine($"Resource count is {resourceCount}"); Console.WriteLine($"Resource count is {resourceCount}");
resourceCount.Value *= Main.resourceScavengingMultiplier.Value; resourceCount.Value *= Main.resourceGatheringMultiplier.Value;
if (Main.debug.Value) if (Main.debug.Value)
Console.WriteLine($"Resource count modified to {resourceCount}"); Console.WriteLine($"Resource count modified to {resourceCount}");
rtraverse.Field<float>($"_quantity").Value = resourceCount.Value; rtraverse.Field<float>($"_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<ResourceID, int>();
var resourcesToDrop = trav.Field<Dictionary<ResourceID, int>>("_resourcesToDrop");
if (Main.debug.Value)
Console.WriteLine($"Resources to drop: {resourcesToDrop}");
if (resourcesToDrop.Value.Count > 0) {
foreach (KeyValuePair<ResourceID, int> 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<ResourceID, int> generatedResource in this._resourcesToDrop)
// {
// for (int i = 0; i < generatedResource.Value; i++)
// {
// this.InstantiateResource(generatedResource.Key);
// }
// }
// this._resourcesCreated = true;
// }
// [HarmonyPrefix] // [HarmonyPrefix]
// [HarmonyPatch(typeof(WorkBase), "SetProgress")] // [HarmonyPatch(typeof(WorkBase), "SetProgress")]
// public static void PostfixSetProgress(WorkBase __instance, ref float progress) { // public static void PostfixSetProgress(WorkBase __instance, ref float progress) {