Breakdown DungeonHandler Monolith to sealed partials
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user