54 lines
2.0 KiB
C#
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;
|
|
}
|
|
}
|
|
} |