Normalize mob visual state before join/state payloads and clarify client animation handling

- Add server-side payload-time normalization to prevent alive mobs from being sent with dead/hurt animations

- Enforce dead state/death animation payload consistency for non-alive mobs

- Apply normalization in both dungeon enter flows and recurring dungeon state sends

- Update pending-clientChanges.md: client must treat currentAnimation as authoritative and gate loot prompt by hasLoot
This commit is contained in:
dingo
2026-02-09 10:29:47 -05:00
parent 8256b01fa4
commit ab8afd4ec1
3 changed files with 40 additions and 1 deletions
+1
View File
@@ -333,6 +333,7 @@ public sealed partial class DungeonHandler
instance.Simulation.Players[session.CharacterId] = player;
instance.LastPlayerActivity = DateTime.UtcNow;
NormalizeMobVisualStateForPayload(instance.Simulation);
session.State = PlayerState.InDungeon;
session.CurrentDungeonId = instance.Id;
+33
View File
@@ -120,6 +120,37 @@ public sealed partial class DungeonHandler : IClientMessageHandler
}
}
private static void NormalizeMobVisualStateForPayload(DungeonSimulation sim)
{
foreach (var mob in sim.Mobs.Values)
{
if (mob.IsAlive)
{
if (mob.State == MobState.Dead)
{
mob.State = MobState.Idle;
}
if (string.IsNullOrWhiteSpace(mob.CurrentAnimation) ||
mob.CurrentAnimation.StartsWith("death_", StringComparison.OrdinalIgnoreCase) ||
mob.CurrentAnimation.StartsWith("hurt_", StringComparison.OrdinalIgnoreCase))
{
mob.CurrentAnimation = mob.GetDirectionalAnimation("idle");
}
}
else
{
mob.Health = 0;
mob.State = MobState.Dead;
if (string.IsNullOrWhiteSpace(mob.CurrentAnimation) ||
!mob.CurrentAnimation.StartsWith("death_", StringComparison.OrdinalIgnoreCase))
{
mob.CurrentAnimation = mob.GetDirectionalAnimation("death");
}
}
}
}
public IReadOnlyCollection<int> SupportedOpCodes => new[]
{
DungeonOpCodes.HUB_STATE,
@@ -706,6 +737,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
// Update last activity
instance.LastPlayerActivity = DateTime.UtcNow;
NormalizeMobVisualStateForPayload(instance.Simulation);
var layout2 = instance.Simulation.Layout;
@@ -2799,6 +2831,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
if (dungeon == null) return;
var sim = dungeon.Simulation;
NormalizeMobVisualStateForPayload(sim);
var selfPlayer = sim.Players.GetValueOrDefault(session.CharacterId);
bool spatialFiltering = _spatialStateFilterEnabled && selfPlayer != null;
bool sendSpatialThisTick = !spatialFiltering ||
+6 -1
View File
@@ -1,7 +1,7 @@
# Pending Client Changes
## Status
One client-side update is still required for corpse interaction UX.
Two client-side updates are still required for animation/loot interaction consistency.
## Required Client Update
1. Gate loot prompt (`E`) by `hasLoot`.
@@ -11,6 +11,11 @@ One client-side update is still required for corpse interaction UX.
- `hasLoot == true`
- Hide loot interaction if `hasLoot == false` (corpse remains, but not lootable).
2. Treat `currentAnimation` as authoritative on mob update.
- Server now sends `currentAnimation` on join/state payloads.
- On each update for an existing mob entity, client should apply server animation directly.
- Do not keep a previous local animation state when server sends a different value.
## Notes
1. Server now includes `isAlive`/`hasLoot`/`currentAnimation` consistently in mob payloads and sends `mobCatalog` on dungeon-enter responses and one-time in dungeon state.
2. If invisible mobs still occur, keep a fallback render path when `spriteConfig` is null: