Files
systemrevivalserver/data/entities/Character.cs
T

157 lines
6.1 KiB
C#

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using DataServer.Data;
namespace DataServer.Data.Entities;
/// <summary>
/// Derived stats calculator - used at runtime
/// </summary>
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);
/// <summary>
/// Calculate combat stats including equipment bonuses
/// </summary>
public static CharacterCombatStats GetCombatStats(Character c, List<ItemDefinition>? 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; }
}
/// <summary>
/// Persistent player character with stats and equipment
/// </summary>
[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<CharacterItem> Inventory { get; set; } = new List<CharacterItem>();
public virtual ICollection<StashItem> Stash { get; set; } = new List<StashItem>();
public virtual ICollection<LearnedSpell> LearnedSpells { get; set; } = new List<LearnedSpell>();
}