pre release

This commit is contained in:
2025-07-13 12:44:43 +03:00
parent e7cacc43f4
commit 94c09a6727
2 changed files with 51 additions and 14 deletions

View File

@ -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<TemporalTempestLightModSystem>();
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
);
}
}

View File

@ -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<double>("temporaltempestlight:CurrentStormDurationReduction");
set => Api.WorldManager.SaveGame.StoreData("temporaltempestlight:CurrentStormDurationReduction", value);
}
public override void StartServerSide(ICoreServerAPI api)
{
Api = api;