diff --git a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs index 093af0d2f..834137f1f 100644 --- a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs +++ b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs @@ -56,6 +56,7 @@ public interface IInteractor GameObject GetInteractorGameObject(); IInteractable GetFocusedInteractable(); bool CanSolveInteractionType(InteractionType interactionType); + bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType); bool IsInteractionHidden(IInteractable interactable); bool CanInteractTo(IInteractable interactable, ScriptableObject payloadSo = null); diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs index ee8e89e6b..7dcb8ab7a 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs @@ -108,7 +108,7 @@ public bool IsInteractionHidden(IInteractable interactable) return true; } - protected virtual bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) + public virtual bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) { return RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(type, out solverType); } diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs index b22e70148..ad6c189f7 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs @@ -201,7 +201,7 @@ protected IInteractable GetNearestInteractable() return closest; } - protected override bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) + public override bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) { if (RestaurantInteractionEventSolvers.TypeToPlayerSolver.TryGetValue(type, out solverType)) { diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs b/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs index 99e36aa31..772d4e02e 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs @@ -1,18 +1,19 @@ using System; using System.Collections.Generic; +using JetBrains.Annotations; using UnityEngine; namespace DDD.Restaurant { public static class RestaurantInteractionEventSolvers { - public static Dictionary TypeToSolver = new() + public static readonly Dictionary TypeToSolver = new() { {InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)}, {InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)}, {InteractionType.RestaurantCook, typeof(RestaurantCookSolver)} }; - public static Dictionary TypeToPlayerSolver = new() + public static readonly Dictionary TypeToPlayerSolver = new() { {InteractionType.RestaurantOrder, typeof(RestaurantOrderPlayerSolver)}, }; @@ -46,31 +47,28 @@ public bool RequestInteraction(GameObject causer, GameObject target, Interaction var evt = MakeInteractionEvent(causer, target, interactionType, payload); evt.EventResult = false; - // Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로. - if (RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType)) + + IInteractor interactor = causer.GetComponent(); + if (interactor != null && interactor.CanSolveInteractionType(interactionType)) { - Component solverComponent = causer.GetComponent(solverType); - IInteractionSolver solver = solverComponent as IInteractionSolver; - IInteractor interactor = causer.GetComponent(); - IInteractable interactable = target.GetComponent(); - - // Cast solverComponent to IInteractable - if (solver is not null && interactor is not null) + if (interactor.FetchSolverTypeForInteraction(interactionType, out var solverType)) { - bool canExecute = solver.CanExecuteInteraction(interactor, interactable, evt.Payload); - if (canExecute) + // Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로. + if (solverType != null) { - evt.EventResult = solver.ExecuteInteraction(interactor, interactable, evt.Payload); - } - else - { - evt.EventResult = false; - } - } - else - { - // Should not reach here! - Debug.Assert(false, "Solver Component or Interactor is null"); + IInteractionSolver solver = causer.GetComponent(solverType) as IInteractionSolver; + IInteractable interactable = target.GetComponent(); + if (solver is not null) + { + bool canExecute = solver.CanExecuteInteraction(interactor, interactable, evt.Payload); + evt.EventResult = canExecute && solver.ExecuteInteraction(interactor, interactable, evt.Payload); + } + else + { + // Should not reach here! + Debug.Assert(false, "Solver Component or Interactor is null"); + } + } } }