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) --- // NOTE: Legacy socket fields kept for backward compatibility during migration // New code should use SocketConfigJson instead /// North edge socket type (LEGACY - use SocketConfigJson) public SocketType SocketN { get; set; } = SocketType.Open; /// East edge socket type (LEGACY - use SocketConfigJson) public SocketType SocketE { get; set; } = SocketType.Open; /// South edge socket type (LEGACY - use SocketConfigJson) public SocketType SocketS { get; set; } = SocketType.Open; /// West edge socket type (LEGACY - use SocketConfigJson) public SocketType SocketW { get; set; } = SocketType.Open; /// Custom socket names (LEGACY - use SocketConfigJson) [MaxLength(128)] public string? SocketCustom { get; set; } /// /// New socket configuration supporting: /// - Per-direction custom socket names /// - Multiple sockets per edge for multi-tile templates /// /// JSON format: { "north": [...], "east": [...], "south": [...], "west": [...] } /// See SocketConfiguration class for full structure. /// [Column(TypeName = "json")] public string? SocketConfigJson { 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; }