ProjectDDD/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs

54 lines
2.4 KiB
C#

using System;
using System.Collections.Generic;
using JetBrains.Annotations;
using UnityEngine;
namespace DDD.Restaurant
{
public static class RestaurantInteractionEventSolvers
{
public static readonly Dictionary<InteractionType, Type> TypeToSolver = new()
{
{InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)},
{InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)},
{InteractionType.RestaurantCook, typeof(RestaurantCookSolver)}
};
public static readonly Dictionary<InteractionType, Type> TypeToPlayerSolver = new()
{
{InteractionType.RestaurantOrder, typeof(RestaurantOrderPlayerSolver)},
};
}
public class RestaurantInteractionEvent : RestaurantEventBase<InteractionType>
{
protected override bool EventSolve(GameObject causer, GameObject target, InteractionType interactionType,
ScriptableObject payload)
{
IInteractor interactor = causer.GetComponent<IInteractor>();
if (interactor != null && interactor.CanSolveInteractionType(interactionType))
{
if (interactor.FetchSolverTypeForInteraction(interactionType, out var solverType))
{
// Solve event directly. 이벤트 처리는 여기서 하고, 이벤트 호출로는 이런 이벤트가 호출되었고 결과가 어떻다는 거 전파하는 식으로.
if (solverType != null)
{
IInteractionSolver solver = causer.GetComponent(solverType) as IInteractionSolver;
IInteractable interactable = target.GetComponent<IInteractable>();
if (solver is not null)
{
bool canExecute = solver.CanExecuteInteraction(interactor, interactable, payload);
return canExecute && solver.ExecuteInteraction(interactor, interactable, payload);
}
else
{
// Should not reach here!
Debug.Assert(false, "Solver Component or Interactor is null");
}
}
}
}
return false;
}
}
}