2025-09-04 13:08:14 +02:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
2025-09-06 21:01:54 +02:00
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Interaction requirement that checks if the follower is holding a specific required item.
|
|
|
|
|
|
/// </summary>
|
2025-09-04 13:08:14 +02:00
|
|
|
|
[RequireComponent(typeof(Interactable))]
|
|
|
|
|
|
public class RequiresItemBehavior : InteractionRequirementBase
|
|
|
|
|
|
{
|
|
|
|
|
|
[Header("Required Item")]
|
|
|
|
|
|
public PickupItemData requiredItem;
|
|
|
|
|
|
|
2025-09-06 21:01:54 +02:00
|
|
|
|
/// <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>
|
2025-09-04 13:08:14 +02:00
|
|
|
|
public override bool TryInteract(FollowerController follower)
|
|
|
|
|
|
{
|
2025-09-08 15:23:31 +02:00
|
|
|
|
var heldItem = follower.CurrentlyHeldItem;
|
2025-09-04 13:08:14 +02:00
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|