Files
Cielonos/Assets/Scripts/MainGame/Interactions/MedicalStation.cs
2026-05-10 11:47:55 -04:00

62 lines
2.1 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 Cielonos.Core.Interaction;
using Cielonos.MainGame.Characters;
using Cielonos.MainGame.UI;
using SLSUtilities.General;
using UnityEngine;
namespace Cielonos.MainGame.Interactions
{
/// <summary>
/// 医疗站(休息点)场景交互对象。
/// 玩家交互后恢复一定百分比的最大生命值,单次使用后标记为 Exhausted不可再次触发治疗。
/// </summary>
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));
}
/// <summary>
/// 执行治疗并禁用交互。
/// </summary>
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}。");
}
}
}