Dungeon and Crafting
This commit is contained in:
@@ -226,6 +226,14 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
}
|
||||
|
||||
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>();
|
||||
@@ -247,26 +255,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
|
||||
// Count animation assignments for debugging
|
||||
var assignmentCount = await db.Set<MobAnimationAssignment>().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<byte> 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<GameDbContext>();
|
||||
|
||||
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;
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user