Big script cleanup. Remove the examples from Ropes' external package
This commit is contained in:
48
Assets/Scripts/Interactions/CombineWithBehavior.cs
Normal file
48
Assets/Scripts/Interactions/CombineWithBehavior.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
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.currentlyHeldItem;
|
||||
var pickup = GetComponent<Pickup>();
|
||||
if (heldItem == null)
|
||||
{
|
||||
DebugUIMessage.Show("You need an item to combine.");
|
||||
OnFailure?.Invoke();
|
||||
return false;
|
||||
}
|
||||
if (pickup == null || pickup.itemData == null)
|
||||
{
|
||||
DebugUIMessage.Show("Target item is missing or invalid.");
|
||||
OnFailure?.Invoke();
|
||||
return false;
|
||||
}
|
||||
var rule = GameManager.Instance.GetCombinationRule(heldItem, pickup.itemData);
|
||||
if (rule != null && rule.result != null)
|
||||
{
|
||||
// Remove both items and add result to follower's inventory
|
||||
follower.SetHeldItem(rule.result);
|
||||
follower.justCombined = true;
|
||||
OnSuccess?.Invoke();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
string heldName = heldItem.itemName ?? "an item";
|
||||
string targetName = pickup.itemData.itemName ?? "target item";
|
||||
DebugUIMessage.Show($"Cannot combine {heldName} with {targetName}.");
|
||||
OnFailure?.Invoke();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user