diff --git a/Assets/_DDD/Restaurant/Environments/Interactables/Common/RestaurantOrder.prefab b/Assets/_DDD/Restaurant/Environments/Interactables/Common/RestaurantOrder.prefab index 5d6eeb540..59c8fd213 100644 --- a/Assets/_DDD/Restaurant/Environments/Interactables/Common/RestaurantOrder.prefab +++ b/Assets/_DDD/Restaurant/Environments/Interactables/Common/RestaurantOrder.prefab @@ -167,7 +167,7 @@ MonoBehaviour: Data: - Name: Entry: 12 - Data: 2 + Data: 3 - Name: Entry: 7 Data: @@ -192,6 +192,18 @@ MonoBehaviour: - Name: Entry: 8 Data: + - Name: + Entry: 7 + Data: + - Name: $k + Entry: 3 + Data: 8 + - Name: $v + Entry: 10 + Data: 1 + - Name: + Entry: 8 + Data: - Name: Entry: 13 Data: diff --git a/Assets/_DDD/_Scripts/Game/GameObject/VirtualItem.cs b/Assets/_DDD/_Scripts/Game/GameObject/VirtualItem.cs index 883993f82..576bd631b 100644 --- a/Assets/_DDD/_Scripts/Game/GameObject/VirtualItem.cs +++ b/Assets/_DDD/_Scripts/Game/GameObject/VirtualItem.cs @@ -11,7 +11,7 @@ public VirtualItem(string itemId) _itemId = itemId; } - public string GetCarrierId() => _itemId; + public string GetId() => _itemId; public CarriableType GetCarriableType() => CarriableType.VirtualItem; public GameObject GetGameObject() => null; diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs index 81abaa03d..d2624418a 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Core/CharacterCarrier.cs @@ -12,8 +12,9 @@ public enum CarriableType public interface ICarrier { GameObject GetCarrierGameObject(); - string GetCarrierId(); + string GetCurrentCarriableId(); ICarriable GetCurrentCarriable(); + bool IsCarrying(); bool CanCarryTo(ICarriable carriable); void Carry(ICarriable carriable); void Use(ICarriable carriable); @@ -21,7 +22,7 @@ public interface ICarrier public interface ICarriable { - string GetCarrierId(); + string GetId(); CarriableType GetCarriableType(); void OnCarried(ICarrier carrier); bool CanCarry(); @@ -40,9 +41,9 @@ public GameObject GetCarrierGameObject() return gameObject; } - public string GetCarrierId() + public string GetCurrentCarriableId() { - return _currentCarriable.GetCarrierId(); + return _currentCarriable.GetId(); } public ICarriable GetCurrentCarriable() @@ -50,6 +51,11 @@ public ICarriable GetCurrentCarriable() return _currentCarriable; } + public bool IsCarrying() + { + return GetCurrentCarriable() != null; + } + public bool CanCarryTo(ICarriable carriable) { if (_currentCarriable != null) return false; @@ -65,7 +71,7 @@ public void Carry(ICarriable carriable) _currentCarriable.OnCarried(this); _speechBubble ??= GetComponentInChildren(); - _speechBubble?.Show(_currentCarriable.GetCarrierId()); + _speechBubble?.Show(_currentCarriable.GetId()); } public void Use(ICarriable carriable) diff --git a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerCharacter.cs b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerCharacter.cs index 1abe46f50..26e4a26ef 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerCharacter.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Character/Player/PlayerCharacter.cs @@ -2,6 +2,7 @@ namespace DDD.Restaurant { + [RequireComponent(typeof(CharacterCarrier))] [RequireComponent(typeof(PlayerMovement))] public class PlayerCharacter : RestaurantCharacter { diff --git a/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs b/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs index 5384e5cb6..8322d98c0 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Environment/Interactions/InteractionSubsystem_Order.cs @@ -21,6 +21,8 @@ public class RestaurantOrderObjectState public string RecipeId; public string FoodId; + + public string ServedFoodId; } public interface IRestaurantOrderObject diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Order.cs b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Order.cs index a03a0bbff..240f7c00c 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Order.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Order.cs @@ -16,6 +16,7 @@ public string MenuId public class RestaurantOrderEvent : IEvent { public RestaurantOrderObjectState OrderObjectState; + public RestaurantOrderType OrderPhase; } public class RestaurantOrderSolver_Order : RestaurantOrderSolverBase @@ -53,8 +54,11 @@ public override bool ExecuteInteractionSubsystem(IInteractor interactor, IIntera RestaurantOrderMenuPayload orderPayload = ScriptableObject.CreateInstance(); orderPayload.MenuId = recipeMenu; - RestaurantOrderEvent evt = new RestaurantOrderEvent(); - evt.OrderObjectState = orderObject?.GetOrderObjectState(); + RestaurantOrderEvent evt = new RestaurantOrderEvent + { + OrderObjectState = orderObject?.GetOrderObjectState() + , OrderPhase = RestaurantOrderType.Order + }; EventBus.Broadcast(evt); return base.ExecuteInteractionSubsystem(interactor, interactable, payload); diff --git a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Serve.cs b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Serve.cs index d4718a97d..351c6749b 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Serve.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Event/Solvers/RestaurantOrders/RestaurantOrderSolver_Serve.cs @@ -6,11 +6,40 @@ public class RestaurantOrderSolver_Serve : RestaurantOrderSolverBase { public override bool ExecuteInteractionSubsystem(IInteractor interactor, IInteractable interactable, ScriptableObject payload = null) { - return base.ExecuteInteractionSubsystem(interactor, interactable, payload); + var carrier = interactor?.GetInteractorGameObject()?.GetComponent(); + if(carrier == null) return false; + var orderObject = GetRestaurantOrderObject(interactable); + if(orderObject == null) return false; + if(carrier.GetCurrentCarriable() == null) return false; + + string carriedFoodId = carrier.GetCurrentCarriableId(); + orderObject.GetOrderObjectState().ServedFoodId = carriedFoodId; + + bool result = base.ExecuteInteractionSubsystem(interactor, interactable, payload); + + // ExecuteInteractionSubsystem 이후에 음식 제거 - 미리 제거하면 CanExecute 통과 못 함 + carrier.Use(carrier.GetCurrentCarriable()); + + // OnFoodServed (Consume Bill Hud item) + RestaurantOrderEvent evt = new RestaurantOrderEvent + { + OrderObjectState = orderObject?.GetOrderObjectState() + , OrderPhase = RestaurantOrderType.Serve + }; + EventBus.Broadcast(evt); + + return result; } public override bool CanExecuteInteractionSubsystem(IInteractor interactor = null, IInteractable interactable = null, ScriptableObject payload = null) { + // Does interactor carry any food? + var carrier = interactor?.GetInteractorGameObject()?.GetComponent(); + if (carrier != null) + { + return carrier.IsCarrying(); + } + return false; } } diff --git a/Assets/_DDD/_Scripts/Restaurant/Ui/Hud/BillHud.cs b/Assets/_DDD/_Scripts/Restaurant/Ui/Hud/BillHud.cs index 8df145532..9117c2102 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Ui/Hud/BillHud.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Ui/Hud/BillHud.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; @@ -8,6 +9,7 @@ public class BillHud : MonoBehaviour, IEventHandler { [SerializeField] private RectTransform _billItemsLayoutTransform; [SerializeField] private GameObject _billItemPrefab; + private readonly Dictionary _billItemMap = new(); private void Start() { @@ -18,9 +20,24 @@ private void Start() public void HandleEvent(RestaurantOrderEvent evt) { - var billItem = Instantiate(_billItemPrefab, _billItemsLayoutTransform); - var sprite = DataManager.Instance.GetSprite(evt.OrderObjectState?.FoodId); - billItem.GetComponent().sprite = sprite; + if (evt.OrderPhase == RestaurantOrderType.Order) + { + var orderState = evt.OrderObjectState; + if (orderState == null) return; + var billItem = Instantiate(_billItemPrefab, _billItemsLayoutTransform); + var sprite = DataManager.Instance.GetSprite(orderState.FoodId); + billItem.GetComponent().sprite = sprite; + _billItemMap[orderState.Customer] = billItem; + } + else if (evt.OrderPhase == RestaurantOrderType.Serve) + { + // Find bill item by customer from _billItemMap, then destroy it. + if (_billItemMap.TryGetValue(evt.OrderObjectState.Customer, out var billItem)) + { + Destroy(billItem); + _billItemMap.Remove(evt.OrderObjectState.Customer); + } + } } } } \ No newline at end of file diff --git a/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/PropUiDisplayComponent.cs b/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/PropUiDisplayComponent.cs index a8d034ae6..412581a87 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/PropUiDisplayComponent.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/PropUiDisplayComponent.cs @@ -32,9 +32,8 @@ protected virtual void Initialize() Debug.LogError($"Interaction Subsystem<{typeof(T)}> is not exist"); return; } - - // TODO: 임시 나중에 제대로 수정할 것 - var uiGameObject = Instantiate(new GameObject("TemporaryUi"), transform); + + var uiGameObject = Instantiate(new GameObject("PropWorldUi"), transform); _spriteRenderer = uiGameObject.AddComponent(); UpdateSprite(); @@ -67,7 +66,7 @@ private bool GetOwnerInteractable(out IInteractable interactable) protected virtual int GetDisplayLayer() { - return LayerMask.NameToLayer("WorldUI"); + return LayerMask.NameToLayer(LayerConstants.WorldUi); } protected virtual Sprite GetDisplaySprite() diff --git a/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/RestaurantUiDisplayComponent.cs b/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/RestaurantUiDisplayComponent.cs index aa8d0454e..56880d5a5 100644 --- a/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/RestaurantUiDisplayComponent.cs +++ b/Assets/_DDD/_Scripts/Restaurant/Ui/OrderUi/Component/RestaurantUiDisplayComponent.cs @@ -37,7 +37,11 @@ protected override void UpdateSpriteTransform() protected override Sprite GetDisplaySprite() { - if (GetCurrentInteractionType() == RestaurantOrderType.Serve && _interactionSubsystemObject != null) + if (_interactionSubsystemObject == null) + return base.GetDisplaySprite(); + + if (GetCurrentInteractionType() == RestaurantOrderType.Serve || + GetCurrentInteractionType() == RestaurantOrderType.Busy) { // Sprite by current restaurant order type. get from RestaurantOrderObject. if (_interactionSubsystemObject is IRestaurantOrderObject orderObject) @@ -76,9 +80,14 @@ protected override Vector3 GetDisplayPosition() protected override int GetDisplayLayer() { - if (GetCurrentInteractionType() == RestaurantOrderType.Serve) + if (GetCurrentInteractionType() != RestaurantOrderType.Serve && + GetCurrentInteractionType() != RestaurantOrderType.Busy) { - return LayerMask.NameToLayer("Prop"); + return LayerMask.NameToLayer(LayerConstants.Prop); + } + else + { + return LayerMask.NameToLayer(LayerConstants.WorldUi); } return base.GetDisplayLayer(); } diff --git a/Assets/_DDD/_Scripts/Utilities/Constants.cs b/Assets/_DDD/_Scripts/Utilities/Constants.cs index 8bc7ccd7a..e89072d85 100644 --- a/Assets/_DDD/_Scripts/Utilities/Constants.cs +++ b/Assets/_DDD/_Scripts/Utilities/Constants.cs @@ -66,4 +66,10 @@ public static class SpriteConstants public const string EmptyFoodSpriteKey = "EmptyFood"; public const string EmptyWorker = "EmptyWorker"; } + + public static class LayerConstants + { + public const string Prop = "Prop"; + public const string WorldUi = "WorldUI"; + } } \ No newline at end of file