Files
systemrevivalserver/data/entities/TileMap.cs
T
2025-12-27 22:34:29 -05:00

315 lines
9.3 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace DataServer.Data.Entities;
/// <summary>
/// A tilemap sprite sheet uploaded to CDN
/// </summary>
[Table("tilemap_sheets")]
public class TileMapSheet
{
[Key]
public int Id { get; set; }
/// <summary>Friendly name (e.g., "Dungeon Stone Set", "Cave Tiles")</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>CDN path (e.g., "textures/tilemaps/dungeon_stone.png")</summary>
[Required, MaxLength(256)]
public string CdnPath { get; set; } = "";
/// <summary>Tags for categorization (e.g., "dungeon,stone,dark")</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Total width of sprite sheet in pixels</summary>
public int SheetWidth { get; set; } = 512;
/// <summary>Total height of sprite sheet in pixels</summary>
public int SheetHeight { get; set; } = 512;
/// <summary>Width of each tile in pixels</summary>
public int TileWidth { get; set; } = 32;
/// <summary>Height of each tile in pixels (for isometric, often 16 or TileWidth/2)</summary>
public int TileHeight { get; set; } = 32;
/// <summary>Number of columns in sheet</summary>
[NotMapped]
public int Columns => TileWidth > 0 ? SheetWidth / TileWidth : 1;
/// <summary>Number of rows in sheet</summary>
[NotMapped]
public int Rows => TileHeight > 0 ? SheetHeight / TileHeight : 1;
/// <summary>Total tile count</summary>
[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<TileDefinition>? Tiles { get; set; }
}
/// <summary>
/// Definition of a single tile within a tilemap sheet
/// </summary>
[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; }
/// <summary>Frame index in the sheet (0-based, left-to-right, top-to-bottom)</summary>
public int FrameIndex { get; set; }
/// <summary>Optional name for this specific tile</summary>
[MaxLength(64)]
public string? Name { get; set; }
/// <summary>Tile type for game logic</summary>
public TileType Type { get; set; } = TileType.Floor;
/// <summary>Tags for filtering/selection (e.g., "stone,cracked,corner_nw")</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Whether entities can walk on this tile</summary>
public bool IsWalkable { get; set; } = true;
/// <summary>Whether projectiles can pass through</summary>
public bool BlocksProjectiles { get; set; } = false;
/// <summary>Whether this blocks line of sight</summary>
public bool BlocksLineOfSight { get; set; } = false;
/// <summary>Layer for rendering order (0=ground, 1=floor decor, 2=walls, 3=ceiling)</summary>
public int RenderLayer { get; set; } = 0;
/// <summary>Z-index within the layer</summary>
public int ZIndex { get; set; } = 0;
public bool IsEnabled { get; set; } = true;
}
/// <summary>
/// Types of tiles for game logic
/// </summary>
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
}
/// <summary>
/// A room template that can be placed in dungeons
/// </summary>
[Table("room_templates")]
public class RoomTemplate
{
[Key]
public int Id { get; set; }
/// <summary>Name of this room template</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>Description of the room</summary>
[MaxLength(512)]
public string? Description { get; set; }
/// <summary>Tags for categorization (e.g., "entrance,large,treasure")</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Room type for generation logic</summary>
public RoomType Type { get; set; } = RoomType.Normal;
/// <summary>Width in tiles</summary>
public int Width { get; set; } = 10;
/// <summary>Height in tiles</summary>
public int Height { get; set; } = 10;
/// <summary>Minimum dungeon tier this room can appear in</summary>
public int MinTier { get; set; } = 1;
/// <summary>Maximum dungeon tier (0 = no max)</summary>
public int MaxTier { get; set; } = 0;
/// <summary>Spawn weight for random selection (higher = more common)</summary>
public int Weight { get; set; } = 100;
/// <summary>JSON data containing tile placements</summary>
[Column(TypeName = "json")]
public string? TileDataJson { get; set; }
/// <summary>JSON data containing spawn points</summary>
[Column(TypeName = "json")]
public string? SpawnPointsJson { get; set; }
/// <summary>JSON data for connection points (where hallways can attach)</summary>
[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;
}
/// <summary>
/// Types of rooms for generation logic
/// </summary>
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
}
/// <summary>
/// A complete dungeon template (optional - for hand-crafted dungeons)
/// </summary>
[Table("dungeon_templates")]
public class DungeonTemplate
{
[Key]
public int Id { get; set; }
/// <summary>Name of this dungeon</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>Description</summary>
[MaxLength(512)]
public string? Description { get; set; }
/// <summary>Tags for categorization</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Dungeon tier (difficulty)</summary>
public int Tier { get; set; } = 1;
/// <summary>Total width in tiles</summary>
public int Width { get; set; } = 100;
/// <summary>Total height in tiles</summary>
public int Height { get; set; } = 100;
/// <summary>If true, this is a complete hand-crafted dungeon. If false, it's generation parameters.</summary>
public bool IsHandCrafted { get; set; } = false;
/// <summary>JSON containing full tile data (for hand-crafted)</summary>
[Column(TypeName = "json")]
public string? TileDataJson { get; set; }
/// <summary>JSON containing room placements (for hand-crafted or as hints for generation)</summary>
[Column(TypeName = "json")]
public string? RoomPlacementsJson { get; set; }
/// <summary>JSON containing generation parameters (room counts, weights, etc.)</summary>
[Column(TypeName = "json")]
public string? GenerationParamsJson { get; set; }
/// <summary>Default tilemap sheet to use</summary>
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;
}
/// <summary>
/// Helper class for tile placement data (serialized to JSON)
/// </summary>
public class TilePlacement
{
public int X { get; set; }
public int Y { get; set; }
public int TileDefinitionId { get; set; }
public int Layer { get; set; } = 0;
/// <summary>Optional rotation (0, 90, 180, 270)</summary>
public int Rotation { get; set; } = 0;
/// <summary>Optional flip X</summary>
public bool FlipX { get; set; } = false;
/// <summary>Optional flip Y</summary>
public bool FlipY { get; set; } = false;
}
/// <summary>
/// Helper class for spawn point data (serialized to JSON)
/// </summary>
public class SpawnPoint
{
public int X { get; set; }
public int Y { get; set; }
public TileType Type { get; set; }
/// <summary>Optional specific mob/item ID to spawn</summary>
public int? EntityId { get; set; }
/// <summary>Tags for filtering what can spawn here</summary>
public string? Tags { get; set; }
}
/// <summary>
/// Helper class for room connection points (where hallways attach)
/// </summary>
public class ConnectionPoint
{
public int X { get; set; }
public int Y { get; set; }
/// <summary>Direction this connection faces (north, south, east, west)</summary>
public string Direction { get; set; } = "north";
/// <summary>Width of the connection (for wider hallways)</summary>
public int Width { get; set; } = 1;
}