Interactables fully working now
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user