Dungeon Builder p5
This commit is contained in:
@@ -290,11 +290,17 @@ public class DungeonGeneratorV2
|
||||
if (worldX >= 0 && worldX < MapWidth && worldY >= 0 && worldY < MapHeight)
|
||||
{
|
||||
layout.Tiles[worldX, worldY] = p.TileDefinitionId;
|
||||
|
||||
// Look up tile definition for sheet info
|
||||
var tileDef = _tileDefinitions.GetValueOrDefault(p.TileDefinitionId);
|
||||
|
||||
layout.TileDetails.Add(new PlacedTile
|
||||
{
|
||||
X = worldX,
|
||||
Y = worldY,
|
||||
TileDefinitionId = p.TileDefinitionId,
|
||||
SheetId = tileDef?.TileMapSheetId ?? 0,
|
||||
FrameIndex = tileDef?.FrameIndex ?? 0,
|
||||
Layer = p.Layer,
|
||||
Rotation = p.Rotation,
|
||||
FlipX = p.FlipX,
|
||||
@@ -360,12 +366,14 @@ public class DungeonGeneratorV2
|
||||
{
|
||||
layout.Tiles[x, y] = floorId > 0 ? floorId : 1; // 1 = walkable but no visual
|
||||
|
||||
if (floorId > 0)
|
||||
if (floorId > 0 && floorTile != null)
|
||||
{
|
||||
layout.TileDetails.Add(new PlacedTile
|
||||
{
|
||||
X = x, Y = y,
|
||||
TileDefinitionId = floorId,
|
||||
SheetId = floorTile.TileMapSheetId,
|
||||
FrameIndex = floorTile.FrameIndex,
|
||||
Layer = 0
|
||||
});
|
||||
}
|
||||
@@ -386,21 +394,23 @@ public class DungeonGeneratorV2
|
||||
|
||||
var floorTile = _tileDefinitions.Values.FirstOrDefault(t => t.Type == TileType.Floor);
|
||||
int floorId = floorTile?.Id ?? 1;
|
||||
int sheetId = floorTile?.TileMapSheetId ?? 0;
|
||||
int frameIndex = floorTile?.FrameIndex ?? 0;
|
||||
|
||||
// L-shaped corridor
|
||||
if (_rng.Next(2) == 0)
|
||||
{
|
||||
CarveHorizontalCorridor(layout, x, targetX, y, floorId);
|
||||
CarveVerticalCorridor(layout, y, targetY, targetX, floorId);
|
||||
CarveHorizontalCorridor(layout, x, targetX, y, floorId, sheetId, frameIndex);
|
||||
CarveVerticalCorridor(layout, y, targetY, targetX, floorId, sheetId, frameIndex);
|
||||
}
|
||||
else
|
||||
{
|
||||
CarveVerticalCorridor(layout, y, targetY, x, floorId);
|
||||
CarveHorizontalCorridor(layout, x, targetX, targetY, floorId);
|
||||
CarveVerticalCorridor(layout, y, targetY, x, floorId, sheetId, frameIndex);
|
||||
CarveHorizontalCorridor(layout, x, targetX, targetY, floorId, sheetId, frameIndex);
|
||||
}
|
||||
}
|
||||
|
||||
private void CarveHorizontalCorridor(DungeonLayoutV2 layout, int x1, int x2, int y, int floorId)
|
||||
private void CarveHorizontalCorridor(DungeonLayoutV2 layout, int x1, int x2, int y, int floorId, int sheetId, int frameIndex)
|
||||
{
|
||||
int minX = Math.Min(x1, x2);
|
||||
int maxX = Math.Max(x1, x2);
|
||||
@@ -415,14 +425,21 @@ public class DungeonGeneratorV2
|
||||
layout.Tiles[x, ty] = floorId;
|
||||
if (floorId > 1)
|
||||
{
|
||||
layout.TileDetails.Add(new PlacedTile { X = x, Y = ty, TileDefinitionId = floorId, Layer = 0 });
|
||||
layout.TileDetails.Add(new PlacedTile
|
||||
{
|
||||
X = x, Y = ty,
|
||||
TileDefinitionId = floorId,
|
||||
SheetId = sheetId,
|
||||
FrameIndex = frameIndex,
|
||||
Layer = 0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void CarveVerticalCorridor(DungeonLayoutV2 layout, int y1, int y2, int x, int floorId)
|
||||
private void CarveVerticalCorridor(DungeonLayoutV2 layout, int y1, int y2, int x, int floorId, int sheetId, int frameIndex)
|
||||
{
|
||||
int minY = Math.Min(y1, y2);
|
||||
int maxY = Math.Max(y1, y2);
|
||||
@@ -437,7 +454,14 @@ public class DungeonGeneratorV2
|
||||
layout.Tiles[tx, y] = floorId;
|
||||
if (floorId > 1)
|
||||
{
|
||||
layout.TileDetails.Add(new PlacedTile { X = tx, Y = y, TileDefinitionId = floorId, Layer = 0 });
|
||||
layout.TileDetails.Add(new PlacedTile
|
||||
{
|
||||
X = tx, Y = y,
|
||||
TileDefinitionId = floorId,
|
||||
SheetId = sheetId,
|
||||
FrameIndex = frameIndex,
|
||||
Layer = 0
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -545,6 +569,8 @@ public class PlacedTile
|
||||
public int X { get; set; }
|
||||
public int Y { get; set; }
|
||||
public int TileDefinitionId { get; set; }
|
||||
public int SheetId { get; set; } // For client rendering
|
||||
public int FrameIndex { get; set; } // Frame in the sheet
|
||||
public int Layer { get; set; }
|
||||
public int Rotation { get; set; }
|
||||
public bool FlipX { get; set; }
|
||||
|
||||
@@ -741,6 +741,39 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
session.CurrentDungeonId = dungeonId;
|
||||
session.PlayerInstance = player;
|
||||
|
||||
// Build visual tile data if V2 layout available
|
||||
object? tileSheets = null;
|
||||
object? visualTiles = null;
|
||||
|
||||
if (instance.LayoutV2 != null && instance.LayoutV2.TileDetails.Count > 0)
|
||||
{
|
||||
tileSheets = instance.LayoutV2.TileMapSheets.Select(s => new
|
||||
{
|
||||
id = s.Id,
|
||||
path = s.CdnPath,
|
||||
tileW = s.TileWidth,
|
||||
tileH = s.TileHeight,
|
||||
sheetW = s.SheetWidth,
|
||||
sheetH = s.SheetHeight,
|
||||
cols = s.Columns
|
||||
});
|
||||
|
||||
visualTiles = instance.LayoutV2.TileDetails.Select(t => new
|
||||
{
|
||||
x = t.X,
|
||||
y = t.Y,
|
||||
tid = t.TileDefinitionId,
|
||||
sid = t.SheetId,
|
||||
frame = t.FrameIndex,
|
||||
l = t.Layer,
|
||||
r = t.Rotation,
|
||||
fx = t.FlipX,
|
||||
fy = t.FlipY
|
||||
});
|
||||
|
||||
_log.LogInformation("Sending {TileCount} visual tiles to client", instance.LayoutV2.TileDetails.Count);
|
||||
}
|
||||
|
||||
await SendAsync(connection, DungeonOpCodes.DUNGEON_ENTER_RESULT, new
|
||||
{
|
||||
ok = true,
|
||||
@@ -781,7 +814,10 @@ public sealed partial class DungeonHandler : IClientMessageHandler
|
||||
x = p.X,
|
||||
y = p.Y,
|
||||
type = p.Type.ToString().ToLower()
|
||||
})
|
||||
}),
|
||||
// V2 visual tile data
|
||||
tileSheets,
|
||||
visualTiles
|
||||
}, ct);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user