diff --git a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs index 7e3ab45d0..c386e8e2a 100644 --- a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs +++ b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs @@ -41,7 +41,7 @@ public interface IInteractable { bool CanInteract(); bool IsInteractionHidden(); - bool OnInteracted(IInteractor interactor, ScriptableObject causerPayload = null); + void OnInteracted(IInteractor interactor, ScriptableObject causerPayload = null); InteractionType GetInteractionType(); GameObject GetInteractableGameObject(); void InitializeInteraction(InteractionType interactionType); diff --git a/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/AI/Customer/Actions/StartRestaurantOrder.cs b/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/AI/Customer/Actions/StartRestaurantOrder.cs index ea8bd8db7..cd92b99b1 100644 --- a/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/AI/Customer/Actions/StartRestaurantOrder.cs +++ b/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/AI/Customer/Actions/StartRestaurantOrder.cs @@ -25,7 +25,6 @@ public override void OnStart() public override TaskStatus OnUpdate() { - // TODO : 아래 타겟 찾기가 RestaurantOrderAvailable과 동일해야 함, 동일하면 중복될 필요 없으니 스태틱 유틸 함수정도로 만들어서 공유하기. // 레스토랑 주문 인터랙션 후보를 가져옴 TaskStatus targetSearchSuccess = RestaurantOrderAvailable.FindAvailableOrderInteractable(_requireCanInteract, _targetOrderType, out var outInteractable); @@ -34,19 +33,15 @@ public override TaskStatus OnUpdate() return TaskStatus.Failure; } - // TODO : 아래 상호작용 수행 로직이 우리 프로젝트의 권장하는 방식이 아님. 플레이어가 오브젝트에 인터랙션하는 것과 비슷한 흐름으로 NPC가 오브젝트에 인터랙션하게 만들 것. // 상호작용 수행: 액션이 붙은 에이전트를 Interactor로 사용 if (!_isGetInteractor || !_interactor.CanInteractTo(outInteractable)) { return TaskStatus.Failure; } + // TODO : 아래 상호작용 수행 로직이 우리 프로젝트의 권장하는 방식이 아님. 플레이어가 오브젝트에 인터랙션하는 것과 비슷한 흐름으로 NPC가 오브젝트에 인터랙션하게 만들 것. // TODO : 이벤트 통해서 인터랙션. 직접 호출하지 말 것! - var interacted = outInteractable.OnInteracted(_interactor); - if (!interacted) - { - return TaskStatus.Failure; - } + outInteractable.OnInteracted(_interactor); if (_registerOnBlackboard) { diff --git a/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Core/RestaurantCharacterInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Core/RestaurantCharacterInteraction.cs index 5412d5272..7407eb6de 100644 --- a/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Core/RestaurantCharacterInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Core/RestaurantCharacterInteraction.cs @@ -28,27 +28,20 @@ protected virtual void OnDestroy() } protected virtual void OnInteractionCompleted() { } - - public virtual void RequestInteraction(RestaurantInteractionEvent evt) - { - EventBus.Broadcast(evt); - } public virtual void HandleEvent(RestaurantInteractionEvent evt) { - Debug.Log($"Handle Event : {evt.ToString()}"); + Debug.Log($"Event handled : {evt.ToString()}"); } public GameObject GetInteractorGameObject() => gameObject; - protected RestaurantInteractionEvent MakeInteractionEventTo(IInteractable interactable, ScriptableObject payload = null) + protected void TryInteraction(IInteractable interactable, ScriptableObject payload = null) { - var evt = RestaurantEvents.InteractionEvent; - evt.Target = interactable.GetInteractableGameObject(); - evt.Causer = gameObject; - evt.InteractionType = _nearestInteractable.GetInteractionType(); - evt.Payload = payload; - return evt; + var causer = gameObject; + var target = interactable.GetInteractableGameObject(); + var interactionType = _nearestInteractable.GetInteractionType(); + RestaurantEvents.InteractionEvent.RequestInteraction(causer, target, interactionType, payload); } public IInteractionSolver GetInteractionSolver(InteractionType interactionType) diff --git a/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Player/RestaurantPlayerInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Player/RestaurantPlayerInteraction.cs index 65fb7fdd7..10529301d 100644 --- a/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Player/RestaurantPlayerInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/RestaurantCharacter/Player/RestaurantPlayerInteraction.cs @@ -70,19 +70,19 @@ protected virtual void Update() float requiredHoldTime = _interactingTarget.GetExecutionParameters().HoldTime; float ratio = Mathf.Clamp01(_interactHeldTime / requiredHoldTime); - + if (_interactHeldTime >= requiredHoldTime) { - var evt = MakeInteractionEventTo(_nearestInteractable); - RequestInteraction(evt); + TryInteraction(_nearestInteractable); + OnInteractionCompleted(); ResetInteractionState(); - ratio = 0; - - OnInteractionCompleted(); + OnInteractionHoldProgress(0f); + } + else + { + OnInteractionHoldProgress(ratio); } - - OnInteractionHoldProgress(ratio); } } @@ -95,8 +95,7 @@ private void OnInteractPerformed(InputAction.CallbackContext context) if (requiredHoldTime <= 0f) { - var evt = MakeInteractionEventTo(_nearestInteractable); - RequestInteraction(evt); + TryInteraction(_nearestInteractable); } else { diff --git a/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionComponent.cs b/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionComponent.cs index 1caea9a04..4fdfd83fe 100644 --- a/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionComponent.cs +++ b/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionComponent.cs @@ -75,20 +75,9 @@ public virtual bool IsInteractionHidden() return flowDisabled; } - public virtual bool OnInteracted(IInteractor interactor, ScriptableObject payload = null) + public virtual void OnInteracted(IInteractor interactor, ScriptableObject payload = null) { - if (CanInteract() == false) - { - return false; - } - - bool interactionResult = RestaurantEvents.InteractionEvent.RequestInteraction(interactor.GetInteractorGameObject(), - GetInteractableGameObject(), GetInteractionType(), payload, true); - if (HasSubsystem(_interactionType)) - { - interactionResult &= GetSubsystem(_interactionType).OnInteracted(interactor, payload); - } - return interactionResult; + // TODO : Do Something cosmetic? } public virtual InteractionType GetInteractionType() diff --git a/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionEvents.cs b/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionEvents.cs index e97100ca6..9fe0c5cef 100644 --- a/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionEvents.cs +++ b/Assets/_DDD/_Scripts/Restaurant/RestaurantEvent/RestaurantInteractionEvents.cs @@ -54,7 +54,15 @@ public bool RequestInteraction(GameObject causer, GameObject target, Interaction // Cast solverComponent to IInteractable if (solver is not null && interactor is not null) { - evt.EventResult = solver.ExecuteInteraction(interactor, interactable, payload); + bool canExecute = solver.CanExecuteInteraction(interactor, interactable, payload); + if (canExecute) + { + evt.EventResult = solver.ExecuteInteraction(interactor, interactable, payload); + } + else + { + evt.EventResult = false; + } } else {