From 18a9d9fef000f0da3cabe1a71e84ab41abb4dfb9 Mon Sep 17 00:00:00 2001 From: Jeonghyeon Ha Date: Wed, 27 Aug 2025 19:15:21 +0900 Subject: [PATCH] fixed customer interaction flow --- .../Customer/Actions/StartRestaurantOrder.cs | 4 +-- .../Conditionals/RestaurantOrderAvailable.cs | 3 +- .../InteractionSubsystem_Order.cs | 31 ++++++++++++++----- .../RestaurantOrderSolver_Wait.cs | 15 ++++++--- 4 files changed, 35 insertions(+), 18 deletions(-) diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Actions/StartRestaurantOrder.cs b/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Actions/StartRestaurantOrder.cs index 16216526e..f7b8a1acf 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Actions/StartRestaurantOrder.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Actions/StartRestaurantOrder.cs @@ -39,9 +39,7 @@ public override TaskStatus OnUpdate() return TaskStatus.Failure; } - // TODO : 아래 상호작용 수행 로직이 우리 프로젝트의 권장하는 방식이 아님. 플레이어가 오브젝트에 인터랙션하는 것과 비슷한 흐름으로 NPC가 오브젝트에 인터랙션하게 만들 것. - // TODO : 이벤트 통해서 인터랙션. 직접 호출하지 말 것! - outInteractable.OnInteracted(_interactor); + RestaurantEvents.InteractionEvent.RequestInteraction(_interactor.GetInteractorGameObject(), outInteractable.gameObject, outInteractable.GetInteractionType()); if (_registerOnBlackboard) { diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Conditionals/RestaurantOrderAvailable.cs b/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Conditionals/RestaurantOrderAvailable.cs index 1e99b0ba5..da16bc590 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Conditionals/RestaurantOrderAvailable.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/AI/Customer/Conditionals/RestaurantOrderAvailable.cs @@ -53,8 +53,7 @@ public static TaskStatus FindAvailableOrderInteractable(bool checkCanInteract if (outInteractable == null) continue; if (!outInteractable.TryGetSubsystemObject(out var subsystem)) continue; - if (EqualityComparer.Default.Equals(subsystem.GetInteractionSubsystemType(), targetOrderType) - ) + if (EqualityComparer.Default.Equals(subsystem.GetInteractionSubsystemType(), targetOrderType)) { // CheckCanInteract이 false면 타입만 맞으면 성공 if (!checkCanInteract) diff --git a/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs b/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs index eebb1f995..fde3d3f3c 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs @@ -14,7 +14,12 @@ public enum RestaurantOrderType : uint Dirty = 1u << 4, } - public class InteractionSubsystem_Order : MonoBehaviour, IInteractionSubsystemObject + public interface IRestaurantOrderObject + { + void TransitionToNextPhase(); + } + + public class InteractionSubsystem_Order : MonoBehaviour, IInteractionSubsystemObject, IRestaurantOrderObject { [FormerlySerializedAs("orderType")] [SerializeField] protected RestaurantOrderType _orderType = RestaurantOrderType.Wait; private RestaurantOrderType _currentRestaurantOrderType; @@ -26,18 +31,23 @@ private void Start() public bool CanInteract() { - //if (GetInteractionSubsystemType() == RestaurantOrderType.Wait) - //{ - // return true; - //} + if (GetInteractionSubsystemType() == RestaurantOrderType.Wait) + { + return CanTransitionToNextPhase(); + } return true; } + + public void TransitionToNextPhase() + { + // 간단한 상태 전이: 현재 상태에서 다음 상태로 이동 + var currentState = GetInteractionSubsystemType(); + var nextState = GetNextState(currentState); + SetInteractionSubsystemType(nextState); + } public bool OnInteracted(IInteractor interactor, ScriptableObject payloadSo = null) { - // 간단한 상태 전이: 현재 상태에서 다음 상태로 이동 - var prev = _currentRestaurantOrderType; - _currentRestaurantOrderType = GetNextState(prev); return true; } @@ -74,5 +84,10 @@ private RestaurantOrderType GetNextState(RestaurantOrderType state) default: return RestaurantOrderType.Wait; } } + + public bool CanTransitionToNextPhase() + { + return true; + } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Wait.cs b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Wait.cs index 361b0c465..62dc989e4 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Wait.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Wait.cs @@ -8,11 +8,16 @@ public class RestaurantOrderSolver_Wait : MonoBehaviour, IInteractionSubsystemSo public bool ExecuteInteractionSubsystem(IInteractor interactor, IInteractable interactable, ScriptableObject payload = null) { if (CanExecuteInteractionSubsystem(interactor, interactable, payload) == false) return false; - // TODO : DO SOMETHING!!! - /* TODO - * OnInteracted에서 상태를 바꾸는 대신, 여기서 직접 바꿔주고, 현재 나에게 점유되어 있다는 사실을 알려주기? 그리고 CanInteractTo에서 이게 일치해야만 참 반환하게? - * 필요하다면 IInteractable 인터페이스에 CurrentInteractor를 등록하는 메소드를 추가해야 할수도? - */ + + if (interactable is not IInteractionSubsystemOwner subsystemOwner) + return false; + if (!subsystemOwner.TryGetSubsystemObject(out var subsystem)) + return false; + if (subsystem is IRestaurantOrderObject orderObject) + { + orderObject.TransitionToNextPhase(); + } + return true; }