Add scavenge multiplier item

This commit is contained in:
2024-09-28 01:26:47 +02:00
parent 8eaaaadcd0
commit 8f8f3a1969

View File

@@ -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<float> resourceMultiplier;
public static ConfigEntry<float> resourceGatheringMultiplier;
public static ConfigEntry<float> resourceScavengingMultiplier;
// public static ConfigEntry<float> 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<ResourceCrate>))]
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<float>($"_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<float>($"_quantity").Value = resourceCount.Value;
}
}
}
// [HarmonyPrefix]
// [HarmonyPatch(typeof(WorkBase), "SetProgress")]
// public static void PostfixSetProgress(WorkBase __instance, ref float progress) {