From ab8afd4ec1204c2b1fbce64ace1d22b6cb47d00d Mon Sep 17 00:00:00 2001 From: dingo Date: Mon, 9 Feb 2026 10:29:47 -0500 Subject: [PATCH] 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 --- Game/Dungeon/DungeonHandler.Dungeons.cs | 1 + Game/Dungeon/DungeonHandler.cs | 33 +++++++++++++++++++++++++ pending-clientChanges.md | 7 +++++- 3 files changed, 40 insertions(+), 1 deletion(-) diff --git a/Game/Dungeon/DungeonHandler.Dungeons.cs b/Game/Dungeon/DungeonHandler.Dungeons.cs index 9e9def8..1832447 100644 --- a/Game/Dungeon/DungeonHandler.Dungeons.cs +++ b/Game/Dungeon/DungeonHandler.Dungeons.cs @@ -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; diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 5e926ae..6ceb6cb 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -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 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 || diff --git a/pending-clientChanges.md b/pending-clientChanges.md index 77fbe78..57ff83f 100644 --- a/pending-clientChanges.md +++ b/pending-clientChanges.md @@ -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: