Interactables fully working now

This commit is contained in:
Michal Pikulski
2025-09-10 17:38:03 +02:00
parent 0ef25f265c
commit 3a40d1a151
8 changed files with 101 additions and 109 deletions

View File

@@ -13,7 +13,7 @@ public class CombineWithBehavior : InteractionRequirementBase
/// <returns>True if the combination was successful, false otherwise.</returns>
public override bool TryInteract(FollowerController follower)
{
var heldItem = follower.CurrentlyHeldItem;
var heldItem = follower.GetHeldPickupObject();
var pickup = GetComponent<Pickup>();
if (heldItem == null)
{
@@ -27,36 +27,17 @@ public class CombineWithBehavior : InteractionRequirementBase
OnFailure?.Invoke();
return false;
}
var rule = GameManager.Instance.GetCombinationRule(heldItem, pickup.itemData);
if (rule != null && rule.resultPrefab != null)
var combinedItem = InteractionOrchestrator.Instance.CombineItems(heldItem, pickup.gameObject);
if (combinedItem != null)
{
// Instantiate the result prefab at the pickup's position
var resultObj = GameObject.Instantiate(rule.resultPrefab, pickup.transform.position, Quaternion.identity);
var resultPickup = resultObj.GetComponent<Pickup>();
if (resultPickup != null)
{
// Hide and parent to follower
resultObj.SetActive(false);
resultObj.transform.SetParent(follower.transform);
// Set held item and icon from the spawned prefab
follower.SetHeldItem(resultPickup.itemData, resultPickup.iconRenderer);
// Cache the spawned object as the held item
follower.CacheHeldPickupObject(resultObj);
follower.justCombined = true;
OnSuccess?.Invoke();
return true;
}
else
{
Debug.LogWarning("Result prefab does not have a Pickup component.");
GameObject.Destroy(resultObj);
OnFailure?.Invoke();
return false;
}
InteractionOrchestrator.Instance.PickupItem(follower, combinedItem);
follower.justCombined = true;
OnSuccess?.Invoke();
return true;
}
else
{
// DebugUIMessage.Show($"Cannot combine {heldItem.itemName ?? \"an item\"} with {pickup.itemData.itemName ?? \"target item\"}.");
// DebugUIMessage.Show($"Cannot combine {follower.CurrentlyHeldItem?.itemName ?? "an item"} with {pickup.itemData.itemName ?? "target item"}.");
OnFailure?.Invoke();
return true;
}