Add speed multiplier for humans

This commit is contained in:
2024-09-28 13:46:24 +02:00
parent 1ce4d4368e
commit fa822cedd4

View File

@@ -8,6 +8,7 @@ using Gameplay.Buildings;
using Gameplay.GameResources;
using Gameplay.InGameResources;
using Gameplay.Scavenge;
using Gameplay.Units.Movements;
using Gameplay.Units.Workers.WorkSystem.Works;
using HarmonyLib;
using HarmonyLib.Tools;
@@ -18,7 +19,8 @@ using HarmonyLib.Tools;
// GatherResourcesWork
// GatherableObject
// AreaWork
// Gameplay.Vehicles.Vehicle.Update() : void @060044A1
// System.Single Gameplay.Units.Movements.Movement::CalculateSpeed()
namespace InfectionFreeZone {
[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
@@ -35,17 +37,20 @@ namespace InfectionFreeZone {
public static ConfigEntry<float> buildingStorageCapacityMultiplier;
public static ConfigEntry<float> buildingQuartersCapacityMultiplier;
public static ConfigEntry<float> buildingDeconstructionResourcesMultiplier;
public static ConfigEntry<float> humanMovementSpeedMultiplier;
// public static ConfigEntry<float> workSpeedMultiplier;
public void Awake() {
debug = Config.Bind("General", "Debug", false);
resourceMultiplier = Config.Bind("General", "ResourceMultiplier", 1f);
resourceGatheringMultiplier = Config.Bind("General", "ResourceGatheringMultiplier", 1f);
resourceScavengingMultiplier = Config.Bind("General", "ResourceScavengingMultiplier", 1f);
buildingStorageCapacityMultiplier = Config.Bind("General", "BuildingStorageCapacityMultiplier", 1f);
buildingQuartersCapacityMultiplier = Config.Bind("General", "BuildingQuartersCapacityMultiplier", 1f);
buildingDeconstructionResourcesMultiplier = Config.Bind("General", "BuildingDeconstructionResourcesMultiplier", 1f);
resourceMultiplier = Config.Bind("General", "Resource Multiplier", 1f);
resourceGatheringMultiplier = Config.Bind("General", "Resource Gathering Multiplier", 1f);
resourceScavengingMultiplier = Config.Bind("General", "Resource Scavenging Multiplier", 1f);
buildingStorageCapacityMultiplier = Config.Bind("General", "Building Storage Capacity Multiplier", 1f);
buildingQuartersCapacityMultiplier = Config.Bind("General", "Building Quarters Capacity Multiplier", 1f);
buildingDeconstructionResourcesMultiplier =
Config.Bind("General", "Building Deconstruction Resources Multiplier", 1f);
humanMovementSpeedMultiplier = Config.Bind("General", "Human Movement Speed Multiplier", 1f);
// workSpeedMultiplier = Config.Bind("General", "WorkSpeedMultiplier", 1f);
Logger.LogInfo("Cyka mod loaded");
@@ -155,12 +160,12 @@ namespace InfectionFreeZone {
if (Main.debug.Value)
Console.WriteLine($"Deconstruction resources is {__result}");
for (int i = 0; i < __result.Length; i++) {
var resourceQuantity = __result[i];
if (Main.debug.Value)
Console.WriteLine($"Resource quantity is {resourceQuantity}");
if (Main.debug.Value)
Console.WriteLine($"Resource quantity value is {resourceQuantity.value}");
resourceQuantity.value *= Main.buildingDeconstructionResourcesMultiplier.Value;
@@ -168,96 +173,21 @@ namespace InfectionFreeZone {
Console.WriteLine($"Resource quantity value modified to {resourceQuantity.value}");
}
}
// 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) {
// if (Main.debug.Value)
// Console.WriteLine($"Progress is {progress}");
// if (progress > 0) {
// var traversed = Traverse.Create(__instance);
// var _previousProgress = traversed.Field<float>("_previousProgress");
// if (Main.debug.Value)
// Console.WriteLine($"_previousProgress is {_previousProgress}");
//
// var delta = progress - _previousProgress.Value;
// if (Main.debug.Value)
// Console.WriteLine($"Delta is {delta}");
//
// progress += delta * Main.workSpeedMultiplier.Value;
// if (Main.debug.Value)
// Console.WriteLine($"Progress modified to {progress}");
// }
// }
[HarmonyPostfix]
[HarmonyPatch(typeof(Movement), "CalculateSpeed")]
public static void PostfixCalculateSpeedHuman(Movement __instance, ref float __result) {
if (Main.humanMovementSpeedMultiplier.Value <= 0)
return;
// Humans are "Human(Clone)", infected are "inf_human(Clone)"
if (__instance.gameObject.name != "Human(Clone)")
return;
// Maybe prefix this with __instance
// And then calculate the delta and update progress with progress+delta
// Or like progress+delta*multiplier
// public void SetProgress(float progress)
// {
// this._previousProgress = this._progress;
// this._progress = progress;
// this.ProgressDelta = this._progress - this._previousProgress;
// Action<float> onProgressUpdated = this.OnProgressUpdated;
// if (onProgressUpdated != null)
// {
// onProgressUpdated(this._progress);
// }
// this.ProgressUpdated(this._progress);
// }
//
// [HarmonyPrefix]
// [HarmonyPatch(typeof(UiController), "ChangeGameSpeed")]
// public static void PrefixSpeed(ref int gameSpeed) {
// if (Main.debug.Value)
// Console.WriteLine($"Game speed is {gameSpeed}");
// if (gameSpeed > 1) {
// gameSpeed = Main.fastSpeed.Value;
// if (Main.debug.Value)
// Console.WriteLine($"Game speed modified to {gameSpeed}");
// }
// }
//
// [HarmonyPrefix]
// [HarmonyPatch(typeof(StaffModel), "UpdateXp")]
// public static void PrefixXp(ref int id, ref int amount) {
// if (Main.debug.Value)
// Console.WriteLine($"Staff xp is {amount}");
// if (amount > 0) {
// amount = (int)(amount * Main.staffXpMultiplier.Value);
// if (Main.debug.Value)
// Console.WriteLine($"Staff xp modified to {amount}");
// }
// }
//
// [HarmonyPostfix]
// [HarmonyPatch(typeof(TechTreeModel), nameof(TechTreeModel.GetBonusPeoplePerMinute))]
// public static void PostfixPeoplePerMinute(ref float __result) {
// __result *= Main.peoplePerMinuteMultiplier.Value;
// __result += Main.peoplePerMinuteOffset.Value;
// }
//
// [HarmonyPostfix]
// [HarmonyPatch(typeof(TavernModel), nameof(TavernModel.GetQuality))]
// public static void PostfixQuality(ref int __result) {
// if (Main.debug.Value)
// Console.WriteLine($"Quality is {__result}");
// if (__result > 0) {
// __result = (int)(__result * Main.prestigeMultiplier.Value);
// if (Main.debug.Value)
// Console.WriteLine($"Quality modified to {__result}");
// }
// }
if (Main.debug.Value)
Console.WriteLine($"Human movement speed is {__result}");
__result *= Main.humanMovementSpeedMultiplier.Value;
if (Main.debug.Value)
Console.WriteLine($"Human movement speed modified to {__result}");
}
}
}