pre release
This commit is contained in:
@ -13,6 +13,11 @@ namespace TemporalTempestLight.Patches;
|
|||||||
[HarmonyPatchCategory("temporaltempestlight")]
|
[HarmonyPatchCategory("temporaltempestlight")]
|
||||||
internal class TemporalStabilityPatches
|
internal class TemporalStabilityPatches
|
||||||
{
|
{
|
||||||
|
private const int ActualFirstDay = 36;
|
||||||
|
private const int MonthsPerYear = 12;
|
||||||
|
private const int HoursPerDay = 24;
|
||||||
|
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
[HarmonyPatch(typeof(SystemTemporalStability), "Event_OnEntityDeath")]
|
[HarmonyPatch(typeof(SystemTemporalStability), "Event_OnEntityDeath")]
|
||||||
public static void OnEntityDeathPatch(SystemTemporalStability __instance, ICoreAPI ___api, Entity entity, DamageSource damageSource)
|
public static void OnEntityDeathPatch(SystemTemporalStability __instance, ICoreAPI ___api, Entity entity, DamageSource damageSource)
|
||||||
@ -20,6 +25,8 @@ internal class TemporalStabilityPatches
|
|||||||
var system = __instance;
|
var system = __instance;
|
||||||
var api = ___api;
|
var api = ___api;
|
||||||
|
|
||||||
|
var tempest = api.ModLoader.GetModSystem<TemporalTempestLightModSystem>();
|
||||||
|
|
||||||
if (!system.StormData.nowStormActive) return;
|
if (!system.StormData.nowStormActive) return;
|
||||||
|
|
||||||
var entityIsNotDrifter =
|
var entityIsNotDrifter =
|
||||||
@ -29,13 +36,11 @@ internal class TemporalStabilityPatches
|
|||||||
|
|
||||||
if (entityIsNotDrifter || damageSourceIsDrifter) return;
|
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);
|
// TODO REMOVE ON RELEASE
|
||||||
|
((IServerPlayer)(((EntityPlayer)(damageSource.GetCauseEntity())).Player)).SendMessage(GlobalConstants.GeneralChatGroup, (system.StormData.stormActiveTotalDays - api.World.Calendar.TotalDays).ToString(), EnumChatType.Notification);
|
||||||
var stormActiveDaysReduction =
|
((IServerPlayer)(((EntityPlayer)(damageSource.GetCauseEntity())).Player)).SendMessage(GlobalConstants.GeneralChatGroup, (tempest.CurrentStormDurationReduction).ToString(), EnumChatType.Notification);
|
||||||
stormActiveDays * 0.2;
|
|
||||||
system.StormData.stormActiveTotalDays -= stormActiveDaysReduction;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[HarmonyPostfix]
|
[HarmonyPostfix]
|
||||||
@ -51,13 +56,9 @@ internal class TemporalStabilityPatches
|
|||||||
{
|
{
|
||||||
if (tempest.IsStormInitialized) return;
|
if (tempest.IsStormInitialized) return;
|
||||||
|
|
||||||
var daysPerMoth = api.World.Config.GetAsInt("daysPerMonth");
|
var stormActiveDays = CalcStormActiveDays(api, tempest);
|
||||||
|
stabilitySystem.StormData.stormActiveTotalDays = stormActiveDays + api.World.Calendar.TotalDays;
|
||||||
stabilitySystem.StormData.stormActiveTotalDays = Math.Min(
|
tempest.CurrentStormDurationReduction = CalcStormReduction(api, tempest, stormActiveDays);
|
||||||
TemporalTempestLightModSystem.Config.InitialStormDuration +
|
|
||||||
TemporalTempestLightModSystem.Config.StormDurationGrowthPerYear * ((api.World.Calendar.TotalDays - 36) / daysPerMoth / 12),
|
|
||||||
TemporalTempestLightModSystem.Config.StormDurationLimit) / 24 + api.World.Calendar.TotalDays;
|
|
||||||
|
|
||||||
tempest.IsStormInitialized = true;
|
tempest.IsStormInitialized = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -65,4 +66,34 @@ internal class TemporalStabilityPatches
|
|||||||
tempest.IsStormInitialized = false;
|
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
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
@ -10,7 +10,7 @@ public class TemporalTempestLightModSystem : ModSystem
|
|||||||
{
|
{
|
||||||
private Harmony Patcher { get; set; }
|
private Harmony Patcher { get; set; }
|
||||||
|
|
||||||
public static ModConfig Config { get; private set; }
|
public ModConfig Config { get; private set; }
|
||||||
|
|
||||||
private ICoreServerAPI Api { get; set; }
|
private ICoreServerAPI Api { get; set; }
|
||||||
|
|
||||||
@ -20,6 +20,12 @@ public class TemporalTempestLightModSystem : ModSystem
|
|||||||
set => Api.WorldManager.SaveGame.StoreData("temporaltempestlight:IsStormInitialized", value);
|
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)
|
public override void StartServerSide(ICoreServerAPI api)
|
||||||
{
|
{
|
||||||
Api = api;
|
Api = api;
|
||||||
|
Reference in New Issue
Block a user