2026-05-10 11:47:55 -04:00
|
|
|
|
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>
|
|
|
|
|
|
/// 执行治疗并禁用交互。
|
2026-05-23 08:27:50 -04:00
|
|
|
|
/// UI 更新和 onHealthChanged 事件由 AttributeSubmodule 值变更回调自动触发。
|
2026-05-10 11:47:55 -04:00
|
|
|
|
/// </summary>
|
|
|
|
|
|
private void Rest()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isUsed) return;
|
|
|
|
|
|
|
|
|
|
|
|
Player player = MainGameManager.Player;
|
|
|
|
|
|
if (player == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
Debug.LogWarning("[MedicalStation] 无法获取 Player 引用。");
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-05-23 08:27:50 -04:00
|
|
|
|
float maxHealth = player.attributeSm[CharacterAttribute.MaximumHealth];
|
|
|
|
|
|
float currentHealth = player.attributeSm[CharacterAttribute.Health];
|
2026-05-10 11:47:55 -04:00
|
|
|
|
float healAmount = maxHealth * healPercentage;
|
|
|
|
|
|
float newHealth = Mathf.Min(currentHealth + healAmount, maxHealth);
|
|
|
|
|
|
float actualHeal = newHealth - currentHealth;
|
|
|
|
|
|
|
2026-05-23 08:27:50 -04:00
|
|
|
|
player.attributeSm[CharacterAttribute.Health] = newHealth;
|
2026-05-10 11:47:55 -04:00
|
|
|
|
|
|
|
|
|
|
isUsed = true;
|
|
|
|
|
|
SetInteractable(false);
|
|
|
|
|
|
|
|
|
|
|
|
Debug.Log($"[MedicalStation] 玩家恢复了 {actualHeal:F0} 点生命值({healPercentage * 100f}% of {maxHealth:F0}),当前 HP: {newHealth:F0}/{maxHealth:F0}。");
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|