From 94c09a6727a5d04a7d86c88a836cd0b50d67459c Mon Sep 17 00:00:00 2001 From: Dencher12 Date: Sun, 13 Jul 2025 12:44:43 +0300 Subject: [PATCH] pre release --- .../Patches/TemporalStabilityPatches.cs | 57 ++++++++++++++----- .../TemporalTempestLightModSystem.cs | 8 ++- 2 files changed, 51 insertions(+), 14 deletions(-) diff --git a/TemporalTempestLight/TemporalTempestLight/Patches/TemporalStabilityPatches.cs b/TemporalTempestLight/TemporalTempestLight/Patches/TemporalStabilityPatches.cs index e19e376..a8ac8fe 100644 --- a/TemporalTempestLight/TemporalTempestLight/Patches/TemporalStabilityPatches.cs +++ b/TemporalTempestLight/TemporalTempestLight/Patches/TemporalStabilityPatches.cs @@ -13,6 +13,11 @@ namespace TemporalTempestLight.Patches; [HarmonyPatchCategory("temporaltempestlight")] internal class TemporalStabilityPatches { + private const int ActualFirstDay = 36; + private const int MonthsPerYear = 12; + private const int HoursPerDay = 24; + + [HarmonyPostfix] [HarmonyPatch(typeof(SystemTemporalStability), "Event_OnEntityDeath")] public static void OnEntityDeathPatch(SystemTemporalStability __instance, ICoreAPI ___api, Entity entity, DamageSource damageSource) @@ -20,6 +25,8 @@ internal class TemporalStabilityPatches var system = __instance; var api = ___api; + var tempest = api.ModLoader.GetModSystem(); + if (!system.StormData.nowStormActive) return; var entityIsNotDrifter = @@ -29,13 +36,11 @@ internal class TemporalStabilityPatches if (entityIsNotDrifter || damageSourceIsDrifter) return; - var stormActiveDays = system.StormData.stormActiveTotalDays - api.World.Calendar.TotalDays; + system.StormData.stormActiveTotalDays -= tempest.CurrentStormDurationReduction; - ((IServerPlayer)(((EntityPlayer)(damageSource.GetCauseEntity())).Player)).SendMessage(GlobalConstants.GeneralChatGroup, (stormActiveDays).ToString(), EnumChatType.Notification); - - var stormActiveDaysReduction = - stormActiveDays * 0.2; - system.StormData.stormActiveTotalDays -= stormActiveDaysReduction; + // TODO REMOVE ON RELEASE + ((IServerPlayer)(((EntityPlayer)(damageSource.GetCauseEntity())).Player)).SendMessage(GlobalConstants.GeneralChatGroup, (system.StormData.stormActiveTotalDays - api.World.Calendar.TotalDays).ToString(), EnumChatType.Notification); + ((IServerPlayer)(((EntityPlayer)(damageSource.GetCauseEntity())).Player)).SendMessage(GlobalConstants.GeneralChatGroup, (tempest.CurrentStormDurationReduction).ToString(), EnumChatType.Notification); } [HarmonyPostfix] @@ -51,13 +56,9 @@ internal class TemporalStabilityPatches { if (tempest.IsStormInitialized) return; - var daysPerMoth = api.World.Config.GetAsInt("daysPerMonth"); - - stabilitySystem.StormData.stormActiveTotalDays = Math.Min( - TemporalTempestLightModSystem.Config.InitialStormDuration + - TemporalTempestLightModSystem.Config.StormDurationGrowthPerYear * ((api.World.Calendar.TotalDays - 36) / daysPerMoth / 12), - TemporalTempestLightModSystem.Config.StormDurationLimit) / 24 + api.World.Calendar.TotalDays; - + var stormActiveDays = CalcStormActiveDays(api, tempest); + stabilitySystem.StormData.stormActiveTotalDays = stormActiveDays + api.World.Calendar.TotalDays; + tempest.CurrentStormDurationReduction = CalcStormReduction(api, tempest, stormActiveDays); tempest.IsStormInitialized = true; } else @@ -65,4 +66,34 @@ internal class TemporalStabilityPatches tempest.IsStormInitialized = false; } } + + private static double CalcYearsFromWorldStart(ICoreAPI api) + { + var daysPerMoth = api.World.Config.GetAsInt("daysPerMonth"); + + var daysFromWorldStart = api.World.Calendar.TotalDays - ActualFirstDay; + return daysFromWorldStart / daysPerMoth / MonthsPerYear; + } + + private static double CalcStormReduction(ICoreAPI api, TemporalTempestLightModSystem tempest, double stormActiveDays) + { + return stormActiveDays * CalcStormDurationReductionMul(api, tempest); + } + + private static double CalcStormActiveDays(ICoreAPI api, TemporalTempestLightModSystem tempest) + { + var stormActiveInHours = Math.Min( + tempest.Config.InitialStormDuration + tempest.Config.StormDurationGrowthPerYear * CalcYearsFromWorldStart(api), + tempest.Config.StormDurationLimit); + + return stormActiveInHours / HoursPerDay; + } + + private static double CalcStormDurationReductionMul(ICoreAPI api, TemporalTempestLightModSystem tempest) + { + return Math.Max( + tempest.Config.InitialStormDurationReductionMul - tempest.Config.StormDurationReductionMulDecreasePerYear * + CalcYearsFromWorldStart(api), tempest.Config.StormDurationReductionMulLimit + ); + } } \ No newline at end of file diff --git a/TemporalTempestLight/TemporalTempestLight/TemporalTempestLightModSystem.cs b/TemporalTempestLight/TemporalTempestLight/TemporalTempestLightModSystem.cs index c553cd8..b0ec980 100644 --- a/TemporalTempestLight/TemporalTempestLight/TemporalTempestLightModSystem.cs +++ b/TemporalTempestLight/TemporalTempestLight/TemporalTempestLightModSystem.cs @@ -10,7 +10,7 @@ public class TemporalTempestLightModSystem : ModSystem { private Harmony Patcher { get; set; } - public static ModConfig Config { get; private set; } + public ModConfig Config { get; private set; } private ICoreServerAPI Api { get; set; } @@ -20,6 +20,12 @@ public class TemporalTempestLightModSystem : ModSystem set => Api.WorldManager.SaveGame.StoreData("temporaltempestlight:IsStormInitialized", value); } + public double CurrentStormDurationReduction + { + get => Api.WorldManager.SaveGame.GetData("temporaltempestlight:CurrentStormDurationReduction"); + set => Api.WorldManager.SaveGame.StoreData("temporaltempestlight:CurrentStormDurationReduction", value); + } + public override void StartServerSide(ICoreServerAPI api) { Api = api;