using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; namespace DataServer.Data.Entities; /// /// Defines a sprite sheet uploaded to the CDN /// [Table("mob_sprite_sheets")] public class MobSpriteSheet { [Key] public int Id { get; set; } /// Friendly name for admin UI [Required, MaxLength(64)] public string Name { get; set; } = ""; /// CDN path (e.g., "textures/mobs/skeleton.png") [Required, MaxLength(256)] public string CdnPath { get; set; } = ""; /// Total width of the sprite sheet in pixels public int SheetWidth { get; set; } = 512; /// Total height of the sprite sheet in pixels public int SheetHeight { get; set; } = 512; /// Width of each frame in pixels public int FrameWidth { get; set; } = 64; /// Height of each frame in pixels public int FrameHeight { get; set; } = 64; /// Number of columns in the sheet (calculated from width/frameWidth) [NotMapped] public int Columns => SheetWidth / FrameWidth; /// Number of rows in the sheet [NotMapped] public int Rows => SheetHeight / FrameHeight; /// Total number of frames [NotMapped] public int TotalFrames => 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? Animations { get; set; } } /// /// Defines a named animation using frames from a sprite sheet /// [Table("mob_animation_definitions")] public class MobAnimationDefinition { [Key] public int Id { get; set; } /// Which sprite sheet this animation uses public int SpriteSheetId { get; set; } [ForeignKey(nameof(SpriteSheetId))] public MobSpriteSheet? SpriteSheet { get; set; } /// Animation key (e.g., "walk_left", "attack_down", "idle", "cast") [Required, MaxLength(64)] public string Key { get; set; } = ""; /// Friendly name for admin [MaxLength(64)] public string? Name { get; set; } /// /// Comma-separated list of frame indices (0-based) /// e.g., "0,1,2,3" or "8,9,10,11,10,9" for ping-pong /// Frames are numbered left-to-right, top-to-bottom /// [Required, MaxLength(256)] public string FrameSequence { get; set; } = "0"; /// Frames per second public float Fps { get; set; } = 8f; /// Whether the animation loops public bool Loop { get; set; } = true; /// Optional: flip horizontally (for reusing left as right) public bool FlipX { get; set; } = false; /// Optional: flip vertically public bool FlipY { get; set; } = false; public bool IsEnabled { get; set; } = true; /// Parse frame sequence into array of ints [NotMapped] public int[] Frames => string.IsNullOrEmpty(FrameSequence) ? new[] { 0 } : FrameSequence.Split(',').Select(s => int.TryParse(s.Trim(), out var n) ? n : 0).ToArray(); } /// /// Links a mob to its animations - which animations from which sheets it uses /// [Table("mob_animation_assignments")] public class MobAnimationAssignment { [Key] public int Id { get; set; } /// Which mob this animation is for public int MobDefinitionId { get; set; } [ForeignKey(nameof(MobDefinitionId))] public DungeonMobDefinition? MobDefinition { get; set; } /// Which animation definition to use public int AnimationDefinitionId { get; set; } [ForeignKey(nameof(AnimationDefinitionId))] public MobAnimationDefinition? AnimationDefinition { get; set; } /// /// Override key for this mob (e.g., map "walk" to specific directional animation) /// If null, uses the animation's original key /// [MaxLength(64)] public string? OverrideKey { get; set; } /// Priority when multiple animations match (higher = preferred) public int Priority { get; set; } = 0; public bool IsEnabled { get; set; } = true; } /// /// Maps ability to animation for a specific mob /// [Table("mob_ability_animation_mappings")] public class MobAbilityAnimationMapping { [Key] public int Id { get; set; } /// The mob-ability assignment this mapping is for public int AbilityAssignmentId { get; set; } [ForeignKey(nameof(AbilityAssignmentId))] public MobAbilityAssignment? AbilityAssignment { get; set; } /// /// Animation key to play when this ability is used /// This should match one of the mob's assigned animations /// [Required, MaxLength(64)] public string AnimationKey { get; set; } = "attack"; /// Optional: specific direction variant (down, up, left, right) [MaxLength(16)] public string? DirectionSuffix { get; set; } }