using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using System.Text.Json; using DataServer.Data.Enums; namespace DataServer.Data.Entities; /// /// Monster/NPC template definition stored in database /// [Table("dungeon_mob_definitions")] public class DungeonMobDefinition { [Key] public int Id { get; set; } [Required] [MaxLength(64)] public string Name { get; set; } = ""; [MaxLength(256)] public string Description { get; set; } = ""; public MobType Type { get; set; } = MobType.Normal; public MobCategory Category { get; set; } = MobCategory.Undead; /// /// AI behavior pattern for this mob /// public MobBehavior Behavior { get; set; } = MobBehavior.Aggressive; public int MinTier { get; set; } = 1; // Minimum dungeon tier to spawn public int MaxTier { get; set; } = 99; // Maximum tier (for progression gating) // Base Combat Stats public int BaseHealth { get; set; } = 50; public int BaseMana { get; set; } = 0; public int BasePhysicalDamage { get; set; } = 5; public int BaseMagicDamage { get; set; } = 0; public int BaseArmor { get; set; } = 0; public int BaseMagicResist { get; set; } = 0; /// /// Primary damage type key (references DamageResistanceType.Key) /// e.g., "physical", "fire", "poison" /// [MaxLength(32)] public string DamageTypeKey { get; set; } = "physical"; // Movement & Combat public float MoveSpeed { get; set; } = 60f; public float AttackRange { get; set; } = 40f; // Melee range ~40, ranged 150+ public float AttackSpeed { get; set; } = 1.0f; // Attacks per second public float AggroRange { get; set; } = 150f; // Detection radius public float LeashRange { get; set; } = 400f; // Max chase distance before reset /// /// Preferred combat distance (for ranged/skirmisher behaviors) /// public float PreferredRange { get; set; } = 40f; /// /// Flee threshold - if HP drops below this %, mob may flee (for skirmisher/defensive) /// public float FleeThreshold { get; set; } = 0f; /// /// Call for help radius - alerts nearby mobs when engaged /// public float CallForHelpRadius { get; set; } = 0f; // Scaling per dungeon tier (multipliers) public float HealthPerTier { get; set; } = 1.2f; public float DamagePerTier { get; set; } = 1.15f; public float ArmorPerTier { get; set; } = 1.1f; // Experience & Loot public int BaseXp { get; set; } = 10; public float XpPerTier { get; set; } = 1.25f; public int LootTableId { get; set; } = 0; // Reference to loot_tables public float DropChanceMultiplier { get; set; } = 1.0f; /// /// JSON block for resistances/weaknesses /// Example: {"fire": -0.25, "ice": 0.5, "poison": 1.0} /// Negative = weakness (takes more damage), Positive = resistance (takes less), 1.0 = immune /// [MaxLength(1024)] public string ResistancesJson { get; set; } = "{}"; /// /// JSON block for boss phases (for multi-phase bosses) /// Example: [{"hpThreshold": 0.75, "behavior": "Enrage"}, {"hpThreshold": 0.25, "behavior": "Summoner"}] /// [MaxLength(2048)] public string? PhasesJson { get; set; } // Visuals /// /// JSON configuration for mob sprites and animations /// Structure: { /// "spriteSheet": "textures/mobs/skeleton.png", /// "frameWidth": 64, /// "frameHeight": 64, /// "animations": { /// "idle_down": {"row": 0, "frames": 4, "fps": 4, "loop": true}, /// "idle_up": {"row": 1, "frames": 4, "fps": 4, "loop": true}, /// "idle_left": {"row": 2, "frames": 4, "fps": 4, "loop": true}, /// "idle_right": {"row": 3, "frames": 4, "fps": 4, "loop": true}, /// "walk_down": {"row": 4, "frames": 8, "fps": 8, "loop": true}, /// "walk_up": {"row": 5, "frames": 8, "fps": 8, "loop": true}, /// "walk_left": {"row": 6, "frames": 8, "fps": 8, "loop": true}, /// "walk_right": {"row": 7, "frames": 8, "fps": 8, "loop": true}, /// "attack_down": {"row": 8, "frames": 6, "fps": 12, "loop": false}, /// "attack_up": {"row": 9, "frames": 6, "fps": 12, "loop": false}, /// "attack_left": {"row": 10, "frames": 6, "fps": 12, "loop": false}, /// "attack_right": {"row": 11, "frames": 6, "fps": 12, "loop": false}, /// "cast_down": {"row": 12, "frames": 8, "fps": 10, "loop": false}, /// "death": {"row": 16, "frames": 6, "fps": 8, "loop": false} /// } /// } /// [MaxLength(8192)] public string? SpriteConfigJson { get; set; } /// /// Color tint applied to the mob (hex, e.g., "#ff0000" for red variant) /// [MaxLength(16)] public string TintColor { get; set; } = "#ffffff"; /// /// Scale multiplier for the mob (1.0 = normal size) /// public float Scale { get; set; } = 1.0f; public float AnimationSpeed { get; set; } = 8f; // Frames per second public bool IsEnabled { get; set; } = true; // === Navigation Properties === /// /// Abilities assigned to this mob /// public ICollection AbilityAssignments { get; set; } = new List(); // Helper to get parsed sprite config [NotMapped] public Dictionary? SpriteConfig { get { if (string.IsNullOrEmpty(SpriteConfigJson)) return null; try { return System.Text.Json.JsonSerializer.Deserialize>(SpriteConfigJson); } catch { return null; } } } // Helper methods for JSON parsing [NotMapped] public Dictionary Resistances { get { try { return JsonSerializer.Deserialize>(ResistancesJson) ?? new(); } catch { return new(); } } set { ResistancesJson = JsonSerializer.Serialize(value); } } [NotMapped] public List? Phases { get { if (string.IsNullOrEmpty(PhasesJson)) return null; try { return JsonSerializer.Deserialize>(PhasesJson); } catch { return null; } } set { PhasesJson = value != null ? JsonSerializer.Serialize(value) : null; } } /// /// Calculate scaled stats for a specific level bracket /// Level bracket scaling: each bracket adds 15% to base stats /// public DungeonMobCombatStats GetStatsForBracket(int bracketMin) { // Calculate bracket number (1-10 = bracket 1, 11-20 = bracket 2, etc.) int bracketNumber = Math.Max(1, (bracketMin - 1) / 10 + 1); // Bracket scaling: each bracket adds 15% to base stats (compound) double bracketMultiplier = Math.Pow(1.15, bracketNumber - 1); // Calculate scaled damage values int physDmg = (int)(BasePhysicalDamage * DamagePerTier * bracketMultiplier); int magicDmg = (int)(BaseMagicDamage * DamagePerTier * bracketMultiplier); // Safety: if both physical and magic damage are 0, set physical to 5 as fallback if (physDmg == 0 && magicDmg == 0) { physDmg = 5; } return new DungeonMobCombatStats { MaxHealth = (int)(BaseHealth * HealthPerTier * bracketMultiplier), PhysicalDamage = physDmg, MagicDamage = magicDmg, Armor = (int)(BaseArmor * ArmorPerTier * bracketMultiplier), MoveSpeed = MoveSpeed, AttackRange = AttackRange, AttackSpeed = AttackSpeed, AggroRange = AggroRange, LeashRange = LeashRange, XpReward = (int)(BaseXp * XpPerTier * bracketMultiplier), Resistances = Resistances, DamageTypeKey = DamageTypeKey }; } } /// /// Configuration for a boss phase /// public class MobPhaseConfig { /// HP threshold to trigger this phase (0-1) public float HpThreshold { get; set; } /// New behavior for this phase public MobBehavior Behavior { get; set; } /// Speed multiplier for this phase public float SpeedMultiplier { get; set; } = 1.0f; /// Damage multiplier for this phase public float DamageMultiplier { get; set; } = 1.0f; /// Optional message to display when entering phase public string? PhaseMessage { get; set; } }