using System; using System.Collections.Generic; using DDD.RestaurantOrders; using UnityEngine; namespace DDD { public static class RestaurantOrderSolvers { public static Dictionary TypeToOrderSolver = new() { { RestaurantOrderType.Wait, typeof(RestaurantOrderSolver_Wait) }, { RestaurantOrderType.Order, typeof(RestaurantOrderSolver_Order) }, { RestaurantOrderType.Serve, typeof(RestaurantOrderSolver_Serve) } }; } public class RestaurantOrderSolver : MonoBehaviour, IInteractionSolver { private Dictionary> _solvers = new(); private void Start() { foreach (var orderSolver in RestaurantOrderSolvers.TypeToOrderSolver) { var solver = (IInteractionSubsystemSolver)gameObject.AddComponent(orderSolver.Value); _solvers.Add(orderSolver.Key, solver); } } public bool ExecuteInteraction(IInteractor interactor, IInteractable interactable, ScriptableObject payloadSo = null) { return TryGetSolver(interactable, out var solver) && solver.ExecuteInteractionSubsystem(interactor, interactable, payloadSo); } public bool CanExecuteInteraction(IInteractor interactor = null, IInteractable interactable = null, ScriptableObject payloadSo = null) { return TryGetSolver(interactable, out var solver) && solver.CanExecuteInteractionSubsystem(interactor, interactable, payloadSo); } // Solver를 가져오는 공통 로직 private bool TryGetSolver(IInteractable interactable, out IInteractionSubsystemSolver solver) { solver = null; if (interactable is not IInteractionSubsystemObject subsystem) return false; var type = subsystem.GetInteractionSubsystemType(); return _solvers.TryGetValue(type, out solver); } } }