using UnityEngine;
///
/// Consumable behavior for healing items, food, etc.
///
[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();
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();
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();
if (health == null) return "Cannot use this item";
if (health.IsAtFullHealth() && staminaRestore <= 0) return "Already at full health";
return null;
}
}