diff --git a/src/RustToDust.Core/GridChassis.cs b/src/RustToDust.Core/GridChassis.cs index e3fd867..fdee366 100644 --- a/src/RustToDust.Core/GridChassis.cs +++ b/src/RustToDust.Core/GridChassis.cs @@ -890,10 +890,12 @@ namespace RustToDust.Core UpdateMountedTelemetry(); } - public void ApplyReplicatedCoreHpRatio(float coreHpRatio) + public void ApplyReplicatedCoreHpRatio(float coreHpRatio, bool alive) { if (MaxCoreHp <= 0f) return; - CoreHp = Math.Clamp(coreHpRatio, 0f, 1f) * MaxCoreHp; + CoreHp = alive + ? MathF.Max(0.01f, Math.Clamp(coreHpRatio, 0f, 1f) * MaxCoreHp) + : 0f; } public void ApplyReplicatedThermal(ReadOnlySpan quantizedCellTemps, ReadOnlySpan mountedTemps, ReadOnlySpan mountedCooldowns) diff --git a/src/RustToDust.Net/RemoteArenaSession.cs b/src/RustToDust.Net/RemoteArenaSession.cs index 5855c80..f5ae410 100644 --- a/src/RustToDust.Net/RemoteArenaSession.cs +++ b/src/RustToDust.Net/RemoteArenaSession.cs @@ -1433,7 +1433,7 @@ namespace RustToDust.Net c.ThrottleCmd = nc.Throttle; c.SteerCmd = nc.Steer; c.MaxThermalRatio = nc.MaxThermalRatio; - c.Grid.ApplyReplicatedCoreHpRatio(nc.CoreHpRatio); + c.Grid.ApplyReplicatedCoreHpRatio(nc.CoreHpRatio, nc.Alive); c.X = nc.Pos.X; c.Y = nc.Pos.Y; c.Z = nc.Pos.Z; c.CurrRotX = nc.Rot.X; c.CurrRotY = nc.Rot.Y; c.CurrRotZ = nc.Rot.Z; c.CurrRotW = nc.Rot.W; c.VelX = nc.Vel.X; c.VelY = nc.Vel.Y; c.VelZ = nc.Vel.Z; diff --git a/tests/RustToDust.Tests/CultNetMultiplayerTests.cs b/tests/RustToDust.Tests/CultNetMultiplayerTests.cs index 20bf461..8e42254 100644 --- a/tests/RustToDust.Tests/CultNetMultiplayerTests.cs +++ b/tests/RustToDust.Tests/CultNetMultiplayerTests.cs @@ -829,6 +829,17 @@ namespace RustToDust.Tests var clientRival = client.ViewState.Contenders[rivalSlot]; float actualRatio = clientRival.Grid.MaxCoreHp > 0f ? clientRival.Grid.CoreHp / clientRival.Grid.MaxCoreHp : 1f; Assert.True(synced, $"Expected remote contender {rivalSlot} CoreHpRatio ~ {expectedRatio:F3}, got {actualRatio:F3}"); + + // Edge case: living rival at 0.30 HP rounds 8-bit CoreHpRatio to 0, yet must remain Alive on remote client + serverRival.Grid.ApplyReplicatedDamage(0, 0, 0f, 20f, 0.30f, serverRival.Grid.HitSequence + 1); + Assert.True(serverRival.Alive); + bool lowHpSynced = PumpUntil(host, new[] { client }, () => + { + var c = client.ViewState.Contenders[rivalSlot]; + return c.Alive && c.Grid.CoreHp > 0f && c.Grid.CoreHp <= 0.5f; + }, ref nowMs, 2500); + Assert.True(lowHpSynced && clientRival.Alive && !clientRival.Grid.IsDestroyed && clientRival.Grid.CoreHp > 0f, + $"Expected living 0.30 HP rival to stay Alive on remote client, got Alive={clientRival.Alive}, CoreHp={clientRival.Grid.CoreHp:F3}"); } private static byte[] EncodeRudpLatestDatagram(byte[] frameBytes, uint sequence) =>