Files
Cielonos/Assets/Scripts/MainGame/Interactions/MedicalStation.cs
SoulliesOfficial 649b7a5ddc 更新
2026-05-23 08:27:50 -04:00

55 lines
1.9 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 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>
/// 执行治疗并禁用交互。
/// UI 更新和 onHealthChanged 事件由 AttributeSubmodule 值变更回调自动触发。
/// </summary>
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}。");
}
}
}