diff --git a/Services/Admin/Pages/DungeonBuilder/Index.cshtml b/Services/Admin/Pages/DungeonBuilder/Index.cshtml new file mode 100644 index 0000000..87763f8 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/Index.cshtml @@ -0,0 +1,208 @@ +@page "/admin/dungeonbuilder" +@model DungeonBuilder.IndexModel +@{ + ViewData["Title"] = "Dungeon Builder"; +} + +
+

Dungeon Builder

+

Visual tools for creating dungeon content

+
+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} + + +
+
+
@Model.TileTemplateCount
+
Tile Templates
+
+
+
@Model.ObjectTemplateCount
+
Object Templates
+
+
+
@Model.RoomTemplateCount
+
Room Templates
+
+
+
@Model.PaletteCount
+
Dungeon Palettes
+
+
+ + +
+ + + +
+
+ 🧱 +
+
+

Tile Templates

+

Create reusable floor, wall, and door patterns

+
+ • Single tiles or multi-tile patterns
+ • Socket configuration for matching
+ • Walkability and blocking settings +
+
+
+
+ + + +
+
+ 🏺 +
+
+

Object Templates

+

Design furniture, containers, traps, and decorations

+
+ • Animation states
+ • Interaction settings
+ • Loot and rewards +
+
+
+
+ + + +
+
+ 🗺️ +
+
+

Room Templates

+

Build complete rooms with tiles, objects, and spawns

+
+ • Visual room editor
+ • Connection points
+ • Mob and item spawns +
+
+
+
+ + + +
+
+ 🎨 +
+
+

Dungeon Palettes

+

Combine templates into themed dungeon sets

+
+ • Template collections
+ • Generation parameters
+ • Biome configuration +
+
+
+
+ + + +
+
+ 🖼️ +
+
+

Sprite Sheets

+

Manage tilemap sprite sheets and tile definitions

+
+ • Upload sprite sheets
+ • Tag individual tiles
+ • Define tile properties +
+
+
+
+ + + +
+
+ 🧪 +
+
+

Test Generator

+

Preview dungeon generation with your templates

+
+ • Generate test dungeons
+ • Visual preview
+ • Adjust parameters +
+
+
+
+
+ + +
+

Recent Templates

+ +
+ + + + + + + + + + + + @foreach (var item in Model.RecentItems) + { + + + + + + + + } + @if (!Model.RecentItems.Any()) + { + + + + } + +
TypeNameBiomeUpdatedActions
+ + @item.Type + + @item.Name@(item.Biome ?? "-")@item.UpdatedAt.ToString("MMM d, HH:mm") + Edit +
+ No templates created yet. Start by creating a tile or object template! +
+
+
+ +@functions { + string GetTypeColor(string type) + { + return type switch + { + "Tile" => "bg-blue-500/20 text-blue-400", + "Object" => "bg-purple-500/20 text-purple-400", + "Room" => "bg-green-500/20 text-green-400", + "Palette" => "bg-yellow-500/20 text-yellow-400", + _ => "bg-gray-500/20 text-gray-400" + }; + } +} diff --git a/Services/Admin/Pages/DungeonBuilder/Index.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/Index.cshtml.cs new file mode 100644 index 0000000..45120e9 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/Index.cshtml.cs @@ -0,0 +1,105 @@ +using DataServer.Data; +using DataServer.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Server.Services.Admin.Pages.DungeonBuilder; + +public class IndexModel : AdminPageModel +{ + private readonly GameDbContext _db; + + public IndexModel(GameDbContext db) + { + _db = db; + } + + public int TileTemplateCount { get; set; } + public int ObjectTemplateCount { get; set; } + public int RoomTemplateCount { get; set; } + public int PaletteCount { get; set; } + + public List RecentItems { get; set; } = new(); + + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync() + { + // Get counts + TileTemplateCount = await _db.TileTemplates.CountAsync(); + ObjectTemplateCount = await _db.ObjectTemplates.CountAsync(); + RoomTemplateCount = await _db.BuilderRoomTemplates.CountAsync(); + PaletteCount = await _db.DungeonPalettes.CountAsync(); + + // Get recent items (combined from all types) + var recentTiles = await _db.TileTemplates + .OrderByDescending(t => t.UpdatedAt) + .Take(3) + .Select(t => new RecentItem + { + Type = "Tile", + Name = t.Name, + Biome = t.Biome, + UpdatedAt = t.UpdatedAt, + EditUrl = $"/admin/dungeonbuilder/tiles/edit?id={t.Id}" + }) + .ToListAsync(); + + var recentObjects = await _db.ObjectTemplates + .OrderByDescending(t => t.UpdatedAt) + .Take(3) + .Select(t => new RecentItem + { + Type = "Object", + Name = t.Name, + Biome = t.Biome, + UpdatedAt = t.UpdatedAt, + EditUrl = $"/admin/dungeonbuilder/objects/edit?id={t.Id}" + }) + .ToListAsync(); + + var recentRooms = await _db.BuilderRoomTemplates + .OrderByDescending(t => t.UpdatedAt) + .Take(3) + .Select(t => new RecentItem + { + Type = "Room", + Name = t.Name, + Biome = t.Biome, + UpdatedAt = t.UpdatedAt, + EditUrl = $"/admin/dungeonbuilder/rooms/edit?id={t.Id}" + }) + .ToListAsync(); + + var recentPalettes = await _db.DungeonPalettes + .OrderByDescending(t => t.UpdatedAt) + .Take(2) + .Select(t => new RecentItem + { + Type = "Palette", + Name = t.Name, + Biome = t.Biome, + UpdatedAt = t.UpdatedAt, + EditUrl = $"/admin/dungeonbuilder/palettes/edit?id={t.Id}" + }) + .ToListAsync(); + + RecentItems = recentTiles + .Concat(recentObjects) + .Concat(recentRooms) + .Concat(recentPalettes) + .OrderByDescending(x => x.UpdatedAt) + .Take(10) + .ToList(); + } + + public class RecentItem + { + public string Type { get; set; } = ""; + public string Name { get; set; } = ""; + public string? Biome { get; set; } + public DateTime UpdatedAt { get; set; } + public string EditUrl { get; set; } = ""; + } +} diff --git a/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml b/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml new file mode 100644 index 0000000..8722b1e --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml @@ -0,0 +1,385 @@ +@page "/admin/dungeonbuilder/objects/edit" +@model DungeonBuilder.ObjectEditModel +@using DataServer.Data.Entities +@{ + ViewData["Title"] = Model.Object.Id == 0 ? "New Object Template" : $"Edit: {Model.Object.Name}"; + var types = Enum.GetValues(); + var interactionTypes = Enum.GetValues(); + var placementTypes = Enum.GetValues(); +} + + + +

@ViewData["Title"]

+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} + +
+ @Html.AntiForgeryToken() + + +
+ + +
+
+

Basic Settings

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ +
+ + +
+
+
+ +
+

Size & Blocking

+ +
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+ + +
+
+
+
+ + +
+
+

Sprite

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+
+ + +
+ Select a sprite to preview +
+ + + +
+ +
+

Animation

+ +
+
+ + +
+ +
+
+
+ + +
+
+ + +
+
+ +
+ + +
+ +
+ + +
+
+
+
+
+ + +
+
+

Interaction

+ +
+
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+ + +
+
+
+ +
+

Loot & Rewards

+ +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+

Trap / Hazard

+ +
+
+
+ + +
+
+ + +
+
+ +
+
+ + +
+
+ + +
+
+
+
+ +
+

Generation

+ +
+
+ + +
+ +
+
+ + +
+
+ + +
+
+
+
+
+
+ +
+ Cancel + +
+
+ + diff --git a/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs new file mode 100644 index 0000000..62c3290 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/ObjectEdit.cshtml.cs @@ -0,0 +1,170 @@ +using DataServer.Data; +using DataServer.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Server.Services.Admin.Pages.DungeonBuilder; + +public class ObjectEditModel : AdminPageModel +{ + private readonly GameDbContext _db; + private readonly IConfiguration _config; + + public ObjectEditModel(GameDbContext db, IConfiguration config) + { + _db = db; + _config = config; + } + + [BindProperty] + public ObjectTemplate Object { get; set; } = new(); + + public List SpriteSheets { get; set; } = new(); + public List LootTables { get; set; } = new(); + public List DamageTypes { get; set; } = new(); + public List CdnImages { get; set; } = new(); + + public string CdnBaseUrl => _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? ""; + + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync(int? id) + { + await LoadReferenceData(); + + if (id.HasValue) + { + var obj = await _db.ObjectTemplates + .Include(o => o.SpriteSheet) + .FirstOrDefaultAsync(o => o.Id == id.Value); + + if (obj != null) + { + Object = obj; + } + } + else + { + // Defaults for new object + Object.IsEnabled = true; + Object.Weight = 100; + Object.Width = 1; + Object.Height = 1; + Object.AnimationFps = 8.0f; + Object.AnimationFrameCount = 1; + Object.AnimationLoops = true; + } + } + + public async Task OnPostAsync() + { + await LoadReferenceData(); + + if (!ModelState.IsValid) + { + IsError = true; + Message = "Please fix validation errors."; + return Page(); + } + + Object.UpdatedAt = DateTime.UtcNow; + + if (Object.Id == 0) + { + Object.CreatedAt = DateTime.UtcNow; + _db.ObjectTemplates.Add(Object); + Message = "Object template created!"; + } + else + { + var existing = await _db.ObjectTemplates.FindAsync(Object.Id); + if (existing == null) + { + IsError = true; + Message = "Object not found."; + return Page(); + } + + // Update properties + existing.Name = Object.Name; + existing.Description = Object.Description; + existing.Type = Object.Type; + existing.Tags = Object.Tags; + existing.Biome = Object.Biome; + existing.SpriteSheetId = Object.SpriteSheetId; + existing.FrameIndex = Object.FrameIndex; + existing.SpritePath = Object.SpritePath; + existing.Width = Object.Width; + existing.Height = Object.Height; + existing.OffsetX = Object.OffsetX; + existing.OffsetY = Object.OffsetY; + existing.ZIndex = Object.ZIndex; + existing.BlocksMovement = Object.BlocksMovement; + existing.BlocksProjectiles = Object.BlocksProjectiles; + existing.BlocksLineOfSight = Object.BlocksLineOfSight; + existing.BlockedCellsJson = Object.BlockedCellsJson; + existing.IsAnimated = Object.IsAnimated; + existing.AnimationFrameCount = Object.AnimationFrameCount; + existing.AnimationFps = Object.AnimationFps; + existing.AnimationLoops = Object.AnimationLoops; + existing.AnimationStatesJson = Object.AnimationStatesJson; + existing.DefaultState = Object.DefaultState; + existing.IsInteractable = Object.IsInteractable; + existing.TriggeredByWalk = Object.TriggeredByWalk; + existing.InteractionType = Object.InteractionType; + existing.InteractionState = Object.InteractionState; + existing.InteractionCooldown = Object.InteractionCooldown; + existing.RequiredItemId = Object.RequiredItemId; + existing.LootTableId = Object.LootTableId; + existing.GoldAmount = Object.GoldAmount; + existing.XpReward = Object.XpReward; + existing.IsDestructible = Object.IsDestructible; + existing.Health = Object.Health; + existing.DestroyedState = Object.DestroyedState; + existing.DestroyedLootTableId = Object.DestroyedLootTableId; + existing.Damage = Object.Damage; + existing.DamageTypeKey = Object.DamageTypeKey; + existing.TriggerDelay = Object.TriggerDelay; + existing.ResetTime = Object.ResetTime; + existing.Weight = Object.Weight; + existing.MinTier = Object.MinTier; + existing.MaxTier = Object.MaxTier; + existing.MaxPerRoom = Object.MaxPerRoom; + existing.Placement = Object.Placement; + existing.IsEnabled = Object.IsEnabled; + existing.UpdatedAt = DateTime.UtcNow; + + Message = "Changes saved!"; + } + + await _db.SaveChangesAsync(); + + return RedirectToPage(new { id = Object.Id }); + } + + private async Task LoadReferenceData() + { + SpriteSheets = await _db.TileMapSheets + .Where(s => s.IsEnabled) + .OrderBy(s => s.Name) + .ToListAsync(); + + LootTables = await _db.DungeonLootTables + .Where(t => t.IsEnabled) + .OrderBy(t => t.Name) + .ToListAsync(); + + DamageTypes = await _db.DamageResistanceTypes + .OrderBy(d => d.Name) + .ToListAsync(); + } + + public string GetCdnUrl(string? path) + { + if (string.IsNullOrEmpty(path)) return ""; + var baseUrl = CdnBaseUrl; + if (!baseUrl.EndsWith("/downloads")) baseUrl += "/downloads"; + return $"{baseUrl}/{path.TrimStart('/')}"; + } +} diff --git a/Services/Admin/Pages/DungeonBuilder/Objects.cshtml b/Services/Admin/Pages/DungeonBuilder/Objects.cshtml new file mode 100644 index 0000000..e7ad607 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/Objects.cshtml @@ -0,0 +1,175 @@ +@page "/admin/dungeonbuilder/objects" +@model DungeonBuilder.ObjectsModel +@using DataServer.Data.Entities +@{ + ViewData["Title"] = "Object Templates"; + var types = Enum.GetValues(); +} + + + +
+
+

Object Templates

+

Furniture, containers, traps, and decorations

+
+ + New Object +
+ +@if (!string.IsNullOrEmpty(Model.Message)) +{ +
+ @Model.Message +
+} + + +
+
+
+ +
+ + + + Clear +
+
+ + +
+ @foreach (var obj in Model.Objects) + { +
+
+ +
+ @if (obj.SpriteSheetId.HasValue && obj.SpriteSheet != null) + { + var cols = obj.SpriteSheet.TileWidth > 0 ? obj.SpriteSheet.SheetWidth / obj.SpriteSheet.TileWidth : 1; + var row = obj.FrameIndex / cols; + var col = obj.FrameIndex % cols; + var bgX = -col * obj.SpriteSheet.TileWidth; + var bgY = -row * obj.SpriteSheet.TileHeight; + var imgUrl = Model.GetCdnUrl(obj.SpriteSheet.CdnPath); + +
+ } + else if (!string.IsNullOrEmpty(obj.SpritePath)) + { + @obj.Name + } + else + { + 📦 + } +
+ + +
+

@obj.Name

+
+ @obj.Type + @if (!string.IsNullOrEmpty(obj.Biome)) + { + @obj.Biome + } +
+ + +
+ @if (obj.IsInteractable) + { + Interactive + } + @if (obj.TriggeredByWalk) + { + Walk Trigger + } + @if (obj.IsAnimated) + { + Animated + } + @if (obj.BlocksMovement) + { + Solid + } +
+
+
+ +
+ ID: @obj.Id +
+ Edit +
+ + +
+
+
+
+ } + + @if (!Model.Objects.Any()) + { +
+ No object templates found. Create one! +
+ } +
+ + +@if (Model.TotalPages > 1) +{ +
+ @for (int i = 1; i <= Model.TotalPages; i++) + { + + @i + + } +
+} + +@functions { + string GetTypeColor(ObjectTemplateType type) + { + return type switch + { + ObjectTemplateType.Decoration => "text-gray-400", + ObjectTemplateType.Furniture => "text-blue-400", + ObjectTemplateType.Container => "text-yellow-400", + ObjectTemplateType.Obstacle => "text-orange-400", + ObjectTemplateType.Trap => "text-red-400", + ObjectTemplateType.Hazard => "text-red-500", + ObjectTemplateType.Door => "text-purple-400", + ObjectTemplateType.Switch => "text-cyan-400", + ObjectTemplateType.Portal => "text-pink-400", + ObjectTemplateType.Shrine => "text-green-400", + ObjectTemplateType.Vendor => "text-emerald-400", + ObjectTemplateType.Light => "text-yellow-300", + ObjectTemplateType.Spawner => "text-orange-500", + _ => "text-gray-400" + }; + } +} diff --git a/Services/Admin/Pages/DungeonBuilder/Objects.cshtml.cs b/Services/Admin/Pages/DungeonBuilder/Objects.cshtml.cs new file mode 100644 index 0000000..d5f6a08 --- /dev/null +++ b/Services/Admin/Pages/DungeonBuilder/Objects.cshtml.cs @@ -0,0 +1,103 @@ +using DataServer.Data; +using DataServer.Data.Entities; +using Microsoft.AspNetCore.Mvc; +using Microsoft.EntityFrameworkCore; + +namespace Server.Services.Admin.Pages.DungeonBuilder; + +public class ObjectsModel : AdminPageModel +{ + private readonly GameDbContext _db; + private readonly IConfiguration _config; + + public ObjectsModel(GameDbContext db, IConfiguration config) + { + _db = db; + _config = config; + } + + public List Objects { get; set; } = new(); + public List Biomes { get; set; } = new(); + + public string? Search { get; set; } + public int? TypeFilter { get; set; } + public string? BiomeFilter { get; set; } + + public int CurrentPage { get; set; } = 1; + public int TotalPages { get; set; } + public int PageSize { get; set; } = 20; + + public string? Message { get; set; } + public bool IsError { get; set; } + + public async Task OnGetAsync(string? search, int? type, string? biome, int page = 1) + { + Search = search; + TypeFilter = type; + BiomeFilter = biome; + CurrentPage = Math.Max(1, page); + + // Get unique biomes + Biomes = await _db.ObjectTemplates + .Where(o => o.Biome != null) + .Select(o => o.Biome!) + .Distinct() + .OrderBy(b => b) + .ToListAsync(); + + // Build query + var query = _db.ObjectTemplates + .Include(o => o.SpriteSheet) + .AsQueryable(); + + if (!string.IsNullOrEmpty(search)) + { + query = query.Where(o => o.Name.Contains(search) || (o.Tags != null && o.Tags.Contains(search))); + } + + if (type.HasValue) + { + query = query.Where(o => o.Type == (ObjectTemplateType)type.Value); + } + + if (!string.IsNullOrEmpty(biome)) + { + query = query.Where(o => o.Biome == biome); + } + + var total = await query.CountAsync(); + TotalPages = (int)Math.Ceiling(total / (double)PageSize); + + Objects = await query + .OrderBy(o => o.Name) + .Skip((CurrentPage - 1) * PageSize) + .Take(PageSize) + .ToListAsync(); + } + + public async Task OnPostDeleteAsync(int id) + { + var obj = await _db.ObjectTemplates.FindAsync(id); + if (obj != null) + { + _db.ObjectTemplates.Remove(obj); + await _db.SaveChangesAsync(); + Message = $"Deleted object template: {obj.Name}"; + } + + return RedirectToPage(); + } + + public string GetCdnUrl(string? path) + { + if (string.IsNullOrEmpty(path)) return ""; + + var baseUrl = _config["Cdn:BaseUrl"]?.TrimEnd('/') ?? ""; + if (!baseUrl.EndsWith("/downloads")) + { + baseUrl += "/downloads"; + } + + return $"{baseUrl}/{path.TrimStart('/')}"; + } +} diff --git a/Services/Admin/Pages/Shared/_Layout.cshtml b/Services/Admin/Pages/Shared/_Layout.cshtml index cfb95ec..36468bc 100644 --- a/Services/Admin/Pages/Shared/_Layout.cshtml +++ b/Services/Admin/Pages/Shared/_Layout.cshtml @@ -166,6 +166,13 @@ Room Templates + + + + + Dungeon Builder + + diff --git a/data/GameDbContext.cs b/data/GameDbContext.cs index 9303883..264e7bd 100644 --- a/data/GameDbContext.cs +++ b/data/GameDbContext.cs @@ -39,6 +39,12 @@ public sealed class GameDbContext : DbContext public DbSet RoomTemplates => Set(); public DbSet DungeonTemplates => Set(); public DbSet DungeonObjects => Set(); + + // Dungeon Builder system + public DbSet TileTemplates => Set(); + public DbSet ObjectTemplates => Set(); + public DbSet BuilderRoomTemplates => Set(); + public DbSet DungeonPalettes => Set(); public DbSet DungeonBeltItems => Set(); public DbSet DeathChests => Set(); diff --git a/data/entities/DungeonBuilder.cs b/data/entities/DungeonBuilder.cs new file mode 100644 index 0000000..27fd220 --- /dev/null +++ b/data/entities/DungeonBuilder.cs @@ -0,0 +1,646 @@ +using System.ComponentModel.DataAnnotations; +using System.ComponentModel.DataAnnotations.Schema; + +namespace DataServer.Data.Entities; + +// ============================================================================= +// DUNGEON BUILDER SYSTEM +// ============================================================================= +// This system provides a visual GUI for building dungeon content: +// 1. Sprite Sheet Management - Upload sheets, tag individual tiles +// 2. Tile Templates - Reusable floor/wall/door configurations +// 3. Object Templates - Multi-tile objects with animations and interactions +// 4. Room Templates - Pre-built room layouts using tiles and objects +// 5. Dungeon Palettes - Collections of compatible templates for generation +// ============================================================================= + +/// +/// A reusable tile template (single tile or multi-tile pattern) +/// Examples: "Stone Floor", "Corner Wall NE", "2x2 Pillar", "3x1 Bookshelf" +/// +[Table("tile_templates")] +public class TileTemplate +{ + [Key] + public int Id { get; set; } + + /// Template name (e.g., "Stone Floor Clean", "Wall Corner NE") + [Required, MaxLength(64)] + public string Name { get; set; } = ""; + + /// Description + [MaxLength(256)] + public string? Description { get; set; } + + /// Template category for organization + public TileTemplateCategory Category { get; set; } = TileTemplateCategory.Floor; + + /// Tags for filtering (e.g., "stone,dungeon,clean") + [MaxLength(256)] + public string? Tags { get; set; } + + /// Biome this template belongs to + [MaxLength(32)] + public string? Biome { get; set; } + + /// Width in tiles (for multi-tile templates) + public int Width { get; set; } = 1; + + /// Height in tiles (for multi-tile templates) + public int Height { get; set; } = 1; + + /// + /// JSON array of tile placements for this template + /// Format: [{ "x": 0, "y": 0, "tileDefinitionId": 123, "layer": 0 }, ...] + /// + [Column(TypeName = "json")] + public string? TilesJson { get; set; } + + /// Primary tile definition (for 1x1 templates) + public int? PrimaryTileDefinitionId { get; set; } + + [ForeignKey(nameof(PrimaryTileDefinitionId))] + public TileDefinition? PrimaryTileDefinition { get; set; } + + // --- Blocking Properties (derived from constituent tiles or overridden) --- + + /// Override: Can entities walk on this template? + public bool IsWalkable { get; set; } = true; + + /// Override: Does this block projectiles? + public bool BlocksProjectiles { get; set; } = false; + + /// Override: Does this block line of sight? + public bool BlocksLineOfSight { get; set; } = false; + + /// Override: Does this block movement? + public bool BlocksMovement { get; set; } = false; + + // --- Socket Configuration (for WFC-style matching) --- + + /// North edge socket type + public SocketType SocketN { get; set; } = SocketType.Open; + + /// East edge socket type + public SocketType SocketE { get; set; } = SocketType.Open; + + /// South edge socket type + public SocketType SocketS { get; set; } = SocketType.Open; + + /// West edge socket type + public SocketType SocketW { get; set; } = SocketType.Open; + + /// Custom socket names (comma-separated for each direction) + [MaxLength(128)] + public string? SocketCustom { get; set; } + + // --- Generation Weight --- + + /// Weight for random selection (higher = more likely) + public int Weight { get; set; } = 100; + + /// Minimum tier this can appear in + public int MinTier { get; set; } = 1; + + /// Maximum tier (0 = no limit) + public int MaxTier { get; set; } = 0; + + public bool IsEnabled { get; set; } = true; + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; +} + +/// +/// Categories for tile templates +/// +public enum TileTemplateCategory +{ + Floor = 0, + Wall = 1, + Door = 2, + Window = 3, + Stairs = 4, + Pit = 5, + Water = 6, + Lava = 7, + Bridge = 8, + Platform = 9, + Decoration = 10 +} + +/// +/// An object that can be placed on tiles (furniture, containers, traps, etc.) +/// Enhanced version of DungeonObjectDefinition with more features +/// +[Table("object_templates")] +public class ObjectTemplate +{ + [Key] + public int Id { get; set; } + + /// Object name (e.g., "Wooden Chest", "Stone Pillar", "Spike Trap") + [Required, MaxLength(64)] + public string Name { get; set; } = ""; + + /// Description + [MaxLength(256)] + public string? Description { get; set; } + + /// Object type category + public ObjectTemplateType Type { get; set; } = ObjectTemplateType.Decoration; + + /// Tags for filtering + [MaxLength(256)] + public string? Tags { get; set; } + + /// Biome this object belongs to + [MaxLength(32)] + public string? Biome { get; set; } + + // --- Sprite Configuration --- + + /// Sprite sheet ID + public int? SpriteSheetId { get; set; } + + [ForeignKey(nameof(SpriteSheetId))] + public TileMapSheet? SpriteSheet { get; set; } + + /// Frame index in sprite sheet (for static objects) + public int FrameIndex { get; set; } = 0; + + /// CDN path for standalone sprite + [MaxLength(256)] + public string? SpritePath { get; set; } + + // --- Size & Position --- + + /// Width in tiles + public int Width { get; set; } = 1; + + /// Height in tiles + public int Height { get; set; } = 1; + + /// Pixel offset X for precise positioning + public int OffsetX { get; set; } = 0; + + /// Pixel offset Y for precise positioning + public int OffsetY { get; set; } = 0; + + /// Z-index for rendering order + public int ZIndex { get; set; } = 10; + + // --- Blocking Properties --- + + /// Does this object block movement? + public bool BlocksMovement { get; set; } = false; + + /// Does this object block projectiles? + public bool BlocksProjectiles { get; set; } = false; + + /// Does this object block line of sight? + public bool BlocksLineOfSight { get; set; } = false; + + /// + /// JSON array of blocked cells relative to origin (for multi-tile objects) + /// Format: [{ "x": 0, "y": 0 }, { "x": 1, "y": 0 }] + /// If null, blocks all cells within Width x Height + /// + [Column(TypeName = "json")] + public string? BlockedCellsJson { get; set; } + + // --- Animation --- + + /// Is this object animated? + public bool IsAnimated { get; set; } = false; + + /// Number of animation frames + public int AnimationFrameCount { get; set; } = 1; + + /// Animation frames per second + public float AnimationFps { get; set; } = 8.0f; + + /// Does the animation loop? + public bool AnimationLoops { get; set; } = true; + + // --- Animation States (for objects with multiple states) --- + + /// + /// JSON object defining animation states + /// Format: { "idle": { "startFrame": 0, "frameCount": 4, "fps": 8 }, + /// "open": { "startFrame": 4, "frameCount": 3, "fps": 12 }, ... } + /// + [Column(TypeName = "json")] + public string? AnimationStatesJson { get; set; } + + /// Default animation state name + [MaxLength(32)] + public string? DefaultState { get; set; } = "idle"; + + // --- Interaction --- + + /// Can this object be interacted with (clicked)? + public bool IsInteractable { get; set; } = false; + + /// Is this triggered by walking onto it? + public bool TriggeredByWalk { get; set; } = false; + + /// Interaction type + public ObjectInteractionType InteractionType { get; set; } = ObjectInteractionType.None; + + /// Animation state to play on interaction + [MaxLength(32)] + public string? InteractionState { get; set; } + + /// Cooldown between interactions (seconds, 0 = one-time) + public float InteractionCooldown { get; set; } = 0; + + /// Does interaction require a specific item? + public int? RequiredItemId { get; set; } + + // --- Loot / Rewards --- + + /// Loot table for containers + public int? LootTableId { get; set; } + + /// Gold amount for treasure + public int GoldAmount { get; set; } = 0; + + /// XP reward + public int XpReward { get; set; } = 0; + + // --- Destructible --- + + /// Can this object be destroyed? + public bool IsDestructible { get; set; } = false; + + /// Health if destructible + public int Health { get; set; } = 0; + + /// Animation state when destroyed + [MaxLength(32)] + public string? DestroyedState { get; set; } + + /// Loot table when destroyed + public int? DestroyedLootTableId { get; set; } + + // --- Trap / Hazard --- + + /// Damage dealt (for traps/hazards) + public int Damage { get; set; } = 0; + + /// Damage type key + [MaxLength(32)] + public string? DamageTypeKey { get; set; } + + /// Trigger delay in seconds + public float TriggerDelay { get; set; } = 0; + + /// Reset time after triggering (0 = doesn't reset) + public float ResetTime { get; set; } = 0; + + // --- Generation --- + + /// Weight for random selection + public int Weight { get; set; } = 100; + + /// Minimum tier + public int MinTier { get; set; } = 1; + + /// Maximum tier (0 = no limit) + public int MaxTier { get; set; } = 0; + + /// Maximum count per room (0 = unlimited) + public int MaxPerRoom { get; set; } = 0; + + /// Valid placement types (floor, wall, ceiling, etc.) + public ObjectPlacement Placement { get; set; } = ObjectPlacement.Floor; + + public bool IsEnabled { get; set; } = true; + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; +} + +/// +/// Object template types +/// +public enum ObjectTemplateType +{ + Decoration = 0, // Pure visual, no interaction + Furniture = 1, // Tables, chairs, beds + Container = 2, // Chests, barrels, crates + Obstacle = 3, // Pillars, rocks, blocking objects + Trap = 4, // Spike traps, pressure plates + Hazard = 5, // Fire, poison pools + Door = 6, // Interactive doors + Switch = 7, // Levers, buttons + Portal = 8, // Teleporters + Shrine = 9, // Buff stations + Vendor = 10, // Shops + Light = 11, // Torches, lamps + Spawner = 12 // Mob spawn points +} + +/// +/// Where objects can be placed +/// +[Flags] +public enum ObjectPlacement +{ + Floor = 1, + Wall = 2, + Ceiling = 4, + Water = 8, + Pit = 16, + Any = Floor | Wall | Ceiling +} + +/// +/// A room template built from tile templates and objects +/// This is the main building block for dungeon generation +/// +[Table("builder_room_templates")] +public class BuilderRoomTemplate +{ + [Key] + public int Id { get; set; } + + /// Room name + [Required, MaxLength(64)] + public string Name { get; set; } = ""; + + /// Description + [MaxLength(256)] + public string? Description { get; set; } + + /// Room type + public RoomType Type { get; set; } = RoomType.Normal; + + /// Tags for filtering + [MaxLength(256)] + public string? Tags { get; set; } + + /// Biome + [MaxLength(32)] + public string? Biome { get; set; } + + /// Width in tiles + public int Width { get; set; } = 10; + + /// Height in tiles + public int Height { get; set; } = 10; + + // --- Tile Data --- + + /// + /// JSON 2D array of tile template IDs + /// Format: [[1,1,1],[1,0,1],[1,1,1]] where 0 = empty, >0 = TileTemplate.Id + /// + [Column(TypeName = "json")] + public string? TileGridJson { get; set; } + + /// + /// Alternative: JSON array of tile placements with more detail + /// Format: [{ "x": 0, "y": 0, "templateId": 5, "rotation": 0 }, ...] + /// + [Column(TypeName = "json")] + public string? TilePlacementsJson { get; set; } + + // --- Object Placements --- + + /// + /// JSON array of object placements + /// Format: [{ "x": 5, "y": 3, "objectTemplateId": 12, "state": "idle" }, ...] + /// + [Column(TypeName = "json")] + public string? ObjectPlacementsJson { get; set; } + + // --- Connection Points --- + + /// + /// JSON array of connection points (where hallways attach) + /// Format: [{ "x": 5, "y": 0, "direction": "north", "width": 3 }, ...] + /// + [Column(TypeName = "json")] + public string? ConnectionPointsJson { get; set; } + + // --- Spawn Points --- + + /// + /// JSON array of mob spawn points + /// Format: [{ "x": 3, "y": 4, "mobType": "normal", "count": 2 }, ...] + /// + [Column(TypeName = "json")] + public string? MobSpawnsJson { get; set; } + + /// + /// JSON array of item spawn points + /// Format: [{ "x": 5, "y": 5, "lootTableId": 3 }, ...] + /// + [Column(TypeName = "json")] + public string? ItemSpawnsJson { get; set; } + + /// Player spawn point (for entrance rooms) + public int? PlayerSpawnX { get; set; } + public int? PlayerSpawnY { get; set; } + + /// Exit portal location (for exit rooms) + public int? ExitPortalX { get; set; } + public int? ExitPortalY { get; set; } + + // --- Generation Settings --- + + /// Weight for random selection + public int Weight { get; set; } = 100; + + /// Minimum tier + public int MinTier { get; set; } = 1; + + /// Maximum tier (0 = no limit) + public int MaxTier { get; set; } = 0; + + /// Required connections (minimum number of doors/hallways) + public int MinConnections { get; set; } = 1; + + /// Maximum connections + public int MaxConnections { get; set; } = 4; + + /// Can this room be rotated during generation? + public bool AllowRotation { get; set; } = true; + + /// Can this room be mirrored during generation? + public bool AllowMirror { get; set; } = true; + + public bool IsEnabled { get; set; } = true; + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; +} + +/// +/// A dungeon palette - collection of compatible templates for generation +/// +[Table("dungeon_palettes")] +public class DungeonPalette +{ + [Key] + public int Id { get; set; } + + /// Palette name (e.g., "Stone Dungeon", "Cave System", "Castle") + [Required, MaxLength(64)] + public string Name { get; set; } = ""; + + /// Description + [MaxLength(256)] + public string? Description { get; set; } + + /// Biome + [MaxLength(32)] + public string? Biome { get; set; } + + /// Tags + [MaxLength(256)] + public string? Tags { get; set; } + + // --- Template Collections (JSON arrays of IDs) --- + + /// Floor tile template IDs + [Column(TypeName = "json")] + public string? FloorTemplateIdsJson { get; set; } + + /// Wall tile template IDs + [Column(TypeName = "json")] + public string? WallTemplateIdsJson { get; set; } + + /// Door tile template IDs + [Column(TypeName = "json")] + public string? DoorTemplateIdsJson { get; set; } + + /// Decoration object template IDs + [Column(TypeName = "json")] + public string? DecorationIdsJson { get; set; } + + /// Container object template IDs + [Column(TypeName = "json")] + public string? ContainerIdsJson { get; set; } + + /// Trap object template IDs + [Column(TypeName = "json")] + public string? TrapIdsJson { get; set; } + + /// Room template IDs + [Column(TypeName = "json")] + public string? RoomTemplateIdsJson { get; set; } + + // --- Generation Parameters --- + + /// Default room count range + public int MinRooms { get; set; } = 5; + public int MaxRooms { get; set; } = 15; + + /// Room size range + public int MinRoomWidth { get; set; } = 6; + public int MaxRoomWidth { get; set; } = 20; + public int MinRoomHeight { get; set; } = 6; + public int MaxRoomHeight { get; set; } = 20; + + /// Corridor width range + public int MinCorridorWidth { get; set; } = 3; + public int MaxCorridorWidth { get; set; } = 5; + + /// Decoration density (0-100) + public int DecorationDensity { get; set; } = 30; + + /// Trap density (0-100) + public int TrapDensity { get; set; } = 10; + + /// Container density (0-100) + public int ContainerDensity { get; set; } = 20; + + public bool IsEnabled { get; set; } = true; + public DateTime CreatedAt { get; set; } = DateTime.UtcNow; + public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; +} + +// ============================================================================= +// HELPER CLASSES FOR JSON SERIALIZATION +// ============================================================================= + +/// +/// A tile placement within a template or room +/// +public class BuilderTilePlacement +{ + public int X { get; set; } + public int Y { get; set; } + public int TemplateId { get; set; } + public int TileDefinitionId { get; set; } + public int Layer { get; set; } = 0; + public int Rotation { get; set; } = 0; // 0, 90, 180, 270 + public bool FlipX { get; set; } = false; + public bool FlipY { get; set; } = false; +} + +/// +/// An object placement within a room +/// +public class BuilderObjectPlacement +{ + public int X { get; set; } + public int Y { get; set; } + public int ObjectTemplateId { get; set; } + public string? State { get; set; } + public int Rotation { get; set; } = 0; + public bool FlipX { get; set; } = false; + + /// Optional override properties + public string? OverridesJson { get; set; } +} + +/// +/// A mob spawn point in a room +/// +public class BuilderMobSpawn +{ + public int X { get; set; } + public int Y { get; set; } + public string Type { get; set; } = "normal"; // normal, elite, boss, miniboss + public int? MobDefinitionId { get; set; } // Specific mob, or null for random from pool + public int Count { get; set; } = 1; + public float SpawnChance { get; set; } = 1.0f; +} + +/// +/// An item spawn point in a room +/// +public class BuilderItemSpawn +{ + public int X { get; set; } + public int Y { get; set; } + public int? LootTableId { get; set; } + public int? ItemDefinitionId { get; set; } + public float SpawnChance { get; set; } = 1.0f; +} + +/// +/// Animation state definition +/// +public class AnimationState +{ + public string Name { get; set; } = ""; + public int StartFrame { get; set; } = 0; + public int FrameCount { get; set; } = 1; + public float Fps { get; set; } = 8.0f; + public bool Loop { get; set; } = true; + public string? NextState { get; set; } // State to transition to after playing +} + +/// +/// Blocked cell for multi-tile objects +/// +public class BlockedCell +{ + public int X { get; set; } + public int Y { get; set; } + public bool BlocksMovement { get; set; } = true; + public bool BlocksProjectiles { get; set; } = false; + public bool BlocksLineOfSight { get; set; } = false; +}