diff --git a/Game/Dungeon/DungeonHandler.cs b/Game/Dungeon/DungeonHandler.cs index 1f88a20..4a2c33e 100644 --- a/Game/Dungeon/DungeonHandler.cs +++ b/Game/Dungeon/DungeonHandler.cs @@ -226,6 +226,14 @@ public sealed partial class DungeonHandler : IClientMessageHandler } private async Task LoadMobDefinitionsAsync() + { + await RefreshMobCacheAsync(); + } + + /// + /// Refresh mob definitions cache. Call this after mobs are modified in admin. + /// + public async Task RefreshMobCacheAsync() { using var scope = _scopeFactory.CreateScope(); var db = scope.ServiceProvider.GetRequiredService(); @@ -247,26 +255,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler // Count animation assignments for debugging var assignmentCount = await db.Set().CountAsync(); - _log.LogInformation("Found {Count} total mob animation assignments in database", assignmentCount); - - // Log sprite config status - foreach (var mob in mobs) - { - if (_mobSpriteConfigs.TryGetValue(mob.Id, out var config) && !string.IsNullOrEmpty(config)) - { - _log.LogInformation("Mob {Name} (ID:{Id}) has new-format SpriteConfig ({Length} chars): {Preview}", - mob.Name, mob.Id, config.Length, config.Substring(0, Math.Min(200, config.Length))); - } - else if (!string.IsNullOrEmpty(mob.SpriteConfigJson)) - { - _log.LogInformation("Mob {Name} (ID:{Id}) has legacy SpriteConfigJson: {Json}", - mob.Name, mob.Id, mob.SpriteConfigJson.Substring(0, Math.Min(100, mob.SpriteConfigJson.Length))); - } - else - { - _log.LogInformation("Mob {Name} (ID:{Id}) has NO sprite config", mob.Name, mob.Id); - } - } + _log.LogInformation("Refreshed mob cache: {MobCount} mobs, {AssignmentCount} animation assignments", mobs.Count, assignmentCount); } public async Task HandleAsync(int opCode, IConnection connection, ReadOnlyMemory payload, CancellationToken ct) @@ -672,7 +661,28 @@ public sealed partial class DungeonHandler : IClientMessageHandler dungeonId = Guid.NewGuid(); int seed = Random.Shared.Next(); - var layout = DungeonGenerator.Generate(seed, tier); + // Try V2 generator with room templates first + DungeonLayout layout; + DungeonLayoutV2? layoutV2 = null; + + try + { + using var scope = _scopeFactory.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + + var generator = new DungeonGeneratorV2(db, seed, tier); + layoutV2 = await generator.GenerateAsync(); + layout = layoutV2; // V2 extends V1, use directly + + _log.LogInformation("Generated dungeon with V2 generator - {RoomCount} rooms, {TileCount} visual tiles", + layoutV2.Rooms.Count, layoutV2.TileDetails?.Count ?? 0); + } + catch (Exception ex) + { + _log.LogWarning(ex, "V2 dungeon generator failed, falling back to V1"); + layout = DungeonGenerator.Generate(seed, tier); + } + var simulation = new DungeonSimulation(layout, tier, _mobDefinitions, bracketMin, null, _mobSpriteConfigs); instance = new DungeonInstance @@ -686,7 +696,8 @@ public sealed partial class DungeonHandler : IClientMessageHandler LevelBracketMax = bracketMax, CreatorLevel = playerLevel, CreatorCharacterId = session.CharacterId, - CreatorName = session.Character.Name + CreatorName = session.Character.Name, + LayoutV2 = layoutV2 // Store V2 layout for visual tile data }; _dungeons[dungeonId] = instance; diff --git a/Game/Dungeon/DungeonInstance.cs b/Game/Dungeon/DungeonInstance.cs index 9d61227..657c7d7 100644 --- a/Game/Dungeon/DungeonInstance.cs +++ b/Game/Dungeon/DungeonInstance.cs @@ -19,6 +19,9 @@ public class DungeonInstance public ulong CreatorCharacterId { get; set; } public string CreatorName { get; set; } = ""; + // V2 Layout with visual tiles (null if generated with V1) + public DungeonLayoutV2? LayoutV2 { get; set; } + // Auto-join window (5 minutes) public DateTime JoinWindowEnd => CreatedAt.AddMinutes(5); public bool IsJoinWindowOpen => DateTime.UtcNow < JoinWindowEnd;