Breakdown DungeonHandler Monolith to sealed partials

This commit is contained in:
dingo
2026-01-26 14:41:10 -05:00
parent 39920c81a2
commit 73ff3d8694
8 changed files with 1970 additions and 499 deletions
+45
View File
@@ -0,0 +1,45 @@
using System.Linq;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using DataServer.Data;
using DataServer.Data.Entities;
namespace GameServer.Dungeon;
public sealed partial class DungeonHandler
{
private async Task LoadMobDefinitionsAsync()
{
await RefreshMobCacheAsync();
}
/// <summary>
/// Refresh mob definitions cache. Call this after mobs are modified in admin.
/// </summary>
public async Task RefreshMobCacheAsync()
{
using var scope = _scopeFactory.CreateScope();
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
var mobs = await db.Set<DungeonMobDefinition>()
.Where(m => m.IsEnabled)
.ToListAsync();
if (mobs.Count == 0)
{
_log.LogCritical("Dungeon Mobs Table EMPTY");
}
_mobDefinitions = mobs.ToDictionary(m => m.Id);
// Build sprite configs from animation assignments
var spriteConfigBuilder = new MobSpriteConfigBuilder(db);
_mobSpriteConfigs = await spriteConfigBuilder.BuildSpriteConfigsAsync(mobs.Select(m => m.Id));
// Count animation assignments for debugging
var assignmentCount = await db.Set<MobAnimationAssignment>().CountAsync();
_log.LogInformation("Refreshed mob cache: {MobCount} mobs, {AssignmentCount} animation assignments", mobs.Count, assignmentCount);
}
}