코드 리팩토링
재사용성 및 확장성을 고려하여 코드 전반을 리팩토링함
This commit is contained in:
50
Assets/Scripts/Player/ConsumableBehavior.cs
Normal file
50
Assets/Scripts/Player/ConsumableBehavior.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
using UnityEngine;
|
||||
|
||||
/// <summary>
|
||||
/// Consumable behavior for healing items, food, etc.
|
||||
/// </summary>
|
||||
[CreateAssetMenu(menuName = "Items/Behaviors/Consumable Behavior")]
|
||||
public class ConsumableBehavior : ItemBehavior
|
||||
{
|
||||
[Header("Consumable Settings")]
|
||||
[SerializeField] private float healAmount = 20f;
|
||||
[SerializeField] private float staminaRestore = 0f;
|
||||
|
||||
public override bool IsConsumable => true;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (string.IsNullOrEmpty(behaviorName)) behaviorName = "Consume";
|
||||
if (string.IsNullOrEmpty(animTrigger)) animTrigger = "Consume";
|
||||
canRepeat = false;
|
||||
}
|
||||
|
||||
public override bool CanUse(GameObject user, GameObject target)
|
||||
{
|
||||
// Can use if user has a health component that isn't at full health
|
||||
var health = user.GetComponent<HealthComponent>();
|
||||
if (health == null) return false;
|
||||
|
||||
// Can use if not at full health (healing) or if it restores stamina
|
||||
return !health.IsAtFullHealth() || staminaRestore > 0;
|
||||
}
|
||||
|
||||
public override void Use(GameObject user, GameObject target)
|
||||
{
|
||||
var health = user.GetComponent<HealthComponent>();
|
||||
if (health != null && healAmount > 0)
|
||||
{
|
||||
health.Heal(healAmount);
|
||||
}
|
||||
|
||||
// Stamina restoration would go here when stamina system is implemented
|
||||
}
|
||||
|
||||
public override string GetBlockedReason(GameObject user, GameObject target)
|
||||
{
|
||||
var health = user.GetComponent<HealthComponent>();
|
||||
if (health == null) return "Cannot use this item";
|
||||
if (health.IsAtFullHealth() && staminaRestore <= 0) return "Already at full health";
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user