diff --git a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs index 8131ac6dd..886cfc8f9 100644 --- a/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs +++ b/Assets/_DDD/_Scripts/Game/GameEvent/IInteractable.cs @@ -39,7 +39,7 @@ public InteractionDisplayParameters(string messageKey = "") public interface IInteractable { bool CanInteract(); - bool IsInteractionHidden(IInteractor interactor = null); + bool IsInteractionAvailable(); void OnInteracted(IInteractor interactor, ScriptableObject causerPayload = null); InteractionType GetInteractionType(); GameObject GetInteractableGameObject(); @@ -54,6 +54,7 @@ public interface IInteractor GameObject GetInteractorGameObject(); IInteractable GetFocusedInteractable(); bool CanSolveInteractionType(InteractionType interactionType); + bool IsInteractionHidden(IInteractable interactable); bool CanInteractTo(IInteractable interactable, ScriptableObject payloadSo = null); } @@ -62,5 +63,6 @@ public interface IInteractionSolver { bool ExecuteInteraction(IInteractor interactor, IInteractable interactable, ScriptableObject payload = null); bool CanExecuteInteraction(IInteractor interactor = null, IInteractable interactable = null, ScriptableObject payload = null); + bool CanSolveInteraction(IInteractor interactor, IInteractable interactable); } } diff --git a/Assets/_DDD/_Scripts/Game/GameEvent/InteractionSubsystem.cs b/Assets/_DDD/_Scripts/Game/GameEvent/InteractionSubsystem.cs index cbdc7a8c0..d3165af45 100644 --- a/Assets/_DDD/_Scripts/Game/GameEvent/InteractionSubsystem.cs +++ b/Assets/_DDD/_Scripts/Game/GameEvent/InteractionSubsystem.cs @@ -16,11 +16,11 @@ public interface IInteractionSubsystemObject : IInteractionSubsystemObject wh } public interface IInteractionSubsystemSolver - { - } - public interface IInteractionSubsystemSolver : IInteractionSubsystemSolver where T : Enum { bool ExecuteInteractionSubsystem(IInteractor interactor, IInteractable interactable, ScriptableObject payload = null); bool CanExecuteInteractionSubsystem(IInteractor interactor = null, IInteractable interactable = null, ScriptableObject payload = null); } + public interface IInteractionSubsystemSolver : IInteractionSubsystemSolver where T : Enum + { + } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs index c8352108f..ee8e89e6b 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterInteraction.cs @@ -82,8 +82,10 @@ private bool TryGetSolverForType(InteractionType type, out IInteractionSolver so public bool CanSolveInteractionType(InteractionType type) { - if (_cachedSolvers.TryGetValue(type, out var cachedSolver)) return cachedSolver != null; - + if (_cachedSolvers.TryGetValue(type, out var cachedSolver)) + { + return cachedSolver != null; + } if (!FetchSolverTypeForInteraction(type, out var solverType)) return false; if (transform.TryGetComponent(solverType, out var component) == false) return false; @@ -93,6 +95,19 @@ public bool CanSolveInteractionType(InteractionType type) return solver != null; } + public bool IsInteractionHidden(IInteractable interactable) + { + var interactionType = interactable.GetInteractionType(); + if (GetInteractionSolver(interactionType) is var solver) + { + if (solver != null && solver.CanSolveInteraction(this, interactable)) + { + return false; + } + } + return true; + } + protected virtual bool FetchSolverTypeForInteraction(InteractionType type, out Type solverType) { return RestaurantInteractionEventSolvers.TypeToSolver.TryGetValue(type, out solverType); diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/RestaurantCharacter.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Core/RestaurantCharacter.cs index f3a32003e..5599e61ac 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Core/RestaurantCharacter.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/RestaurantCharacter.cs @@ -37,6 +37,11 @@ public bool CanSolveInteractionType(InteractionType interactionType) return _interactionComponent.CanSolveInteractionType(interactionType); } + public bool IsInteractionHidden(IInteractable interactable) + { + return _interactionComponent.IsInteractionHidden(interactable); + } + public bool CanInteractTo(IInteractable interactable, ScriptableObject payloadSo = null) { return _interactionComponent.CanInteractTo(interactable, payloadSo); diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs index c9db8be25..093f2ddc1 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerInteraction.cs @@ -185,8 +185,9 @@ protected IInteractable GetNearestInteractable() if (col.TryGetComponent(out var interactable) == false) continue; var type = interactable.GetInteractionType(); - if (interactable.IsInteractionHidden(this)) continue; + if (!interactable.IsInteractionAvailable()) continue; if (CanSolveInteractionType(type) == false) continue; + if (IsInteractionHidden(interactable)) continue; float distance = Vector3.Distance(transform.position, col.transform.position); if (distance < closestDistance) diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/Cosmetic/InteractableHighlight.cs b/Assets/_DDD/_Scripts/Restaurant/Event/Cosmetic/InteractableHighlight.cs index 24006ed2f..a31f62ced 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/Cosmetic/InteractableHighlight.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/Cosmetic/InteractableHighlight.cs @@ -159,7 +159,11 @@ private InteractionOutlineType GetCurrentOutlineType() if (_interactionComponent is not IInteractable interactable) return InteractionOutlineType.None; - if (_interactionComponent.IsInteractionHidden(_interactor)) + if (!_interactionComponent.IsInteractionAvailable()) + { + return InteractionOutlineType.None; + } + if (_interactor.IsInteractionHidden(_interactionComponent)) { return InteractionOutlineType.None; } diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionComponent.cs b/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionComponent.cs index 7d757bfdd..8a8c447a5 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionComponent.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/RestaurantInteractionComponent.cs @@ -58,35 +58,26 @@ private static IEnumerable GetAllInteractionTypes() public virtual bool CanInteract() { - bool isInteractionVisible = !IsInteractionHidden(); + bool isInteractionAvailable = IsInteractionAvailable(); bool hasValidSubsystem = true; if (HasSubsystem(_interactionType)) { hasValidSubsystem = GetSubsystem(_interactionType).CanInteract(); } - return isInteractionVisible && hasValidSubsystem; + return isInteractionAvailable && hasValidSubsystem; } - public virtual bool IsInteractionHidden(IInteractor interactor = null) + public virtual bool IsInteractionAvailable() { + var currentGameFlowState = GameFlowManager.Instance.GameFlowDataSo.CurrentGameState; var flowDisabled = (currentGameFlowState & _interactionAvailableFlows) == 0; if (flowDisabled) { - return true; - } - - // only check if interactor is valid. if not, pass the check. - if (interactor != null && HasSubsystem(_interactionType)) - { - bool canSolve = interactor.CanSolveInteractionType(_interactionType); - if (!canSolve) - { - return true; - } + return false; } - return false; + return true; } public virtual void OnInteracted(IInteractor interactor, ScriptableObject payload = null) diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantSubsystemSolver.cs b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantSubsystemSolver.cs index 1e6326cde..60be7f94c 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantSubsystemSolver.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantSubsystemSolver.cs @@ -30,6 +30,19 @@ public bool CanExecuteInteraction(IInteractor interactor = null, IInteractable i solver.CanExecuteInteractionSubsystem(interactor, interactable, payload); } + public bool CanSolveInteraction(IInteractor interactor, IInteractable interactable) + { + if (interactable is IInteractionSubsystemOwner subsystemOwner) + { + if (subsystemOwner.TryGetSubsystemEnumType(out T subsystemType)) + { + return _solvers.ContainsKey(subsystemType); + } + } + + return false; + } + // Solver를 가져오는 공통 로직 private bool TryGetSolver(IInteractable interactable, out IInteractionSubsystemSolver solver) {