using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Server.Data; namespace DungeonCrawler.Data.Entities; /// /// Derived stats calculator - used at runtime /// public static class CharacterStats { public static int GetMaxHealth(Character c) => 50 + (c.Endurance * 10); public static int GetMaxMana(Character c) => 20 + (c.Wisdom * 8); public static int GetMaxStamina(Character c) => 50 + (c.Endurance * 5); public static float GetXpBonus(Character c) => 1.0f + (c.Wisdom * 0.02f); public static float GetMoveSpeed(Character c) => 100f + (c.Dexterity * 2f); public static float GetAttackSpeed(Character c) => 1.0f + (c.Dexterity * 0.02f); public static float GetRegenRate(Character c) => 1.0f + (c.Endurance * 0.1f); /// /// Calculate combat stats including equipment bonuses /// public static CharacterCombatStats GetCombatStats(Character c, List? equippedItems = null) { var stats = new CharacterCombatStats { Strength = c.Strength, Intelligence = c.Intelligence, Wisdom = c.Wisdom, Endurance = c.Endurance, Dexterity = c.Dexterity }; if (equippedItems != null) { foreach (var item in equippedItems) { stats.Strength += item.BonusStrength; stats.Intelligence += item.BonusIntelligence; stats.Wisdom += item.BonusWisdom; stats.Endurance += item.BonusEndurance; stats.Dexterity += item.BonusDexterity; stats.BonusHealth += item.BonusHealth; stats.BonusMana += item.BonusMana; stats.Armor += item.Armor; stats.MagicResist += item.MagicResist; } } stats.MaxHealth = 50 + (stats.Endurance * 10) + stats.BonusHealth; stats.MaxMana = 20 + (stats.Wisdom * 8) + stats.BonusMana; stats.MaxStamina = 50 + (stats.Endurance * 5); stats.MoveSpeed = 100f + (stats.Dexterity * 2f); stats.AttackSpeed = 1.0f + (stats.Dexterity * 0.02f); stats.RegenRate = 1.0f + (stats.Endurance * 0.1f); stats.PhysicalDamageMultiplier = 1.0f + (stats.Strength * 0.05f); stats.SpellDamageMultiplier = 1.0f + (stats.Intelligence * 0.05f); stats.XpBonus = 1.0f + (stats.Wisdom * 0.02f); return stats; } } public class CharacterCombatStats { public int Strength { get; set; } public int Intelligence { get; set; } public int Wisdom { get; set; } public int Endurance { get; set; } public int Dexterity { get; set; } public int MaxHealth { get; set; } public int MaxMana { get; set; } public int MaxStamina { get; set; } public int BonusHealth { get; set; } public int BonusMana { get; set; } public int Armor { get; set; } public int MagicResist { get; set; } public float MoveSpeed { get; set; } public float AttackSpeed { get; set; } public float RegenRate { get; set; } public float PhysicalDamageMultiplier { get; set; } public float SpellDamageMultiplier { get; set; } public float XpBonus { get; set; } } /// /// Persistent player character with stats and equipment /// [Table("characters")] public class Character { [Key] public ulong Id { get; set; } [Required] public ulong AccountId { get; set; } [Required] [MaxLength(32)] public string Name { get; set; } = ""; public DateTime CreatedAt { get; set; } = DateTime.UtcNow; public DateTime LastPlayedAt { get; set; } = DateTime.UtcNow; // Progression public int Level { get; set; } = 1; public long Experience { get; set; } = 0; public int UnspentStatPoints { get; set; } = 5; // Start with 5 points // Core Stats (5 points per level to distribute) public int Strength { get; set; } = 1; // Physical damage, heavy equipment public int Intelligence { get; set; } = 1; // Spell damage, magical equipment public int Wisdom { get; set; } = 1; // Max mana, XP bonus, spell learning public int Endurance { get; set; } = 1; // Max HP, max stamina, regen rate public int Dexterity { get; set; } = 1; // Move speed, attack speed, light equipment // Derived stats (calculated from base stats) [NotMapped] public int MaxHealth => 50 + (Endurance * 10); [NotMapped] public int MaxMana => 20 + (Wisdom * 8); [NotMapped] public int MaxStamina => 50 + (Endurance * 5); [NotMapped] public float XpBonus => 1.0f + (Wisdom * 0.02f); // 2% per WIS [NotMapped] public float MoveSpeed => 100f + (Dexterity * 2f); [NotMapped] public float AttackSpeed => 1.0f + (Dexterity * 0.02f); [NotMapped] public float RegenRate => 1.0f + (Endurance * 0.1f); // HP/Mana/Stamina regen multiplier // Current state (saved on logout/death) public int CurrentHealth { get; set; } = 50; public int CurrentMana { get; set; } = 20; // Equipment slots (ItemId references, null = empty) public ulong? EquippedWeapon { get; set; } public ulong? EquippedOffhand { get; set; } public ulong? EquippedHead { get; set; } public ulong? EquippedChest { get; set; } public ulong? EquippedLegs { get; set; } public ulong? EquippedBoots { get; set; } public ulong? EquippedGloves { get; set; } public ulong? EquippedAccessory { get; set; } // Lifetime stats public int TotalKills { get; set; } public int TotalDeaths { get; set; } public int PlayersKilled { get; set; } public int DungeonsCompleted { get; set; } public int BossesKilled { get; set; } // Soft delete public bool IsDeleted { get; set; } = false; // Navigation public virtual Account? Account { get; set; } public virtual ICollection Inventory { get; set; } = new List(); public virtual ICollection Stash { get; set; } = new List(); public virtual ICollection LearnedSpells { get; set; } = new List(); } /// /// Experience required per level (exponential curve) /// public static class LevelSystem { public static long GetXpForLevel(int level) { // Base 100 XP for level 2, scaling exponentially return (long)(100 * Math.Pow(1.15, level - 1)); } public static long GetTotalXpForLevel(int level) { long total = 0; for (int i = 1; i < level; i++) total += GetXpForLevel(i); return total; } public static int GetLevelForXp(long totalXp) { int level = 1; long xpNeeded = 0; while (xpNeeded <= totalXp) { xpNeeded += GetXpForLevel(level); if (xpNeeded <= totalXp) level++; } return level; } }