Files
systemrevivalserver/data/entities/DungeonMobDefinition.cs
T
2025-12-06 18:06:03 -05:00

140 lines
5.0 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Text.Json;
using Server.Data.Enums;
namespace Server.Data.Entities;
/// <summary>
/// Monster/NPC template definition stored in database
/// </summary>
[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;
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;
// 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
// 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;
/// <summary>
/// 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
/// </summary>
[MaxLength(1024)]
public string ResistancesJson { get; set; } = "{}";
/// <summary>
/// JSON block for special abilities/behaviors
/// Example: {"canFlee": true, "fleeHealthPercent": 0.2, "callsForHelp": true}
/// </summary>
[MaxLength(1024)]
public string AbilitiesJson { get; set; } = "{}";
// Visuals - reference to sprite/animation
[MaxLength(128)]
public string SpriteSheet { get; set; } = "mobs/skeleton.png";
public int SpriteIndex { get; set; } = 0; // Index in spritesheet
public int SpriteWidth { get; set; } = 32;
public int SpriteHeight { get; set; } = 32;
[MaxLength(16)]
public string TintColor { get; set; } = "#ffffff"; // Color tint for variants
// Animation frames (JSON array of frame indices)
[MaxLength(256)]
public string IdleFrames { get; set; } = "[0]";
[MaxLength(256)]
public string WalkFrames { get; set; } = "[0,1,2,3]";
[MaxLength(256)]
public string AttackFrames { get; set; } = "[4,5]";
[MaxLength(256)]
public string DeathFrames { get; set; } = "[6,7]";
public float AnimationSpeed { get; set; } = 8f; // Frames per second
public bool IsEnabled { get; set; } = true;
// Helper methods for JSON parsing
[NotMapped]
public Dictionary<string, float> Resistances
{
get
{
try { return JsonSerializer.Deserialize<Dictionary<string, float>>(ResistancesJson) ?? new(); }
catch { return new(); }
}
set { ResistancesJson = JsonSerializer.Serialize(value); }
}
[NotMapped]
public Dictionary<string, object> Abilities
{
get
{
try { return JsonSerializer.Deserialize<Dictionary<string, object>>(AbilitiesJson) ?? new(); }
catch { return new(); }
}
set { AbilitiesJson = JsonSerializer.Serialize(value); }
}
/// <summary>
/// Calculate scaled stats for a specific dungeon tier
/// </summary>
public DungeonMobCombatStats GetStatsForTier(int tier)
{
return new DungeonMobCombatStats
{
MaxHealth = (int)(BaseHealth * Math.Pow(HealthPerTier, tier - 1)),
PhysicalDamage = (int)(BasePhysicalDamage * Math.Pow(DamagePerTier, tier - 1)),
MagicDamage = (int)(BaseMagicDamage * Math.Pow(DamagePerTier, tier - 1)),
Armor = (int)(BaseArmor * Math.Pow(ArmorPerTier, tier - 1)),
MagicResist = (int)(BaseMagicResist * Math.Pow(ArmorPerTier, tier - 1)),
MoveSpeed = MoveSpeed,
AttackRange = AttackRange,
AttackSpeed = AttackSpeed,
AggroRange = AggroRange,
LeashRange = LeashRange,
XpReward = (int)(BaseXp * Math.Pow(XpPerTier, tier - 1)),
Resistances = Resistances
};
}
}