using Cielonos.Core.Interaction; using Cielonos.MainGame.Characters; using UnityEngine; namespace Cielonos.MainGame.Interactions { /// /// 医疗站(休息点)场景交互对象。 /// 玩家交互后恢复一定百分比的最大生命值,单次使用后标记为 Exhausted,不可再次触发治疗。 /// public class MedicalStation : InteractableObjectBase { private const float DEFAULT_HEAL_PERCENTAGE = 0.3f; [Tooltip("恢复最大生命值的百分比(0~1),默认 0.3 即 30%。")] public float healPercentage = DEFAULT_HEAL_PERCENTAGE; private bool isUsed; protected override void InitializeChoices() { choices.Add(new InteractionChoice("Rest", Rest)); } /// /// 执行治疗并禁用交互。 /// UI 更新和 onHealthChanged 事件由 AttributeSubmodule 值变更回调自动触发。 /// private void Rest() { if (isUsed) return; Player player = MainGameManager.Player; if (player == null) { Debug.LogWarning("[MedicalStation] 无法获取 Player 引用。"); return; } float maxHealth = player.attributeSm[CharacterAttribute.MaximumHealth]; float currentHealth = player.attributeSm[CharacterAttribute.Health]; float healAmount = maxHealth * healPercentage; float newHealth = Mathf.Min(currentHealth + healAmount, maxHealth); float actualHeal = newHealth - currentHealth; player.attributeSm[CharacterAttribute.Health] = newHealth; isUsed = true; SetInteractable(false); Debug.Log($"[MedicalStation] 玩家恢复了 {actualHeal:F0} 点生命值({healPercentage * 100f}% of {maxHealth:F0}),当前 HP: {newHealth:F0}/{maxHealth:F0}。"); } } }