using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace DataServer.Data.Entities; /// /// A tilemap sprite sheet uploaded to CDN /// [Table("tilemap_sheets")] public class TileMapSheet { [Key] public int Id { get; set; } /// Friendly name (e.g., "Dungeon Stone Set", "Cave Tiles") [Required, MaxLength(64)] public string Name { get; set; } = ""; /// CDN path (e.g., "textures/tilemaps/dungeon_stone.png") [Required, MaxLength(256)] public string CdnPath { get; set; } = ""; /// Tags for categorization (e.g., "dungeon,stone,dark") [MaxLength(256)] public string? Tags { get; set; } /// Total width of sprite sheet in pixels public int SheetWidth { get; set; } = 512; /// Total height of sprite sheet in pixels public int SheetHeight { get; set; } = 512; /// Width of each tile in pixels public int TileWidth { get; set; } = 32; /// Height of each tile in pixels (for isometric, often 16 or TileWidth/2) public int TileHeight { get; set; } = 32; /// Number of columns in sheet [NotMapped] public int Columns => TileWidth > 0 ? SheetWidth / TileWidth : 1; /// Number of rows in sheet [NotMapped] public int Rows => TileHeight > 0 ? SheetHeight / TileHeight : 1; /// Total tile count [NotMapped] public int TotalTiles => Columns * Rows; public bool IsEnabled { get; set; } = true; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; // Navigation public ICollection? Tiles { get; set; } } /// /// Socket type for tile edge connections /// public enum SocketType { /// Closed edge - only connects to other Closed edges (walls, void borders) Closed = 0, /// Open edge - only connects to other Open edges (interior floors) Open = 1, /// Custom type - must match exact custom string in SocketCustom field Custom = 2 } /// /// Definition of a single tile within a tilemap sheet /// [Table("tile_definitions")] public class TileDefinition { [Key] public int Id { get; set; } public int TileMapSheetId { get; set; } [ForeignKey(nameof(TileMapSheetId))] public TileMapSheet? TileMapSheet { get; set; } /// Frame index in the sheet (0-based, left-to-right, top-to-bottom) public int FrameIndex { get; set; } /// Optional name for this specific tile [MaxLength(64)] public string? Name { get; set; } /// Tile type for game logic public TileType Type { get; set; } = TileType.Floor; /// Tags for filtering/selection (e.g., "stone,cracked,biome:cave") [MaxLength(256)] public string? Tags { get; set; } /// Whether entities can walk on this tile public bool IsWalkable { get; set; } = true; /// Whether projectiles can pass through public bool BlocksProjectiles { get; set; } = false; /// Whether this blocks line of sight public bool BlocksLineOfSight { get; set; } = false; /// Layer for rendering order (0=ground, 1=floor decor, 2=walls, 3=ceiling) public int RenderLayer { get; set; } = 0; /// Z-index within the layer public int ZIndex { get; set; } = 0; /// Whether this tile is animated public bool IsAnimated { get; set; } = false; /// Number of animation frames (consecutive frames starting at FrameIndex) public int AnimationFrameCount { get; set; } = 1; /// Animation speed in frames per second public float AnimationFps { get; set; } = 8.0f; /// Biome this tile belongs to (e.g., "cave", "dungeon", "forest") [MaxLength(32)] public string? Biome { get; set; } // ========================================================================= // SOCKET SYSTEM - Controls how tiles connect to neighbors // ========================================================================= /// North edge socket type public SocketType SocketN { get; set; } = SocketType.Closed; /// East edge socket type public SocketType SocketE { get; set; } = SocketType.Closed; /// South edge socket type public SocketType SocketS { get; set; } = SocketType.Closed; /// West edge socket type public SocketType SocketW { get; set; } = SocketType.Closed; /// Custom socket type name for North (only used when SocketN = Custom) [MaxLength(32)] public string? SocketNCustom { get; set; } /// Custom socket type name for East (only used when SocketE = Custom) [MaxLength(32)] public string? SocketECustom { get; set; } /// Custom socket type name for South (only used when SocketS = Custom) [MaxLength(32)] public string? SocketSCustom { get; set; } /// Custom socket type name for West (only used when SocketW = Custom) [MaxLength(32)] public string? SocketWCustom { get; set; } public bool IsEnabled { get; set; } = true; // ========================================================================= // HELPER METHODS // ========================================================================= /// Get the effective socket identifier for a direction public string GetSocketId(string direction) { return direction.ToUpperInvariant() switch { "N" or "NORTH" => SocketN == SocketType.Custom ? $"Custom:{SocketNCustom}" : SocketN.ToString(), "E" or "EAST" => SocketE == SocketType.Custom ? $"Custom:{SocketECustom}" : SocketE.ToString(), "S" or "SOUTH" => SocketS == SocketType.Custom ? $"Custom:{SocketSCustom}" : SocketS.ToString(), "W" or "WEST" => SocketW == SocketType.Custom ? $"Custom:{SocketWCustom}" : SocketW.ToString(), _ => "Closed" }; } /// Check if this tile's edge is compatible with another tile's edge public bool IsEdgeCompatible(string thisEdge, TileDefinition other, string otherEdge) { var thisSocket = GetSocketId(thisEdge); var otherSocket = other.GetSocketId(otherEdge); // Exact match required return thisSocket.Equals(otherSocket, StringComparison.OrdinalIgnoreCase); } /// Set all sockets to a given type (useful for bulk operations) public void SetAllSockets(SocketType type, string? customName = null) { SocketN = SocketE = SocketS = SocketW = type; if (type == SocketType.Custom) { SocketNCustom = SocketECustom = SocketSCustom = SocketWCustom = customName; } else { SocketNCustom = SocketECustom = SocketSCustom = SocketWCustom = null; } } /// Auto-configure sockets based on tile type public void AutoConfigureSockets() { switch (Type) { case TileType.Floor: case TileType.FloorDecor: SetAllSockets(SocketType.Open); break; case TileType.Wall: case TileType.WallDecor: SetAllSockets(SocketType.Closed); break; case TileType.Door: // Doors typically open on two sides // Default to vertical door (open N/S, closed E/W) SocketN = SocketType.Open; SocketS = SocketType.Open; SocketE = SocketType.Closed; SocketW = SocketType.Closed; break; default: SetAllSockets(SocketType.Closed); break; } } } /// /// Types of tiles for game logic /// public enum TileType { Floor = 0, Wall = 1, Door = 2, Water = 3, Lava = 4, Pit = 5, Stairs = 6, // Spawn points PlayerSpawn = 10, MobSpawn = 11, BossSpawn = 12, ChestSpawn = 13, // Special Trigger = 20, Transition = 21, Secret = 22, Trap = 23, // Decorative (walkable but with visual interest) FloorDecor = 30, WallDecor = 31 } /// /// A room template that can be placed in dungeons /// [Table("room_templates")] public class RoomTemplate { [Key] public int Id { get; set; } /// Name of this room template [Required, MaxLength(64)] public string Name { get; set; } = ""; /// Description of the room [MaxLength(512)] public string? Description { get; set; } /// Tags for categorization (e.g., "entrance,large,treasure") [MaxLength(256)] public string? Tags { get; set; } /// Room type for generation logic public RoomType Type { get; set; } = RoomType.Normal; /// Width in tiles public int Width { get; set; } = 10; /// Height in tiles public int Height { get; set; } = 10; /// Minimum dungeon tier this room can appear in public int MinTier { get; set; } = 1; /// Maximum dungeon tier (0 = no max) public int MaxTier { get; set; } = 0; /// Spawn weight for random selection (higher = more common) public int Weight { get; set; } = 100; /// JSON data containing tile placements [Column(TypeName = "json")] public string? TileDataJson { get; set; } /// JSON data containing spawn points [Column(TypeName = "json")] public string? SpawnPointsJson { get; set; } /// JSON data for connection points (where hallways can attach) [Column(TypeName = "json")] public string? ConnectionPointsJson { get; set; } public bool IsEnabled { get; set; } = true; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; } /// /// Types of rooms for generation logic /// public enum RoomType { Normal = 0, Entrance = 1, Exit = 2, Boss = 3, Treasure = 4, Secret = 5, Shop = 6, Shrine = 7, Challenge = 8, Hallway = 9, Junction = 10 } /// /// A complete dungeon template (optional - for hand-crafted dungeons) /// [Table("dungeon_templates")] public class DungeonTemplate { [Key] public int Id { get; set; } /// Name of this dungeon [Required, MaxLength(64)] public string Name { get; set; } = ""; /// Description [MaxLength(512)] public string? Description { get; set; } /// Tags for categorization [MaxLength(256)] public string? Tags { get; set; } /// Dungeon tier (difficulty) public int Tier { get; set; } = 1; /// Total width in tiles public int Width { get; set; } = 100; /// Total height in tiles public int Height { get; set; } = 100; /// If true, this is a complete hand-crafted dungeon. If false, it's generation parameters. public bool IsHandCrafted { get; set; } = false; /// JSON containing full tile data (for hand-crafted) [Column(TypeName = "json")] public string? TileDataJson { get; set; } /// JSON containing room placements (for hand-crafted or as hints for generation) [Column(TypeName = "json")] public string? RoomPlacementsJson { get; set; } /// JSON containing generation parameters (room counts, weights, etc.) [Column(TypeName = "json")] public string? GenerationParamsJson { get; set; } /// Default tilemap sheet to use public int? DefaultTileMapSheetId { get; set; } [ForeignKey(nameof(DefaultTileMapSheetId))] public TileMapSheet? DefaultTileMapSheet { get; set; } public bool IsEnabled { get; set; } = true; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; } /// /// Helper class for tile placement data (serialized to JSON) /// public class TilePlacement { public int X { get; set; } public int Y { get; set; } public int TileDefinitionId { get; set; } public int Layer { get; set; } = 0; /// Optional rotation (0, 90, 180, 270) public int Rotation { get; set; } = 0; /// Optional flip X public bool FlipX { get; set; } = false; /// Optional flip Y public bool FlipY { get; set; } = false; } /// /// Helper class for spawn point data (serialized to JSON) /// public class SpawnPoint { public int X { get; set; } public int Y { get; set; } public TileType Type { get; set; } /// Optional specific mob/item ID to spawn public int? EntityId { get; set; } /// Tags for filtering what can spawn here public string? Tags { get; set; } } /// /// Helper class for room connection points (where hallways attach) /// public class ConnectionPoint { public int X { get; set; } public int Y { get; set; } /// Direction this connection faces (north, south, east, west) public string Direction { get; set; } = "north"; /// Width of the connection (for wider hallways) public int Width { get; set; } = 1; } /// /// Definition of a dungeon object (interactable, obstacle, container) /// [Table("dungeon_objects")] public class DungeonObjectDefinition { [Key] public int Id { get; set; } /// Name of this object [Required, MaxLength(64)] public string Name { get; set; } = ""; /// Description [MaxLength(512)] public string? Description { get; set; } /// Object type public DungeonObjectType Type { get; set; } = DungeonObjectType.Decoration; /// Sprite path on CDN [MaxLength(256)] public string? SpritePath { get; set; } /// Sprite ID for shared sprites public int? SpriteId { get; set; } /// Alternative sprite when interacted (e.g., opened chest) [MaxLength(256)] public string? InteractedSpritePath { get; set; } /// Whether this object blocks movement public bool BlocksMovement { get; set; } = false; /// Whether this object blocks projectiles public bool BlocksProjectiles { get; set; } = false; /// Whether this object blocks line of sight public bool BlocksLineOfSight { get; set; } = false; /// Whether this object can be interacted with public bool IsInteractable { get; set; } = false; /// Whether this object can be destroyed public bool IsDestructible { get; set; } = false; /// Health if destructible (0 = instant destroy) public int Health { get; set; } = 0; /// Interaction type (what happens when player interacts) public ObjectInteractionType InteractionType { get; set; } = ObjectInteractionType.None; /// Loot table ID for containers public int? LootTableId { get; set; } /// Tags for filtering/categorization [MaxLength(256)] public string? Tags { get; set; } /// Biome this object belongs to [MaxLength(32)] public string? Biome { get; set; } /// Size in tiles (width) public int Width { get; set; } = 1; /// Size in tiles (height) public int Height { get; set; } = 1; /// Z-index for rendering order public int ZIndex { get; set; } = 0; /// Whether this object is animated public bool IsAnimated { get; set; } = false; /// Animation frame count public int AnimationFrameCount { get; set; } = 1; /// Animation FPS public float AnimationFps { get; set; } = 8.0f; public bool IsEnabled { get; set; } = true; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime UpdatedAt { get; set; } = DateTime.UtcNow; } /// /// Types of dungeon objects /// public enum DungeonObjectType { Decoration = 0, Obstacle = 1, Container = 2, Interactable = 3, Destructible = 4, Door = 5, Trap = 6, Shrine = 7, Vendor = 8 } /// /// Types of object interactions /// public enum ObjectInteractionType { None = 0, OpenContainer = 1, Toggle = 2, Trigger = 3, Teleport = 4, Heal = 5, Buff = 6, Dialogue = 7, Shop = 8 }