using Cielonos.Core.Interaction; using Cielonos.MainGame.Characters; using Cielonos.MainGame.UI; using SLSUtilities.General; 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)); } /// /// 执行治疗并禁用交互。 /// private void Rest() { if (isUsed) return; Player player = MainGameManager.Player; if (player == null) { Debug.LogWarning("[MedicalStation] 无法获取 Player 引用。"); return; } float maxHealth = player.attributeSm["MaximumHealth"]; float currentHealth = player.attributeSm["Health"]; float healAmount = maxHealth * healPercentage; float newHealth = Mathf.Min(currentHealth + healAmount, maxHealth); float actualHeal = newHealth - currentHealth; player.attributeSm["Health"] = newHealth; // 通知 UI 刷新血条 PlayerCanvas.PlayerInfoUIArea.UpdateHealth(true); // 触发 onHealthChanged 事件(正值表示治疗) player.eventSm.onHealthChanged.Invoke(actualHeal); isUsed = true; SetInteractable(false); Debug.Log($"[MedicalStation] 玩家恢复了 {actualHeal:F0} 点生命值({healPercentage * 100f}% of {maxHealth:F0}),当前 HP: {newHealth:F0}/{maxHealth:F0}。"); } } }