Files
AppleHillsProduction/Assets/Scripts/Interactions/CombineWithBehavior.cs
2025-09-11 14:07:57 +02:00

46 lines
1.7 KiB
C#

using UnityEngine;
/// <summary>
/// Interaction requirement that allows combining the follower's held item with this pickup if a valid combination rule exists.
/// </summary>
[RequireComponent(typeof(Pickup))]
public class CombineWithBehavior : InteractionRequirementBase
{
/// <summary>
/// Attempts to combine the follower's held item with this pickup's item.
/// </summary>
/// <param name="follower">The follower attempting the interaction.</param>
/// <returns>True if the combination was successful, false otherwise.</returns>
public override bool TryInteract(FollowerController follower)
{
var heldItem = follower.GetHeldPickupObject();
var pickup = GetComponent<Pickup>();
if (heldItem == null)
{
// DebugUIMessage.Show("You need an item to combine.");
OnFailure?.Invoke();
return true;
}
if (pickup == null || pickup.itemData == null)
{
DebugUIMessage.Show("Target item is missing or invalid.");
OnFailure?.Invoke();
return false;
}
var combinedItem = InteractionOrchestrator.Instance.CombineItems(heldItem, pickup.gameObject);
if (combinedItem != null)
{
InteractionOrchestrator.Instance.PickupItem(follower, combinedItem);
follower.justCombined = true;
OnSuccess?.Invoke();
return true;
}
else
{
// DebugUIMessage.Show($"Cannot combine {follower.CurrentlyHeldItem?.itemName ?? "an item"} with {pickup.itemData.itemName ?? "target item"}.");
OnFailure?.Invoke();
return true;
}
}
}