Mostly working, double invocation of dialogue progression
This commit is contained in:
@@ -34,6 +34,7 @@ namespace Core
|
||||
|
||||
private readonly HashSet<Pickup> _pickups = new HashSet<Pickup>();
|
||||
private readonly HashSet<ItemSlot> _itemSlots = new HashSet<ItemSlot>();
|
||||
private readonly HashSet<string> _itemsCreatedThroughCombination = new HashSet<string>();
|
||||
|
||||
// Central events forwarded from registered pickups/slots
|
||||
// Broadcasts when any registered pickup was picked up (passes the picked item data)
|
||||
@@ -43,6 +44,10 @@ namespace Core
|
||||
// Args: slot's itemData (the slot definition), then the slotted item data
|
||||
public event Action<PickupItemData, PickupItemData> OnCorrectItemSlotted;
|
||||
|
||||
// Broadcasts when any two items are successfully combined
|
||||
// Args: first item data, second item data, result item data
|
||||
public event Action<PickupItemData, PickupItemData, PickupItemData> OnItemsCombined;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
@@ -86,7 +91,10 @@ namespace Core
|
||||
foreach (var p in pickupsCopy)
|
||||
{
|
||||
if (p != null)
|
||||
{
|
||||
p.OnItemPickedUp -= Pickup_OnItemPickedUp;
|
||||
p.OnItemsCombined -= Pickup_OnItemsCombined;
|
||||
}
|
||||
}
|
||||
_pickups.Clear();
|
||||
|
||||
@@ -99,9 +107,13 @@ namespace Core
|
||||
}
|
||||
_itemSlots.Clear();
|
||||
|
||||
// Clear item tracking
|
||||
_itemsCreatedThroughCombination.Clear();
|
||||
|
||||
// Clear manager-level event subscribers
|
||||
OnItemPickedUp = null;
|
||||
OnCorrectItemSlotted = null;
|
||||
OnItemsCombined = null;
|
||||
}
|
||||
|
||||
public void RegisterPickup(Pickup pickup)
|
||||
@@ -111,6 +123,7 @@ namespace Core
|
||||
if (_pickups.Add(pickup))
|
||||
{
|
||||
pickup.OnItemPickedUp += Pickup_OnItemPickedUp;
|
||||
pickup.OnItemsCombined += Pickup_OnItemsCombined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +133,7 @@ namespace Core
|
||||
if (_pickups.Remove(pickup))
|
||||
{
|
||||
pickup.OnItemPickedUp -= Pickup_OnItemPickedUp;
|
||||
pickup.OnItemsCombined -= Pickup_OnItemsCombined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,6 +167,28 @@ namespace Core
|
||||
OnCorrectItemSlotted?.Invoke(slotData, slottedItem);
|
||||
}
|
||||
|
||||
// Handler that forwards item combination events
|
||||
private void Pickup_OnItemsCombined(PickupItemData itemA, PickupItemData itemB, PickupItemData resultItem)
|
||||
{
|
||||
// Track the created item
|
||||
if (resultItem != null)
|
||||
{
|
||||
_itemsCreatedThroughCombination.Add(resultItem.itemId);
|
||||
}
|
||||
|
||||
OnItemsCombined?.Invoke(itemA, itemB, resultItem);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if a specific item has been created through item combination.
|
||||
/// </summary>
|
||||
/// <param name="itemId">The ID of the item to check.</param>
|
||||
/// <returns>True if the item has been created through combination, false otherwise.</returns>
|
||||
public bool WasItemCreatedThroughCombination(string itemId)
|
||||
{
|
||||
return !string.IsNullOrEmpty(itemId) && _itemsCreatedThroughCombination.Contains(itemId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Returns the current slot state for the given item data by searching registered slots.
|
||||
/// If the item is currently slotted in a slot, returns that slot's state; otherwise returns ItemSlotState.None.
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace Dialogue
|
||||
{
|
||||
ItemManager.Instance.OnItemPickedUp += OnAnyItemPickedUp;
|
||||
ItemManager.Instance.OnCorrectItemSlotted += OnAnyItemSlotted;
|
||||
ItemManager.Instance.OnItemsCombined += OnAnyItemsCombined;
|
||||
}
|
||||
|
||||
speechBubble = GetComponentInChildren<SpeechBubble>();
|
||||
@@ -86,6 +87,7 @@ namespace Dialogue
|
||||
{
|
||||
ItemManager.Instance.OnItemPickedUp -= OnAnyItemPickedUp;
|
||||
ItemManager.Instance.OnCorrectItemSlotted -= OnAnyItemSlotted;
|
||||
ItemManager.Instance.OnItemsCombined -= OnAnyItemsCombined;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -140,7 +142,7 @@ namespace Dialogue
|
||||
{
|
||||
currentLine = currentNode.dialogueLines[currentLineIndex];
|
||||
}
|
||||
|
||||
Debug.Log("Returning line: " + currentLine);
|
||||
// Return the current line
|
||||
return currentLine;
|
||||
}
|
||||
@@ -242,6 +244,15 @@ namespace Dialogue
|
||||
}
|
||||
break;
|
||||
|
||||
case RuntimeDialogueNodeType.WaitOnCombination:
|
||||
// Check if the result item is already created through combination
|
||||
if (IsResultItemCreated(currentNode.combinationResultItemID))
|
||||
{
|
||||
// If it's already created, move past this node automatically
|
||||
MoveToNextNode();
|
||||
}
|
||||
break;
|
||||
|
||||
case RuntimeDialogueNodeType.End:
|
||||
// End node, complete the dialogue
|
||||
IsActive = false;
|
||||
@@ -269,8 +280,8 @@ namespace Dialogue
|
||||
MoveToNextNode();
|
||||
|
||||
// Notify any listeners about the dialogue change
|
||||
string line = GetCurrentDialogueLine();
|
||||
OnDialogueChanged?.Invoke(line);
|
||||
// string line = GetCurrentDialogueLine();
|
||||
// OnDialogueChanged?.Invoke(line);
|
||||
|
||||
// Update bubble visibility after state change
|
||||
if (speechBubble != null)
|
||||
@@ -294,8 +305,8 @@ namespace Dialogue
|
||||
MoveToNextNode();
|
||||
|
||||
// Notify any listeners about the dialogue change
|
||||
string line = GetCurrentDialogueLine();
|
||||
OnDialogueChanged?.Invoke(line);
|
||||
// string line = GetCurrentDialogueLine();
|
||||
// OnDialogueChanged?.Invoke(line);
|
||||
|
||||
// Update bubble visibility after state change
|
||||
if (speechBubble != null)
|
||||
@@ -305,14 +316,16 @@ namespace Dialogue
|
||||
}
|
||||
|
||||
// Always check if any dialogue was unblocked by this pickup
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
// if (speechBubble != null)
|
||||
// {
|
||||
// speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnAnyItemSlotted(PickupItemData slotDefinition, PickupItemData slottedItem)
|
||||
{
|
||||
Debug.Log("[DialogueComponent] OnAnyItemSlotted");
|
||||
|
||||
// Only react if we're active and waiting on a slot
|
||||
if (!IsActive || IsCompleted || currentNode == null ||
|
||||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnSlot)
|
||||
@@ -325,8 +338,8 @@ namespace Dialogue
|
||||
MoveToNextNode();
|
||||
|
||||
// Notify any listeners about the dialogue change
|
||||
string line = GetCurrentDialogueLine();
|
||||
OnDialogueChanged?.Invoke(line);
|
||||
// string line = GetCurrentDialogueLine();
|
||||
// OnDialogueChanged?.Invoke(line);
|
||||
|
||||
// Update bubble visibility after state change
|
||||
if (speechBubble != null)
|
||||
@@ -336,10 +349,41 @@ namespace Dialogue
|
||||
}
|
||||
|
||||
// Always check if any dialogue was unblocked by this slotting
|
||||
if (speechBubble != null)
|
||||
// if (speechBubble != null)
|
||||
// {
|
||||
// speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
// }
|
||||
}
|
||||
|
||||
private void OnAnyItemsCombined(PickupItemData itemA, PickupItemData itemB, PickupItemData resultItem)
|
||||
{
|
||||
// Only react if we're active and waiting on a combination
|
||||
if (!IsActive || IsCompleted || currentNode == null ||
|
||||
currentNode.nodeType != RuntimeDialogueNodeType.WaitOnCombination)
|
||||
return;
|
||||
|
||||
// Check if this is the result item we're waiting for
|
||||
if (resultItem.itemId == currentNode.combinationResultItemID)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
// Move to next node automatically when condition is met
|
||||
MoveToNextNode();
|
||||
|
||||
// Notify any listeners about the dialogue change
|
||||
// string line = GetCurrentDialogueLine();
|
||||
// OnDialogueChanged?.Invoke(line);
|
||||
|
||||
// Update bubble visibility after state change
|
||||
if (speechBubble != null)
|
||||
{
|
||||
speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
}
|
||||
}
|
||||
|
||||
// Always check if any dialogue was unblocked by this combination
|
||||
// if (speechBubble != null)
|
||||
// {
|
||||
// speechBubble.UpdatePromptVisibility(HasAnyLines());
|
||||
// }
|
||||
}
|
||||
|
||||
// Helper methods
|
||||
@@ -355,6 +399,8 @@ namespace Dialogue
|
||||
return !IsItemPickedUp(currentNode.pickupItemID);
|
||||
case RuntimeDialogueNodeType.WaitOnSlot:
|
||||
return !IsItemSlotted(currentNode.slotItemID);
|
||||
case RuntimeDialogueNodeType.WaitOnCombination:
|
||||
return !IsResultItemCreated(currentNode.combinationResultItemID);
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
@@ -398,6 +444,14 @@ namespace Dialogue
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool IsResultItemCreated(string resultItemId)
|
||||
{
|
||||
if (ItemManager.Instance == null) return false;
|
||||
|
||||
// Use the ItemManager's tracking of items created through combination
|
||||
return ItemManager.Instance.WasItemCreatedThroughCombination(resultItemId);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Checks if the dialogue component has any lines available to serve
|
||||
/// </summary>
|
||||
|
||||
@@ -11,6 +11,7 @@ namespace Dialogue
|
||||
WaitOnPuzzleStep,
|
||||
WaitOnPickup,
|
||||
WaitOnSlot,
|
||||
WaitOnCombination,
|
||||
End
|
||||
}
|
||||
|
||||
@@ -43,6 +44,7 @@ namespace Dialogue
|
||||
public string puzzleStepID; // For WaitOnPuzzleStep
|
||||
public string pickupItemID; // For WaitOnPickup
|
||||
public string slotItemID; // For WaitOnSlot
|
||||
public string combinationResultItemID; // For WaitOnCombination
|
||||
|
||||
// For WaitOnSlot - different responses
|
||||
public List<string> incorrectItemLines = new List<string>();
|
||||
|
||||
@@ -56,6 +56,8 @@ namespace Interactions
|
||||
|
||||
protected override void OnCharacterArrived()
|
||||
{
|
||||
Debug.Log("[ItemSlot] OnCharacterArrived");
|
||||
|
||||
var heldItemData = FollowerController.CurrentlyHeldItemData;
|
||||
var heldItemObj = FollowerController.GetHeldPickupObject();
|
||||
var config = GameManager.Instance.GetSlotItemConfig(itemData);
|
||||
|
||||
@@ -20,6 +20,9 @@ namespace Interactions
|
||||
// Event: invoked when the item was picked up successfully
|
||||
public event Action<PickupItemData> OnItemPickedUp;
|
||||
|
||||
// Event: invoked when this item is successfully combined with another
|
||||
public event Action<PickupItemData, PickupItemData, PickupItemData> OnItemsCombined;
|
||||
|
||||
/// <summary>
|
||||
/// Unity Awake callback. Sets up icon, interactable, and event handlers.
|
||||
/// </summary>
|
||||
@@ -100,10 +103,35 @@ namespace Interactions
|
||||
|
||||
protected virtual void OnCharacterArrived()
|
||||
{
|
||||
Debug.Log("[Pickup] OnCharacterArrived");
|
||||
|
||||
var combinationResult = FollowerController.TryCombineItems(this, out var combinationResultItem);
|
||||
if (combinationResultItem != null)
|
||||
{
|
||||
Interactable.BroadcastInteractionComplete(true);
|
||||
|
||||
// Fire the combination event when items are successfully combined
|
||||
if (combinationResult == FollowerController.CombinationResult.Successful)
|
||||
{
|
||||
var resultPickup = combinationResultItem.GetComponent<Pickup>();
|
||||
if (resultPickup != null && resultPickup.itemData != null)
|
||||
{
|
||||
// Get the combined item data
|
||||
var resultItemData = resultPickup.itemData;
|
||||
var heldItem = FollowerController.GetHeldPickupObject();
|
||||
|
||||
if (heldItem != null)
|
||||
{
|
||||
var heldPickup = heldItem.GetComponent<Pickup>();
|
||||
if (heldPickup != null && heldPickup.itemData != null)
|
||||
{
|
||||
// Trigger the combination event
|
||||
OnItemsCombined?.Invoke(itemData, heldPickup.itemData, resultItemData);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user