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 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<ResourceCrate>))]
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<float>($"_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<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]
// [HarmonyPatch(typeof(WorkBase), "SetProgress")]
// public static void PostfixSetProgress(WorkBase __instance, ref float progress) {