ProjectDDD/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs
김산 759384d626 Merge branch 'feature/Entry-ExitPoint' into develop
# Conflicts:
#	Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionEvents.cs
2025-08-29 19:35:08 +09:00

54 lines
2.0 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)
{
if (!RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType))
{
return false;
}
Component solverComponent = causer.GetComponent(solverType);
IInteractionSolver solver = solverComponent as IInteractionSolver;
IInteractor interactor = causer.GetComponent<IInteractor>();
IInteractable interactable = target.GetComponent<IInteractable>();
// Cast solverComponent to IInteractable
if (solver is not null && interactor is not null)
{
bool canExecute = solver.CanExecuteInteraction(interactor, interactable, payload);
if (canExecute)
{
return solver.ExecuteInteraction(interactor, interactable, payload);
}
return false;
}
// Should not reach here!
Debug.Assert(false, "Solver Component or Interactor is null");
return false;
}
}
}