Files
AppleHillsProduction/Assets/Scripts/Interactions/RequiresItemBehavior.cs

42 lines
1.4 KiB
C#
Raw Normal View History

using UnityEngine;
/// <summary>
/// Interaction requirement that checks if the follower is holding a specific required item.
/// </summary>
[RequireComponent(typeof(Interactable))]
public class RequiresItemBehavior : InteractionRequirementBase
{
[Header("Required Item")]
public PickupItemData requiredItem;
/// <summary>
/// Attempts to interact, succeeds only if the follower is holding the required item.
/// </summary>
/// <param name="follower">The follower attempting the interaction.</param>
/// <returns>True if the interaction was successful, false otherwise.</returns>
public override bool TryInteract(FollowerController follower)
{
var heldItem = follower.CurrentlyHeldItem;
if (heldItem == requiredItem)
{
OnSuccess?.Invoke();
return true;
}
else
{
string requiredName = requiredItem != null ? requiredItem.itemName : "required item";
if (heldItem == null)
{
DebugUIMessage.Show($"You need {requiredName} to interact.");
}
else
{
string heldName = heldItem.itemName ?? "an item";
DebugUIMessage.Show($"You need {requiredName}, but you are holding {heldName}.");
}
OnFailure?.Invoke();
return false;
}
}
}