diff --git a/JotunnModStub/Aswid/AswidRace.cs b/JotunnModStub/Aswid/AswidRace.cs index b3612bc..c864a7f 100644 --- a/JotunnModStub/Aswid/AswidRace.cs +++ b/JotunnModStub/Aswid/AswidRace.cs @@ -863,6 +863,38 @@ namespace RacesOfValheim StartCoroutine(EclipseRoutine()); } + /// + /// The Eclipse's dusk as (seconds, day fraction) keys, walked linearly between them. + /// + /// Not one even sweep, because the sky does not change evenly. EnvMan keeps it looking like + /// day from 0.25 to 0.75 and does all its darkening around sunset, so an even run from + /// the afternoon to midnight looked still for three seconds and then fell dark in half of + /// one. Here the afternoon goes by in half a second and the sunset band gets three. + /// The first key's fraction is replaced by the time of the cast, and any key earlier in + /// the day than that is lifted to it, so a cast near dusk does not run the clock backwards. + /// + private static readonly Vector2[] EclipseDuskKeys = + { + new Vector2(0f, 0f), // the time of the cast + new Vector2(0.5f, 0.70f), // late afternoon, just before the sky starts to change + new Vector2(3.5f, 0.95f), // through the sunset band, slowly + new Vector2(4f, 1f), // midnight + }; + + private static float EclipseDuskFraction(float from, float seconds) + { + float prevT = 0f, prevF = from; + for (int i = 1; i < EclipseDuskKeys.Length; i++) + { + float keyT = EclipseDuskKeys[i].x; + float keyF = Mathf.Max(EclipseDuskKeys[i].y, from); + if (seconds <= keyT) return Mathf.Lerp(prevF, keyF, Mathf.InverseLerp(prevT, keyT, seconds)); + prevT = keyT; + prevF = keyF; + } + return 1f; + } + private System.Collections.IEnumerator EclipseRoutine() { IsEclipseActive = true; @@ -897,8 +929,23 @@ namespace RacesOfValheim { if (EnvMan.instance != null) { - EnvMan.instance.m_debugTime = 0f; + // Run the clock forward through dusk to midnight rather than cutting to it. + // While m_debugTimeOfDay is on, EnvMan copies m_debugTime straight onto the sky + // with no smoothing of its own, so the pacing has to happen here - see + // EclipseDuskKeys. Forward means up to 1, which is midnight again; the Aswid's + // night buffs start at 0.75, partway through. The way back needs nothing: once the switch is off, EnvMan + // eases towards the real time by itself. + float from = EnvMan.instance.GetDayFraction(); + EnvMan.instance.m_debugTime = from; EnvMan.instance.m_debugTimeOfDay = true; + + float duskSeconds = EclipseDuskKeys[EclipseDuskKeys.Length - 1].x; + for (float t = 0f; t < duskSeconds && EnvMan.instance != null; t += Time.deltaTime) + { + EnvMan.instance.m_debugTime = EclipseDuskFraction(from, t); + yield return null; + } + if (EnvMan.instance != null) EnvMan.instance.m_debugTime = 1f; } yield return new WaitForSeconds(AswidConfig.EclipseDuration.Value);