2025-07-22 11:15:20 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
2025-08-29 07:50:54 +00:00
|
|
|
using JetBrains.Annotations;
|
2025-07-22 11:15:20 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
2025-08-27 07:52:34 +00:00
|
|
|
namespace DDD.Restaurant
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
2025-08-05 08:09:14 +00:00
|
|
|
public static class RestaurantInteractionEventSolvers
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
2025-08-29 07:50:54 +00:00
|
|
|
public static readonly Dictionary<InteractionType, Type> TypeToSolver = new()
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
2025-08-20 09:55:30 +00:00
|
|
|
{InteractionType.RestaurantManagement, typeof(RestaurantManagementSolver)},
|
2025-08-27 04:05:08 +00:00
|
|
|
{InteractionType.RestaurantOrder, typeof(RestaurantOrderSolver)},
|
|
|
|
{InteractionType.RestaurantCook, typeof(RestaurantCookSolver)}
|
2025-07-22 11:15:20 +00:00
|
|
|
};
|
2025-08-29 07:50:54 +00:00
|
|
|
public static readonly Dictionary<InteractionType, Type> TypeToPlayerSolver = new()
|
2025-08-28 03:43:32 +00:00
|
|
|
{
|
|
|
|
{InteractionType.RestaurantOrder, typeof(RestaurantOrderPlayerSolver)},
|
|
|
|
};
|
2025-07-22 11:15:20 +00:00
|
|
|
}
|
|
|
|
|
2025-08-29 08:16:48 +00:00
|
|
|
public class RestaurantInteractionEvent : RestaurantEventBase<InteractionType>
|
|
|
|
{
|
|
|
|
protected override bool EventSolve(GameObject causer, GameObject target, InteractionType interactionType,
|
|
|
|
ScriptableObject payload)
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
2025-08-29 08:16:48 +00:00
|
|
|
if (!RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(interactionType, out var solverType))
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2025-08-29 08:16:48 +00:00
|
|
|
|
|
|
|
Component solverComponent = causer.GetComponent(solverType);
|
|
|
|
IInteractionSolver solver = solverComponent as IInteractionSolver;
|
2025-08-29 07:50:54 +00:00
|
|
|
IInteractor interactor = causer.GetComponent<IInteractor>();
|
2025-08-29 08:16:48 +00:00
|
|
|
IInteractable interactable = target.GetComponent<IInteractable>();
|
|
|
|
|
|
|
|
// Cast solverComponent to IInteractable
|
|
|
|
if (solver is not null && interactor is not null)
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
2025-08-29 08:16:48 +00:00
|
|
|
bool canExecute = solver.CanExecuteInteraction(interactor, interactable, payload);
|
|
|
|
if (canExecute)
|
2025-07-22 11:15:20 +00:00
|
|
|
{
|
2025-08-29 08:16:48 +00:00
|
|
|
return solver.ExecuteInteraction(interactor, interactable, payload);
|
2025-07-22 11:15:20 +00:00
|
|
|
}
|
2025-08-29 08:16:48 +00:00
|
|
|
|
|
|
|
return false;
|
2025-07-22 11:15:20 +00:00
|
|
|
}
|
|
|
|
|
2025-08-29 08:16:48 +00:00
|
|
|
// Should not reach here!
|
|
|
|
Debug.Assert(false, "Solver Component or Interactor is null");
|
|
|
|
return false;
|
2025-07-22 11:15:20 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|