Files
systemrevivalserver/data/entities/DungeonBuilder.cs
T
2026-01-09 07:08:41 -05:00

660 lines
21 KiB
C#

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
// =============================================================================
/// <summary>
/// A reusable tile template (single tile or multi-tile pattern)
/// Examples: "Stone Floor", "Corner Wall NE", "2x2 Pillar", "3x1 Bookshelf"
/// </summary>
[Table("tile_templates")]
public class TileTemplate
{
[Key]
public int Id { get; set; }
/// <summary>Template name (e.g., "Stone Floor Clean", "Wall Corner NE")</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>Description</summary>
[MaxLength(256)]
public string? Description { get; set; }
/// <summary>Template category for organization</summary>
public TileTemplateCategory Category { get; set; } = TileTemplateCategory.Floor;
/// <summary>Tags for filtering (e.g., "stone,dungeon,clean")</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Biome this template belongs to</summary>
[MaxLength(32)]
public string? Biome { get; set; }
/// <summary>Width in tiles (for multi-tile templates)</summary>
public int Width { get; set; } = 1;
/// <summary>Height in tiles (for multi-tile templates)</summary>
public int Height { get; set; } = 1;
/// <summary>
/// JSON array of tile placements for this template
/// Format: [{ "x": 0, "y": 0, "tileDefinitionId": 123, "layer": 0 }, ...]
/// </summary>
[Column(TypeName = "json")]
public string? TilesJson { get; set; }
/// <summary>Primary tile definition (for 1x1 templates)</summary>
public int? PrimaryTileDefinitionId { get; set; }
[ForeignKey(nameof(PrimaryTileDefinitionId))]
public TileDefinition? PrimaryTileDefinition { get; set; }
// --- Blocking Properties (derived from constituent tiles or overridden) ---
/// <summary>Override: Can entities walk on this template?</summary>
public bool IsWalkable { get; set; } = true;
/// <summary>Override: Does this block projectiles?</summary>
public bool BlocksProjectiles { get; set; } = false;
/// <summary>Override: Does this block line of sight?</summary>
public bool BlocksLineOfSight { get; set; } = false;
/// <summary>Override: Does this block movement?</summary>
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
/// <summary>North edge socket type (LEGACY - use SocketConfigJson)</summary>
public SocketType SocketN { get; set; } = SocketType.Open;
/// <summary>East edge socket type (LEGACY - use SocketConfigJson)</summary>
public SocketType SocketE { get; set; } = SocketType.Open;
/// <summary>South edge socket type (LEGACY - use SocketConfigJson)</summary>
public SocketType SocketS { get; set; } = SocketType.Open;
/// <summary>West edge socket type (LEGACY - use SocketConfigJson)</summary>
public SocketType SocketW { get; set; } = SocketType.Open;
/// <summary>Custom socket names (LEGACY - use SocketConfigJson)</summary>
[MaxLength(128)]
public string? SocketCustom { get; set; }
/// <summary>
/// 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.
/// </summary>
[Column(TypeName = "json")]
public string? SocketConfigJson { get; set; }
// --- Generation Weight ---
/// <summary>Weight for random selection (higher = more likely)</summary>
public int Weight { get; set; } = 100;
/// <summary>Minimum tier this can appear in</summary>
public int MinTier { get; set; } = 1;
/// <summary>Maximum tier (0 = no limit)</summary>
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;
}
/// <summary>
/// Categories for tile templates
/// </summary>
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
}
/// <summary>
/// An object that can be placed on tiles (furniture, containers, traps, etc.)
/// Enhanced version of DungeonObjectDefinition with more features
/// </summary>
[Table("object_templates")]
public class ObjectTemplate
{
[Key]
public int Id { get; set; }
/// <summary>Object name (e.g., "Wooden Chest", "Stone Pillar", "Spike Trap")</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>Description</summary>
[MaxLength(256)]
public string? Description { get; set; }
/// <summary>Object type category</summary>
public ObjectTemplateType Type { get; set; } = ObjectTemplateType.Decoration;
/// <summary>Tags for filtering</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Biome this object belongs to</summary>
[MaxLength(32)]
public string? Biome { get; set; }
// --- Sprite Configuration ---
/// <summary>Sprite sheet ID</summary>
public int? SpriteSheetId { get; set; }
[ForeignKey(nameof(SpriteSheetId))]
public TileMapSheet? SpriteSheet { get; set; }
/// <summary>Frame index in sprite sheet (for static objects)</summary>
public int FrameIndex { get; set; } = 0;
/// <summary>CDN path for standalone sprite</summary>
[MaxLength(256)]
public string? SpritePath { get; set; }
// --- Size & Position ---
/// <summary>Width in tiles</summary>
public int Width { get; set; } = 1;
/// <summary>Height in tiles</summary>
public int Height { get; set; } = 1;
/// <summary>Pixel offset X for precise positioning</summary>
public int OffsetX { get; set; } = 0;
/// <summary>Pixel offset Y for precise positioning</summary>
public int OffsetY { get; set; } = 0;
/// <summary>Z-index for rendering order</summary>
public int ZIndex { get; set; } = 10;
// --- Blocking Properties ---
/// <summary>Does this object block movement?</summary>
public bool BlocksMovement { get; set; } = false;
/// <summary>Does this object block projectiles?</summary>
public bool BlocksProjectiles { get; set; } = false;
/// <summary>Does this object block line of sight?</summary>
public bool BlocksLineOfSight { get; set; } = false;
/// <summary>
/// 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
/// </summary>
[Column(TypeName = "json")]
public string? BlockedCellsJson { get; set; }
// --- Animation ---
/// <summary>Is this object animated?</summary>
public bool IsAnimated { get; set; } = false;
/// <summary>Number of animation frames</summary>
public int AnimationFrameCount { get; set; } = 1;
/// <summary>Animation frames per second</summary>
public float AnimationFps { get; set; } = 8.0f;
/// <summary>Does the animation loop?</summary>
public bool AnimationLoops { get; set; } = true;
// --- Animation States (for objects with multiple states) ---
/// <summary>
/// JSON object defining animation states
/// Format: { "idle": { "startFrame": 0, "frameCount": 4, "fps": 8 },
/// "open": { "startFrame": 4, "frameCount": 3, "fps": 12 }, ... }
/// </summary>
[Column(TypeName = "json")]
public string? AnimationStatesJson { get; set; }
/// <summary>Default animation state name</summary>
[MaxLength(32)]
public string? DefaultState { get; set; } = "idle";
// --- Interaction ---
/// <summary>Can this object be interacted with (clicked)?</summary>
public bool IsInteractable { get; set; } = false;
/// <summary>Is this triggered by walking onto it?</summary>
public bool TriggeredByWalk { get; set; } = false;
/// <summary>Interaction type</summary>
public ObjectInteractionType InteractionType { get; set; } = ObjectInteractionType.None;
/// <summary>Animation state to play on interaction</summary>
[MaxLength(32)]
public string? InteractionState { get; set; }
/// <summary>Cooldown between interactions (seconds, 0 = one-time)</summary>
public float InteractionCooldown { get; set; } = 0;
/// <summary>Does interaction require a specific item?</summary>
public int? RequiredItemId { get; set; }
// --- Loot / Rewards ---
/// <summary>Loot table for containers</summary>
public int? LootTableId { get; set; }
/// <summary>Gold amount for treasure</summary>
public int GoldAmount { get; set; } = 0;
/// <summary>XP reward</summary>
public int XpReward { get; set; } = 0;
// --- Destructible ---
/// <summary>Can this object be destroyed?</summary>
public bool IsDestructible { get; set; } = false;
/// <summary>Health if destructible</summary>
public int Health { get; set; } = 0;
/// <summary>Animation state when destroyed</summary>
[MaxLength(32)]
public string? DestroyedState { get; set; }
/// <summary>Loot table when destroyed</summary>
public int? DestroyedLootTableId { get; set; }
// --- Trap / Hazard ---
/// <summary>Damage dealt (for traps/hazards)</summary>
public int Damage { get; set; } = 0;
/// <summary>Damage type key</summary>
[MaxLength(32)]
public string? DamageTypeKey { get; set; }
/// <summary>Trigger delay in seconds</summary>
public float TriggerDelay { get; set; } = 0;
/// <summary>Reset time after triggering (0 = doesn't reset)</summary>
public float ResetTime { get; set; } = 0;
// --- Generation ---
/// <summary>Weight for random selection</summary>
public int Weight { get; set; } = 100;
/// <summary>Minimum tier</summary>
public int MinTier { get; set; } = 1;
/// <summary>Maximum tier (0 = no limit)</summary>
public int MaxTier { get; set; } = 0;
/// <summary>Maximum count per room (0 = unlimited)</summary>
public int MaxPerRoom { get; set; } = 0;
/// <summary>Valid placement types (floor, wall, ceiling, etc.)</summary>
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;
}
/// <summary>
/// Object template types
/// </summary>
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
}
/// <summary>
/// Where objects can be placed
/// </summary>
[Flags]
public enum ObjectPlacement
{
Floor = 1,
Wall = 2,
Ceiling = 4,
Water = 8,
Pit = 16,
Any = Floor | Wall | Ceiling
}
/// <summary>
/// A room template built from tile templates and objects
/// This is the main building block for dungeon generation
/// </summary>
[Table("builder_room_templates")]
public class BuilderRoomTemplate
{
[Key]
public int Id { get; set; }
/// <summary>Room name</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>Description</summary>
[MaxLength(256)]
public string? Description { get; set; }
/// <summary>Room type</summary>
public RoomType Type { get; set; } = RoomType.Normal;
/// <summary>Tags for filtering</summary>
[MaxLength(256)]
public string? Tags { get; set; }
/// <summary>Biome</summary>
[MaxLength(32)]
public string? Biome { get; set; }
/// <summary>Width in tiles</summary>
public int Width { get; set; } = 10;
/// <summary>Height in tiles</summary>
public int Height { get; set; } = 10;
// --- Tile Data ---
/// <summary>
/// JSON 2D array of tile template IDs
/// Format: [[1,1,1],[1,0,1],[1,1,1]] where 0 = empty, >0 = TileTemplate.Id
/// </summary>
[Column(TypeName = "json")]
public string? TileGridJson { get; set; }
/// <summary>
/// Alternative: JSON array of tile placements with more detail
/// Format: [{ "x": 0, "y": 0, "templateId": 5, "rotation": 0 }, ...]
/// </summary>
[Column(TypeName = "json")]
public string? TilePlacementsJson { get; set; }
// --- Object Placements ---
/// <summary>
/// JSON array of object placements
/// Format: [{ "x": 5, "y": 3, "objectTemplateId": 12, "state": "idle" }, ...]
/// </summary>
[Column(TypeName = "json")]
public string? ObjectPlacementsJson { get; set; }
// --- Connection Points ---
/// <summary>
/// JSON array of connection points (where hallways attach)
/// Format: [{ "x": 5, "y": 0, "direction": "north", "width": 3 }, ...]
/// </summary>
[Column(TypeName = "json")]
public string? ConnectionPointsJson { get; set; }
// --- Spawn Points ---
/// <summary>
/// JSON array of mob spawn points
/// Format: [{ "x": 3, "y": 4, "mobType": "normal", "count": 2 }, ...]
/// </summary>
[Column(TypeName = "json")]
public string? MobSpawnsJson { get; set; }
/// <summary>
/// JSON array of item spawn points
/// Format: [{ "x": 5, "y": 5, "lootTableId": 3 }, ...]
/// </summary>
[Column(TypeName = "json")]
public string? ItemSpawnsJson { get; set; }
/// <summary>Player spawn point (for entrance rooms)</summary>
public int? PlayerSpawnX { get; set; }
public int? PlayerSpawnY { get; set; }
/// <summary>Exit portal location (for exit rooms)</summary>
public int? ExitPortalX { get; set; }
public int? ExitPortalY { get; set; }
// --- Generation Settings ---
/// <summary>Weight for random selection</summary>
public int Weight { get; set; } = 100;
/// <summary>Minimum tier</summary>
public int MinTier { get; set; } = 1;
/// <summary>Maximum tier (0 = no limit)</summary>
public int MaxTier { get; set; } = 0;
/// <summary>Required connections (minimum number of doors/hallways)</summary>
public int MinConnections { get; set; } = 1;
/// <summary>Maximum connections</summary>
public int MaxConnections { get; set; } = 4;
/// <summary>Can this room be rotated during generation?</summary>
public bool AllowRotation { get; set; } = true;
/// <summary>Can this room be mirrored during generation?</summary>
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;
}
/// <summary>
/// A dungeon palette - collection of compatible templates for generation
/// </summary>
[Table("dungeon_palettes")]
public class DungeonPalette
{
[Key]
public int Id { get; set; }
/// <summary>Palette name (e.g., "Stone Dungeon", "Cave System", "Castle")</summary>
[Required, MaxLength(64)]
public string Name { get; set; } = "";
/// <summary>Description</summary>
[MaxLength(256)]
public string? Description { get; set; }
/// <summary>Biome</summary>
[MaxLength(32)]
public string? Biome { get; set; }
/// <summary>Tags</summary>
[MaxLength(256)]
public string? Tags { get; set; }
// --- Template Collections (JSON arrays of IDs) ---
/// <summary>Floor tile template IDs</summary>
[Column(TypeName = "json")]
public string? FloorTemplateIdsJson { get; set; }
/// <summary>Wall tile template IDs</summary>
[Column(TypeName = "json")]
public string? WallTemplateIdsJson { get; set; }
/// <summary>Door tile template IDs</summary>
[Column(TypeName = "json")]
public string? DoorTemplateIdsJson { get; set; }
/// <summary>Decoration object template IDs</summary>
[Column(TypeName = "json")]
public string? DecorationIdsJson { get; set; }
/// <summary>Container object template IDs</summary>
[Column(TypeName = "json")]
public string? ContainerIdsJson { get; set; }
/// <summary>Trap object template IDs</summary>
[Column(TypeName = "json")]
public string? TrapIdsJson { get; set; }
/// <summary>Room template IDs</summary>
[Column(TypeName = "json")]
public string? RoomTemplateIdsJson { get; set; }
// --- Generation Parameters ---
/// <summary>Default room count range</summary>
public int MinRooms { get; set; } = 5;
public int MaxRooms { get; set; } = 15;
/// <summary>Room size range</summary>
public int MinRoomWidth { get; set; } = 6;
public int MaxRoomWidth { get; set; } = 20;
public int MinRoomHeight { get; set; } = 6;
public int MaxRoomHeight { get; set; } = 20;
/// <summary>Corridor width range</summary>
public int MinCorridorWidth { get; set; } = 3;
public int MaxCorridorWidth { get; set; } = 5;
/// <summary>Decoration density (0-100)</summary>
public int DecorationDensity { get; set; } = 30;
/// <summary>Trap density (0-100)</summary>
public int TrapDensity { get; set; } = 10;
/// <summary>Container density (0-100)</summary>
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
// =============================================================================
/// <summary>
/// A tile placement within a template or room
/// </summary>
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;
}
/// <summary>
/// An object placement within a room
/// </summary>
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;
/// <summary>Optional override properties</summary>
public string? OverridesJson { get; set; }
}
/// <summary>
/// A mob spawn point in a room
/// </summary>
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;
}
/// <summary>
/// An item spawn point in a room
/// </summary>
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;
}
/// <summary>
/// Animation state definition
/// </summary>
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
}
/// <summary>
/// Blocked cell for multi-tile objects
/// </summary>
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;
}