diff --git a/JotunnModStub/Sverm/SvermBlisterTick.cs b/JotunnModStub/Sverm/SvermBlisterTick.cs index b0fd8ad..6fd2a57 100644 --- a/JotunnModStub/Sverm/SvermBlisterTick.cs +++ b/JotunnModStub/Sverm/SvermBlisterTick.cs @@ -31,7 +31,9 @@ namespace RacesOfValheim /// The blast, in rising order of nastiness. Both are verified manifest names. private const string EarlyBlast = "BombBlob_Poison_projectile"; private const string LateBlast = "BombBlob_PoisonElite_projectile"; - private const string BlastEffect = "BombBlob_explode_poison"; + // "vfx_" and not the bare name, which is not an asset at all: until 2026-09-30 the lookup + // came back null and the tick burst with no effect. Checked against the 1.0 manifest. + private const string BlastEffect = "vfx_BombBlob_explode_poison"; private static HitData.DamageTypes earlyDamage; private static HitData.DamageTypes lateDamage; diff --git a/JotunnModStub/Sverm/SvermBrood.cs b/JotunnModStub/Sverm/SvermBrood.cs index a77e0ac..c54c9ef 100644 --- a/JotunnModStub/Sverm/SvermBrood.cs +++ b/JotunnModStub/Sverm/SvermBrood.cs @@ -281,24 +281,19 @@ namespace RacesOfValheim { ZNetView nview = View(nest); if (nview == null) return 0; - - ZDO zdo = nview.GetZDO(); - int stored = zdo.GetInt(EggKey, 0); - long clock = zdo.GetLong(ClockKey, 0L); - - // A clutch that has never been settled has no elapsed time to claim. Reading a missing - // clock as zero would hand a brand new nest every egg since the world began. - if (clock <= 0L) return Mathf.Clamp(stored, 0, Cap(nest)); - - long elapsed = WorldSecond() - clock; - int laid = elapsed > 0L ? (int)(elapsed / SvermConfig.EggInterval) : 0; - - return Mathf.Clamp(stored + laid, 0, Cap(nest)); + return Tally(nview.GetZDO(), nest, out _); } /// - /// Writes down what time has laid and restarts the clock. The owner calls this on a timer so - /// the number the other clients read is never far behind. + /// Writes down what time has laid. The owner calls this every second so the number the + /// other clients read is never far behind. + /// + /// It used to restart the clock at "now" on every call. One second is 1/20 of an egg, which + /// integer division rounds to none, so with the owner standing by the nest the clock was + /// reset every second, twenty seconds never went by, and the clutch stayed empty for as + /// long as anybody was there to see it. Every troop and the Blister Tick cost an egg, so the + /// whole shelf stayed grey. The clock now moves on only by the eggs actually laid, the same + /// rule SvermBiomass.Digest keeps. /// public static void Settle(Transform nest) { @@ -306,10 +301,10 @@ namespace RacesOfValheim if (nview == null || !nview.IsOwner()) return; ZDO zdo = nview.GetZDO(); - int now = Count(nest); + int now = Tally(zdo, nest, out long clock); zdo.Set(EggKey, now); - zdo.Set(ClockKey, WorldSecond()); + zdo.Set(ClockKey, clock); } /// Takes eggs out of the clutch. All or nothing. @@ -318,15 +313,53 @@ namespace RacesOfValheim ZNetView nview = View(nest); if (nview == null) return false; - int have = Count(nest); + ZDO zdo = nview.GetZDO(); + int have = Tally(zdo, nest, out long clock); if (have < howMany) return false; if (!nview.IsOwner()) nview.ClaimOwnership(); - nview.GetZDO().Set(EggKey, have - howMany); - nview.GetZDO().Set(ClockKey, WorldSecond()); + zdo.Set(EggKey, have - howMany); + zdo.Set(ClockKey, clock); return true; } + /// + /// The clutch as of now, and where its clock should stand afterwards. + /// + /// The clock advances by whole eggs only, so the part of the twenty seconds already waited + /// for the next one is kept. A full clutch lays nothing, so its clock is held at now: the + /// first egg after one is taken comes twenty seconds later, not at once. A clutch that has + /// never been settled has no elapsed time to claim - reading a missing clock as zero would + /// hand a brand new nest every egg since the world began. + /// + private static int Tally(ZDO zdo, Transform nest, out long clock) + { + long now = WorldSecond(); + int cap = Cap(nest); + int stored = zdo.GetInt(EggKey, 0); + clock = zdo.GetLong(ClockKey, 0L); + + if (clock <= 0L) + { + clock = now; + return Mathf.Clamp(stored, 0, cap); + } + + long interval = (long)SvermConfig.EggInterval; + long elapsed = now - clock; + long laid = elapsed > 0L && interval > 0L ? elapsed / interval : 0L; + + long eggs = stored + laid; + if (eggs >= cap) + { + clock = now; + return cap; + } + + clock += laid * interval; + return Mathf.Max(0, (int)eggs); + } + private static ZNetView View(Transform nest) { ZNetView nview = nest != null ? nest.GetComponent() : null; diff --git a/JotunnModStub/Trol/TrolGammelLog.cs b/JotunnModStub/Trol/TrolGammelLog.cs index 68cbb16..4056e3d 100644 --- a/JotunnModStub/Trol/TrolGammelLog.cs +++ b/JotunnModStub/Trol/TrolGammelLog.cs @@ -14,10 +14,16 @@ namespace RacesOfValheim /// then the log is the child, and the parent would bring the whole rose along with it. /// If none of that resolves, GetProjectile returns null and TrolRace falls back to the old /// physical log. "dumpgammel" in the console logs what was actually found. + /// + /// "Gammeltroll" is only the developers' name for it. The prefab is TrollFrost, the Deep North + /// troll: its clips fire the sfx_gameltroll_* sounds, and its 'Attack TreeThrow' shows a + /// 'treebundle' at 2.03s and throws it at 3.54s (dumpanim TrollFrost). No prefab is called + /// Gammeltroll, so from v1.4.16 until this was corrected the lookup found nothing and every + /// True Form throw fell back to the physical log. /// public static class TrolGammelLog { - private const string GammeltrollPrefab = "Gammeltroll"; + private const string GammeltrollPrefab = "TrollFrost"; private static GameObject cachedProjectile; private static float cachedVelocity; @@ -45,7 +51,7 @@ namespace RacesOfValheim velocity = 0f; GameObject troll = FindGammeltroll(); - if (troll == null) { log?.Invoke("Gammeltroll prefab not found in ZNetScene."); return; } + if (troll == null) { log?.Invoke($"Gammeltroll prefab '{GammeltrollPrefab}' not found in ZNetScene."); return; } log?.Invoke($"Monster prefab: '{troll.name}'"); Humanoid humanoid = troll.GetComponent(); @@ -87,14 +93,10 @@ namespace RacesOfValheim private static GameObject FindGammeltroll() { - GameObject exact = ZNetScene.instance.GetPrefab(GammeltrollPrefab); - if (exact != null) return exact; - foreach (GameObject prefab in ZNetScene.instance.m_prefabs) - { - if (prefab != null && prefab.name.ToLowerInvariant().Contains("gammel") && prefab.GetComponent() != null) - return prefab; - } - return null; + // Exact name only. The old fallback took the first Humanoid with "gammel" anywhere in + // its name, which in vanilla matches nothing and in a modded game matches whatever + // another mod happens to call that - see the prefab-name audit. + return ZNetScene.instance.GetPrefab(GammeltrollPrefab); } private static IEnumerable ItemsOf(Humanoid h)