Fix slot items to fully work with the stashing prefab flow
This commit is contained in:
committed by
Michal Pikulski
parent
a8d398e097
commit
5804b170d0
@@ -28,19 +28,35 @@ public class CombineWithBehavior : InteractionRequirementBase
|
||||
return false;
|
||||
}
|
||||
var rule = GameManager.Instance.GetCombinationRule(heldItem, pickup.itemData);
|
||||
if (rule != null && rule.result != null)
|
||||
if (rule != null && rule.resultPrefab != null)
|
||||
{
|
||||
// Remove both items and add result to follower's inventory
|
||||
follower.SetHeldItem(rule.result);
|
||||
follower.justCombined = true;
|
||||
OnSuccess?.Invoke();
|
||||
return true;
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
string heldName = heldItem.itemName ?? "an item";
|
||||
string targetName = pickup.itemData.itemName ?? "target item";
|
||||
// DebugUIMessage.Show($"Cannot combine {heldName} with {targetName}.");
|
||||
// DebugUIMessage.Show($"Cannot combine {heldItem.itemName ?? \"an item\"} with {pickup.itemData.itemName ?? \"target item\"}.");
|
||||
OnFailure?.Invoke();
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user