Refresh fix, Dungeon Builder v2
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -670,16 +670,16 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
var generator = new DungeonGeneratorV2(db, seed, tier);
|
||||
var generator = new DungeonGeneratorV3(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",
|
||||
_log.LogInformation("Generated dungeon with V3 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");
|
||||
_log.LogWarning(ex, "V3 dungeon generator failed, falling back to V1");
|
||||
layout = DungeonGenerator.Generate(seed, tier);
|
||||
}
|
||||
|
||||
@@ -744,6 +744,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
// Build visual tile data if V2 layout available
|
||||
object? tileSheets = null;
|
||||
object? visualTiles = null;
|
||||
object? placedObjects = null;
|
||||
|
||||
_log.LogInformation("LayoutV2 is null: {IsNull}, TileDetails count: {Count}",
|
||||
instance.LayoutV2 == null, instance.LayoutV2?.TileDetails?.Count ?? 0);
|
||||
@@ -775,8 +776,28 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
fy = t.FlipY
|
||||
}).ToArray();
|
||||
|
||||
_log.LogInformation("Sending {SheetCount} sheets, {TileCount} visual tiles to client",
|
||||
instance.LayoutV2.TileMapSheets.Count, instance.LayoutV2.TileDetails.Count);
|
||||
// V3: Include placed objects (decorations, containers, traps)
|
||||
if (instance.LayoutV2.Objects?.Count > 0)
|
||||
{
|
||||
placedObjects = instance.LayoutV2.Objects.Select(o => new
|
||||
{
|
||||
x = o.X,
|
||||
y = o.Y,
|
||||
id = o.ObjectTemplateId,
|
||||
name = o.Name,
|
||||
type = o.Type,
|
||||
sheetId = o.SpriteSheetId,
|
||||
frame = o.FrameIndex,
|
||||
blocks = o.BlocksMovement,
|
||||
interact = o.IsInteractable,
|
||||
trap = o.IsTrap,
|
||||
damage = o.TrapDamage,
|
||||
loot = o.LootTableId
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
_log.LogInformation("Sending {SheetCount} sheets, {TileCount} visual tiles, {ObjectCount} objects to client",
|
||||
instance.LayoutV2.TileMapSheets.Count, instance.LayoutV2.TileDetails.Count, instance.LayoutV2.Objects?.Count ?? 0);
|
||||
}
|
||||
|
||||
await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new
|
||||
@@ -820,9 +841,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
y = p.Y,
|
||||
type = p.Type.ToString().ToLower()
|
||||
}),
|
||||
// V2 visual tile data
|
||||
// V3 visual tile data
|
||||
tileSheets,
|
||||
visualTiles
|
||||
visualTiles,
|
||||
placedObjects
|
||||
}, ct);
|
||||
}
|
||||
|
||||
@@ -2152,16 +2174,16 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
var generator = new DungeonGeneratorV2(db, seed, tier);
|
||||
var generator = new DungeonGeneratorV3(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",
|
||||
_log.LogInformation("Generated dungeon with V3 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");
|
||||
_log.LogWarning(ex, "V3 dungeon generator failed, falling back to V1");
|
||||
layout = DungeonGenerator.Generate(seed, tier);
|
||||
}
|
||||
|
||||
@@ -2323,6 +2345,7 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
// Build visual tile data if V2 layout available
|
||||
object? tileSheets = null;
|
||||
object? visualTiles = null;
|
||||
object? placedObjects = null;
|
||||
|
||||
if (instance.LayoutV2 != null && instance.LayoutV2.TileDetails.Count > 0)
|
||||
{
|
||||
@@ -2350,8 +2373,28 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
fy = t.FlipY
|
||||
}).ToArray();
|
||||
|
||||
_log.LogInformation("Sending {SheetCount} sheets, {TileCount} visual tiles to client",
|
||||
instance.LayoutV2.TileMapSheets.Count, instance.LayoutV2.TileDetails.Count);
|
||||
// V3: Include placed objects (decorations, containers, traps)
|
||||
if (instance.LayoutV2.Objects?.Count > 0)
|
||||
{
|
||||
placedObjects = instance.LayoutV2.Objects.Select(o => new
|
||||
{
|
||||
x = o.X,
|
||||
y = o.Y,
|
||||
id = o.ObjectTemplateId,
|
||||
name = o.Name,
|
||||
type = o.Type,
|
||||
sheetId = o.SpriteSheetId,
|
||||
frame = o.FrameIndex,
|
||||
blocks = o.BlocksMovement,
|
||||
interact = o.IsInteractable,
|
||||
trap = o.IsTrap,
|
||||
damage = o.TrapDamage,
|
||||
loot = o.LootTableId
|
||||
}).ToArray();
|
||||
}
|
||||
|
||||
_log.LogInformation("Sending {SheetCount} sheets, {TileCount} visual tiles, {ObjectCount} objects to client",
|
||||
instance.LayoutV2.TileMapSheets.Count, instance.LayoutV2.TileDetails.Count, instance.LayoutV2.Objects?.Count ?? 0);
|
||||
}
|
||||
|
||||
await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new
|
||||
@@ -2402,9 +2445,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
y = p.Y,
|
||||
type = p.Type.ToString().ToLower()
|
||||
}),
|
||||
// V2 visual tile data
|
||||
// V3 visual tile data
|
||||
tileSheets,
|
||||
visualTiles
|
||||
visualTiles,
|
||||
placedObjects
|
||||
}, ct);
|
||||
|
||||
_log.LogInformation("Player {Name} (Level {Level}) joined dungeon {Id}",
|
||||
|
||||
@@ -18,6 +18,33 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
/// </summary>
|
||||
public List<TileMapSheetInfo> TileMapSheets { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Placed objects (decorations, containers, traps)
|
||||
/// </summary>
|
||||
public List<PlacedObject> Objects { get; set; } = new();
|
||||
|
||||
/// <summary>
|
||||
/// Player spawn position
|
||||
/// </summary>
|
||||
public int PlayerSpawnX { get; set; }
|
||||
public int PlayerSpawnY { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Exit portal position
|
||||
/// </summary>
|
||||
public int ExitX { get; set; }
|
||||
public int ExitY { get; set; }
|
||||
|
||||
public DungeonLayoutV2() : base() { }
|
||||
|
||||
public DungeonLayoutV2(int width, int height)
|
||||
{
|
||||
Width = width;
|
||||
Height = height;
|
||||
Tiles = new int[width, height];
|
||||
Walkable = new bool[width, height];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Build tile data optimized for client transmission
|
||||
/// </summary>
|
||||
@@ -31,6 +58,14 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
.Distinct()
|
||||
.ToList();
|
||||
|
||||
// Also add sheets from direct SheetId references
|
||||
var directSheetIds = TileDetails
|
||||
.Where(t => t.SheetId > 0)
|
||||
.Select(t => t.SheetId)
|
||||
.Distinct();
|
||||
sheetIds.AddRange(directSheetIds);
|
||||
sheetIds = sheetIds.Distinct().ToList();
|
||||
|
||||
var sheets = tileDefinitions.Values
|
||||
.Where(t => sheetIds.Contains(t.TileMapSheetId))
|
||||
.Select(t => t.TileMapSheet)
|
||||
@@ -76,7 +111,8 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
height = Height,
|
||||
tileSize = TileSize,
|
||||
tilesRLE = SerializeTilesRLE(),
|
||||
spawn = new { x = SpawnPoint.X, y = SpawnPoint.Y },
|
||||
spawn = new { x = PlayerSpawnX > 0 ? PlayerSpawnX : SpawnPoint.X, y = PlayerSpawnY > 0 ? PlayerSpawnY : SpawnPoint.Y },
|
||||
exit = new { x = ExitX, y = ExitY },
|
||||
rooms = Rooms.Select(r => new
|
||||
{
|
||||
x = r.X, y = r.Y, w = r.Width, h = r.Height,
|
||||
@@ -96,7 +132,23 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
type = c.ChestType.ToString(),
|
||||
roomIndex = c.RoomIndex
|
||||
}),
|
||||
// New: Visual tile data
|
||||
// Objects (decorations, containers, traps)
|
||||
objects = Objects.Select(o => new
|
||||
{
|
||||
x = o.X,
|
||||
y = o.Y,
|
||||
id = o.ObjectTemplateId,
|
||||
name = o.Name,
|
||||
type = o.Type,
|
||||
sheetId = o.SpriteSheetId,
|
||||
frame = o.FrameIndex,
|
||||
blocks = o.BlocksMovement,
|
||||
interact = o.IsInteractable,
|
||||
trap = o.IsTrap,
|
||||
damage = o.TrapDamage,
|
||||
loot = o.LootTableId
|
||||
}),
|
||||
// Tile sheets
|
||||
tileSheets = TileMapSheets.Select(s => new
|
||||
{
|
||||
id = s.Id,
|
||||
@@ -108,11 +160,14 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
cols = s.Columns,
|
||||
rows = s.Rows
|
||||
}),
|
||||
// Visual tile details
|
||||
visualTiles = TileDetails.Select(t => new
|
||||
{
|
||||
x = t.X,
|
||||
y = t.Y,
|
||||
tid = t.TileDefinitionId,
|
||||
sid = t.SheetId,
|
||||
f = t.FrameIndex,
|
||||
l = t.Layer,
|
||||
r = t.Rotation,
|
||||
fx = t.FlipX,
|
||||
@@ -134,10 +189,12 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
height = Height,
|
||||
tileSize = TileSize,
|
||||
tilesRLE = SerializeTilesRLE(),
|
||||
spawn = new { x = SpawnPoint.X, y = SpawnPoint.Y },
|
||||
spawn = new { x = PlayerSpawnX > 0 ? PlayerSpawnX : SpawnPoint.X, y = PlayerSpawnY > 0 ? PlayerSpawnY : SpawnPoint.Y },
|
||||
exit = new { x = ExitX, y = ExitY },
|
||||
rooms = Rooms.Select(r => new { x = r.X, y = r.Y, w = r.Width, h = r.Height, type = r.Type.ToString() }),
|
||||
mobs = MobSpawns.Select(m => new { id = m.Id, x = m.X, y = m.Y, type = m.MobType.ToString() }),
|
||||
chests = ChestSpawns.Select(c => new { id = c.Id, x = c.X, y = c.Y, type = c.ChestType.ToString() })
|
||||
chests = ChestSpawns.Select(c => new { id = c.Id, x = c.X, y = c.Y, type = c.ChestType.ToString() }),
|
||||
objects = Objects.Select(o => new { x = o.X, y = o.Y, id = o.ObjectTemplateId, type = o.Type, blocks = o.BlocksMovement })
|
||||
});
|
||||
}
|
||||
|
||||
@@ -163,6 +220,8 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
x = t.X,
|
||||
y = t.Y,
|
||||
tid = t.TileDefinitionId,
|
||||
sid = t.SheetId,
|
||||
f = t.FrameIndex,
|
||||
l = t.Layer,
|
||||
r = t.Rotation,
|
||||
fx = t.FlipX,
|
||||
@@ -170,6 +229,4 @@ public class DungeonLayoutV2 : DungeonLayout
|
||||
})
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,48 +1,65 @@
|
||||
using DataServer.Data.Entities;
|
||||
using Server.Game.Dungeon;
|
||||
using DataServer.Data.Entities;
|
||||
|
||||
namespace Server.Game.Dungeon
|
||||
namespace Server.Game.Dungeon;
|
||||
|
||||
/// <summary>
|
||||
/// Extended room with template info
|
||||
/// </summary>
|
||||
public class DungeonRoomV2 : DungeonRoom
|
||||
{
|
||||
/// <summary>
|
||||
/// Extended room with template info
|
||||
/// </summary>
|
||||
public class DungeonRoomV2 : DungeonRoom
|
||||
public int? TemplateId { get; set; }
|
||||
public string? TemplateName { get; set; }
|
||||
public HashSet<string> TemplateTags { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public new RoomType Type { get; set; } = RoomType.Normal;
|
||||
|
||||
/// <summary>Connection points parsed from template</summary>
|
||||
public List<ConnectionPoint> ConnectionPoints { get; set; } = new();
|
||||
|
||||
/// <summary>Mob spawns from template (intermediate storage before conversion)</summary>
|
||||
public List<RoomMobSpawn> MobSpawns { get; set; } = new();
|
||||
|
||||
/// <summary>Player spawn position (for entrance rooms)</summary>
|
||||
public int? PlayerSpawnX { get; set; }
|
||||
public int? PlayerSpawnY { get; set; }
|
||||
|
||||
/// <summary>Exit position (for exit rooms)</summary>
|
||||
public int? ExitX { get; set; }
|
||||
public int? ExitY { get; set; }
|
||||
|
||||
public DungeonRoomV2(int x, int y, int width, int height) : base(x, y, width, height) { }
|
||||
|
||||
/// <summary>Get the best connection point for a given direction</summary>
|
||||
public ConnectionPoint? GetConnectionPoint(string direction)
|
||||
{
|
||||
public int? TemplateId { get; set; }
|
||||
public string? TemplateName { get; set; }
|
||||
public HashSet<string> TemplateTags { get; set; } = new(StringComparer.OrdinalIgnoreCase);
|
||||
public new RoomType Type { get; set; } = RoomType.Normal;
|
||||
// First try exact match
|
||||
var exact = ConnectionPoints.FirstOrDefault(c => c.Direction.Equals(direction, StringComparison.OrdinalIgnoreCase));
|
||||
if (exact != null) return exact;
|
||||
|
||||
/// <summary>Connection points parsed from template</summary>
|
||||
public List<ConnectionPoint> ConnectionPoints { get; set; } = new();
|
||||
|
||||
public DungeonRoomV2(int x, int y, int width, int height) : base(x, y, width, height) { }
|
||||
|
||||
/// <summary>Get the best connection point for a given direction</summary>
|
||||
public ConnectionPoint? GetConnectionPoint(string direction)
|
||||
// No exact match - create a default one for this direction
|
||||
return direction.ToLower() switch
|
||||
{
|
||||
// First try exact match
|
||||
var exact = ConnectionPoints.FirstOrDefault(c => c.Direction.Equals(direction, StringComparison.OrdinalIgnoreCase));
|
||||
if (exact != null) return exact;
|
||||
|
||||
// No exact match - create a default one for this direction rather than using wrong direction
|
||||
// This ensures the connection point is actually on the correct edge
|
||||
return direction.ToLower() switch
|
||||
{
|
||||
"north" => new ConnectionPoint { X = Width / 2, Y = 0, Direction = "north", Width = 3 },
|
||||
"south" => new ConnectionPoint { X = Width / 2, Y = Height - 1, Direction = "south", Width = 3 },
|
||||
"east" => new ConnectionPoint { X = Width - 1, Y = Height / 2, Direction = "east", Width = 3 },
|
||||
"west" => new ConnectionPoint { X = 0, Y = Height / 2, Direction = "west", Width = 3 },
|
||||
_ => ConnectionPoints.FirstOrDefault() // Last resort fallback
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Get world position of a connection point</summary>
|
||||
public (int X, int Y) GetConnectionWorldPos(ConnectionPoint cp)
|
||||
{
|
||||
return (X + cp.X, Y + cp.Y);
|
||||
}
|
||||
|
||||
"north" => new ConnectionPoint { X = Width / 2, Y = 0, Direction = "north", Width = 3 },
|
||||
"south" => new ConnectionPoint { X = Width / 2, Y = Height - 1, Direction = "south", Width = 3 },
|
||||
"east" => new ConnectionPoint { X = Width - 1, Y = Height / 2, Direction = "east", Width = 3 },
|
||||
"west" => new ConnectionPoint { X = 0, Y = Height / 2, Direction = "west", Width = 3 },
|
||||
_ => ConnectionPoints.FirstOrDefault()
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>Get world position of a connection point</summary>
|
||||
public (int X, int Y) GetConnectionWorldPos(ConnectionPoint cp)
|
||||
{
|
||||
return (X + cp.X, Y + cp.Y);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Mob spawn point within a room (intermediate type for template data)
|
||||
/// </summary>
|
||||
public class RoomMobSpawn
|
||||
{
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public string Type { get; set; } = "normal";
|
||||
public int Count { get; set; } = 1;
|
||||
}
|
||||
|
||||
@@ -41,7 +41,14 @@ public class LootService
|
||||
public async Task InitializeAsync()
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
await RefreshCacheAsync();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Refresh all loot-related caches (can be called on-demand from admin)
|
||||
/// </summary>
|
||||
public async Task RefreshCacheAsync()
|
||||
{
|
||||
using var scope = _scopeFactory.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<GameDbContext>();
|
||||
|
||||
@@ -95,7 +102,7 @@ public class LootService
|
||||
_itemDefinitions = items.ToDictionary(i => i.Id);
|
||||
|
||||
_initialized = true;
|
||||
_log.LogInformation("LootService initialized: {Tables} tables, {Items} items, {Mappings} mob mappings",
|
||||
_log.LogInformation("LootService cache refreshed: {Tables} tables, {Items} items, {Mappings} mob mappings",
|
||||
_lootTables.Count, _itemDefinitions.Count, mappings.Count);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user