Merge branch 'fix-frost-troll-and-blister-names'
This commit is contained in:
commit
057ecd2d47
3 changed files with 68 additions and 31 deletions
|
|
@ -31,7 +31,9 @@ namespace RacesOfValheim
|
||||||
/// <summary>The blast, in rising order of nastiness. Both are verified manifest names.</summary>
|
/// <summary>The blast, in rising order of nastiness. Both are verified manifest names.</summary>
|
||||||
private const string EarlyBlast = "BombBlob_Poison_projectile";
|
private const string EarlyBlast = "BombBlob_Poison_projectile";
|
||||||
private const string LateBlast = "BombBlob_PoisonElite_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 earlyDamage;
|
||||||
private static HitData.DamageTypes lateDamage;
|
private static HitData.DamageTypes lateDamage;
|
||||||
|
|
|
||||||
|
|
@ -281,24 +281,19 @@ namespace RacesOfValheim
|
||||||
{
|
{
|
||||||
ZNetView nview = View(nest);
|
ZNetView nview = View(nest);
|
||||||
if (nview == null) return 0;
|
if (nview == null) return 0;
|
||||||
|
return Tally(nview.GetZDO(), nest, out _);
|
||||||
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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Writes down what time has laid and restarts the clock. The owner calls this on a timer so
|
/// Writes down what time has laid. The owner calls this every second so the number the
|
||||||
/// the number the other clients read is never far behind.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static void Settle(Transform nest)
|
public static void Settle(Transform nest)
|
||||||
{
|
{
|
||||||
|
|
@ -306,10 +301,10 @@ namespace RacesOfValheim
|
||||||
if (nview == null || !nview.IsOwner()) return;
|
if (nview == null || !nview.IsOwner()) return;
|
||||||
|
|
||||||
ZDO zdo = nview.GetZDO();
|
ZDO zdo = nview.GetZDO();
|
||||||
int now = Count(nest);
|
int now = Tally(zdo, nest, out long clock);
|
||||||
|
|
||||||
zdo.Set(EggKey, now);
|
zdo.Set(EggKey, now);
|
||||||
zdo.Set(ClockKey, WorldSecond());
|
zdo.Set(ClockKey, clock);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>Takes eggs out of the clutch. All or nothing.</summary>
|
/// <summary>Takes eggs out of the clutch. All or nothing.</summary>
|
||||||
|
|
@ -318,15 +313,53 @@ namespace RacesOfValheim
|
||||||
ZNetView nview = View(nest);
|
ZNetView nview = View(nest);
|
||||||
if (nview == null) return false;
|
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 (have < howMany) return false;
|
||||||
|
|
||||||
if (!nview.IsOwner()) nview.ClaimOwnership();
|
if (!nview.IsOwner()) nview.ClaimOwnership();
|
||||||
nview.GetZDO().Set(EggKey, have - howMany);
|
zdo.Set(EggKey, have - howMany);
|
||||||
nview.GetZDO().Set(ClockKey, WorldSecond());
|
zdo.Set(ClockKey, clock);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 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.
|
||||||
|
/// </summary>
|
||||||
|
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)
|
private static ZNetView View(Transform nest)
|
||||||
{
|
{
|
||||||
ZNetView nview = nest != null ? nest.GetComponent<ZNetView>() : null;
|
ZNetView nview = nest != null ? nest.GetComponent<ZNetView>() : null;
|
||||||
|
|
|
||||||
|
|
@ -14,10 +14,16 @@ namespace RacesOfValheim
|
||||||
/// then the log is the child, and the parent would bring the whole rose along with it.
|
/// 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
|
/// 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.
|
/// 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.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static class TrolGammelLog
|
public static class TrolGammelLog
|
||||||
{
|
{
|
||||||
private const string GammeltrollPrefab = "Gammeltroll";
|
private const string GammeltrollPrefab = "TrollFrost";
|
||||||
|
|
||||||
private static GameObject cachedProjectile;
|
private static GameObject cachedProjectile;
|
||||||
private static float cachedVelocity;
|
private static float cachedVelocity;
|
||||||
|
|
@ -45,7 +51,7 @@ namespace RacesOfValheim
|
||||||
velocity = 0f;
|
velocity = 0f;
|
||||||
|
|
||||||
GameObject troll = FindGammeltroll();
|
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}'");
|
log?.Invoke($"Monster prefab: '{troll.name}'");
|
||||||
|
|
||||||
Humanoid humanoid = troll.GetComponent<Humanoid>();
|
Humanoid humanoid = troll.GetComponent<Humanoid>();
|
||||||
|
|
@ -87,14 +93,10 @@ namespace RacesOfValheim
|
||||||
|
|
||||||
private static GameObject FindGammeltroll()
|
private static GameObject FindGammeltroll()
|
||||||
{
|
{
|
||||||
GameObject exact = ZNetScene.instance.GetPrefab(GammeltrollPrefab);
|
// Exact name only. The old fallback took the first Humanoid with "gammel" anywhere in
|
||||||
if (exact != null) return exact;
|
// its name, which in vanilla matches nothing and in a modded game matches whatever
|
||||||
foreach (GameObject prefab in ZNetScene.instance.m_prefabs)
|
// another mod happens to call that - see the prefab-name audit.
|
||||||
{
|
return ZNetScene.instance.GetPrefab(GammeltrollPrefab);
|
||||||
if (prefab != null && prefab.name.ToLowerInvariant().Contains("gammel") && prefab.GetComponent<Humanoid>() != null)
|
|
||||||
return prefab;
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static IEnumerable<GameObject> ItemsOf(Humanoid h)
|
private static IEnumerable<GameObject> ItemsOf(Humanoid h)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue