diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 6ceb6cb..71b9661 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -2951,6 +2951,32 @@ public sealed partial class DungeonHandler : IClientMessageHandler y = i.Y }), + projectiles = (sendSpatialThisTick ? sim.Projectiles.Values.Where(p => !spatialFiltering || IsNearby(p.X, p.Y)) : Enumerable.Empty()) + .Select(p => new + { + id = p.Id, + sourceType = p.SourceType.ToString().ToLower(), + sourceMobId = p.SourceMobId, + sourcePlayerId = p.SourcePlayerId, + abilityId = p.AbilityId, + x = p.X, + y = p.Y, + targetX = p.TargetX, + targetY = p.TargetY, + velocityX = p.VelocityX, + velocityY = p.VelocityY, + speed = p.Speed, + damage = p.Damage, + damageTypeKey = p.DamageTypeKey, + aoeRadius = p.AoeRadius, + spriteKey = p.SpriteKey, + isLinear = p.IsLinear, + frontX = p.FrontX, + frontY = p.FrontY, + backX = p.BackX, + backY = p.BackY + }), + portals = sim.Portals.Values .Where(p => p.IsActive) .Select(p => new diff --git a/Game/Dungeon/DungeonSimulation.cs b/Game/Dungeon/DungeonSimulation.cs index 60680e0..d1c14b8 100644 --- a/Game/Dungeon/DungeonSimulation.cs +++ b/Game/Dungeon/DungeonSimulation.cs @@ -44,6 +44,8 @@ public partial class DungeonSimulation private readonly List _pendingAbilityEvents = new(); private readonly List _pendingProjectileHitEvents = new(); private readonly List _pendingProjectileExpiredEvents = new(); + private readonly Dictionary _projectileDiagnostics = new(StringComparer.OrdinalIgnoreCase); + private long _lastProjectileDiagnosticsLogTick; private int _nextDroppedItemId = 1; private int _nextMobId = 10000; // Start summoned mobs at high ID to avoid conflicts @@ -735,6 +737,7 @@ public partial class DungeonSimulation } Projectiles[projectile.Id] = projectile; + IncrementProjectileDiagnostic(ability.Key, d => d.Spawned++); } private void UpdateProjectiles() @@ -766,6 +769,7 @@ public partial class DungeonSimulation Y = projectile.Y, Reason = "range" }); + IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.ExpiredRange++); toRemove.Add(projectile.Id); continue; } @@ -864,6 +868,7 @@ public partial class DungeonSimulation X = projectile.X, Y = projectile.Y }); + IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.HitMob++); toRemove.Add(projectile.Id); break; @@ -904,6 +909,7 @@ public partial class DungeonSimulation X = projectile.X, Y = projectile.Y }); + IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.HitPlayer++); toRemove.Add(projectile.Id); break; @@ -926,6 +932,7 @@ public partial class DungeonSimulation Y = projectile.Y, Reason = "wall" }); + IncrementProjectileDiagnostic(ResolveProjectileAbilityKey(projectile), d => d.ExpiredWall++); toRemove.Add(projectile.Id); } } @@ -934,6 +941,50 @@ public partial class DungeonSimulation { Projectiles.TryRemove(id, out _); } + + LogProjectileDiagnosticsIfNeeded(); + } + + private void IncrementProjectileDiagnostic(string abilityKey, Action increment) + { + string key = string.IsNullOrWhiteSpace(abilityKey) ? "unknown" : abilityKey; + if (!_projectileDiagnostics.TryGetValue(key, out var diag)) + { + diag = new ProjectileAbilityDiagnostics(); + _projectileDiagnostics[key] = diag; + } + + increment(diag); + } + + private string ResolveProjectileAbilityKey(ProjectileInstance projectile) + { + if (projectile.AbilityId > 0 && + _abilityDefinitions != null && + _abilityDefinitions.TryGetValue(projectile.AbilityId, out var def)) + { + return string.IsNullOrWhiteSpace(def.Key) ? $"ability_{projectile.AbilityId}" : def.Key; + } + + return projectile.SourceType == ProjectileSource.Player ? "player_projectile" : "mob_projectile"; + } + + private void LogProjectileDiagnosticsIfNeeded() + { + if (CurrentTick - _lastProjectileDiagnosticsLogTick < TicksPerSecond * 5) return; + _lastProjectileDiagnosticsLogTick = CurrentTick; + + if (_projectileDiagnostics.Count == 0) return; + + var parts = _projectileDiagnostics + .OrderBy(kvp => kvp.Key) + .Select(kvp => + { + var d = kvp.Value; + return $"{kvp.Key}: spawned={d.Spawned}, hitP={d.HitPlayer}, hitM={d.HitMob}, expWall={d.ExpiredWall}, expRange={d.ExpiredRange}"; + }); + + Console.WriteLine($"[ProjectileDiag][Tick {CurrentTick}] {string.Join(" | ", parts)}"); } private void ProcessAoeAbility(MobInstance mob, MobAbilityDefinition ability, float targetX, float targetY) @@ -1583,4 +1634,13 @@ public partial class DungeonSimulation return true; } + private sealed class ProjectileAbilityDiagnostics + { + public long Spawned { get; set; } + public long HitPlayer { get; set; } + public long HitMob { get; set; } + public long ExpiredWall { get; set; } + public long ExpiredRange { get; set; } + } + } diff --git a/pending-clientChanges.md b/pending-clientChanges.md index 57ff83f..f5bd1c2 100644 --- a/pending-clientChanges.md +++ b/pending-clientChanges.md @@ -1,7 +1,7 @@ # Pending Client Changes ## Status -Two client-side updates are still required for animation/loot interaction consistency. +Three client-side updates are still required for animation/loot/projectile consistency. ## Required Client Update 1. Gate loot prompt (`E`) by `hasLoot`. @@ -16,6 +16,11 @@ Two client-side updates are still required for animation/loot interaction consis - 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. +3. Render active projectiles from `projectiles` in `DUNGEON_STATE`. +- Server now sends active projectile entities each tick (spatial-filtered). +- Use `x/y`, `velocityX/velocityY`, `spriteKey`, and linear metadata (`isLinear`, `frontX/frontY`, `backX/backY`) for rendering. +- Keep existing `events.projectileHits` / `events.projectileExpired` handling for impact/cleanup effects. + ## 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: