using UnityEngine; namespace MazeGen { /// /// Core character/monster statistics. Stores both base stats and current values /// (health can be reduced in combat, speed affects action order, attack/defense/magic /// are used in combat resolution). /// [System.Serializable] public class CharacterStats { [SerializeField] private float _maxHealth = 100f; [SerializeField] private float _speed = 10f; // Initiative and movement speed [SerializeField] private float _attack = 10f; // Physical damage output [SerializeField] private float _defense = 5f; // Physical damage reduction [SerializeField] private float _magic = 5f; // Magical power (casting damage/resistance) private float _currentHealth; public float MaxHealth => _maxHealth; public float CurrentHealth { get => _currentHealth; set => _currentHealth = Mathf.Clamp(value, 0, _maxHealth); } public float Speed => _speed; public float Attack => _attack; public float Defense => _defense; public float Magic => _magic; public bool IsAlive => _currentHealth > 0; public CharacterStats() { _currentHealth = _maxHealth; } /// Create a copy of this stat block (useful for monster instances). public CharacterStats Clone() { var clone = new CharacterStats { _maxHealth = _maxHealth, _speed = _speed, _attack = _attack, _defense = _defense, _magic = _magic, _currentHealth = _currentHealth }; return clone; } /// Reset health to max (for a fresh combat or new agent spawn). public void RestoreHealth() { _currentHealth = _maxHealth; } /// Take damage (already accounting for defense). public void TakeDamage(float damage) { CurrentHealth -= Mathf.Max(0, damage); } /// Calculate effective damage taken after defense reduction. public float CalculateDamageReduction(float incomingDamage) { // Simple formula: defense reduces damage by 10% per defense point, up to 90% reduction float reductionPercent = Mathf.Clamp01(_defense * 0.1f); return incomingDamage * (1f - reductionPercent); } } }