Files
zeling_v2/Assets/Scripts/Enemies/EnemyStats.cs
2026-05-08 11:04:00 +08:00

46 lines
1.3 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using UnityEngine;
namespace BaseGames.Enemies
{
/// <summary>
/// 敌人运行时数值组件(架构 07_EnemyModule §2
/// 由 EnemyBase.Awake() 通过 Initialize(EnemyStatsSO) 注入配置。
/// </summary>
public class EnemyStats : MonoBehaviour
{
private EnemyStatsSO _config;
public int MaxHP { get; private set; }
public int CurrentHP { get; private set; }
public int Defense { get; private set; }
public float AttackCooldownTimer { get; private set; }
/// <summary>每帧由 EnemyBase 更新(读取玩家位置后写入)。</summary>
public float DistanceToPlayer { get; set; }
public void Initialize(EnemyStatsSO so)
{
_config = so;
MaxHP = so.MaxHP;
CurrentHP = so.MaxHP;
Defense = so.Defense;
}
public void TakeDamage(int amount)
{
CurrentHP = Mathf.Max(0, CurrentHP - amount);
}
public void TickAttackCooldown(float dt)
{
if (AttackCooldownTimer > 0f)
AttackCooldownTimer -= dt;
}
public void ResetAttackCooldown()
{
AttackCooldownTimer = _config != null ? _config.AttackCooldown : 1f;
}
}
}