using System; using System.Collections.Generic; using System.Threading.Tasks; using Sirenix.OdinInspector; using UnityEngine; namespace DDD { [CreateAssetMenu(fileName = "RestaurantManagementSo", menuName = "GameState/RestaurantManagementSo")] public class RestaurantManagementSo : GameFlowTask { // TODO : 체크리스트 기능 // TODO : 조리도구 등록, 해제 기능 public ItemSlotUi ItemSlotUiPrefab; [Title("선택된 메뉴 상세 내용")] public TasteHashTagSlotUi TasteHashTagSlotUiPrefab; public Color FoodTasteOutlineColor = Color.magenta; public Color DrinkTasteOutlineColor = Color.magenta; [Title("오늘의 메뉴")] public int MaxFoodCount = 8; public int MaxDrinkCount = 6; private Dictionary _foodRecipeIds = new(); private Dictionary _drinkRecipeIds = new(); public IReadOnlyDictionary FoodRecipeIds => _foodRecipeIds; public IReadOnlyDictionary DrinkRecipeIds => _drinkRecipeIds; public override Task OnReadyNewFlow(GameFlowState newFlowState) { _foodRecipeIds.Clear(); _drinkRecipeIds.Clear(); return Task.CompletedTask; } public bool TryAddTodayMenu(ItemSlotUi itemSlotUi) { string recipeId = itemSlotUi.Model.Id; if (itemSlotUi.Model.ItemType != ItemType.Recipe) return false; if (!DataManager.Instance.GetDataSo().TryGetDataById(recipeId, out RecipeData recipeData)) return false; bool added = false; if (recipeData.RecipeType == RecipeType.FoodRecipe) { if (_foodRecipeIds.Count >= MaxFoodCount || _foodRecipeIds.ContainsKey(recipeId)) return false; var foodData = DataManager.Instance.GetDataSo().GetDataById(recipeData.RecipeResult); var craftableCount = foodData.GetCraftableCount(); foodData.ConsumeAllCraftableIngredients(); _foodRecipeIds[recipeId] = craftableCount; added = true; } else if (recipeData.RecipeType == RecipeType.DrinkRecipe) { if (_drinkRecipeIds.Count >= MaxDrinkCount || _drinkRecipeIds.ContainsKey(recipeId)) return false; var drinkData = DataManager.Instance.GetDataSo().GetDataById(recipeData.RecipeResult); var craftableCount = drinkData.GetCraftableCount(); drinkData.ConsumeAllCraftableIngredients(); _drinkRecipeIds[recipeId] = craftableCount; added = true; } if (added) { EventBus.Broadcast(RestaurantEvents.TodayMenuAddedEvent); } return added; } public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi) { string recipeId = itemSlotUi.Model.Id; var evt = RestaurantEvents.TodayMenuRemovedEvent; if (!DataManager.Instance.GetDataSo().TryGetDataById(recipeId, out RecipeData recipeData)) return false; bool removed = false; int refundCount = 0; if (recipeData.RecipeType == RecipeType.FoodRecipe) { if (_foodRecipeIds.TryGetValue(recipeId, out refundCount)) { removed = _foodRecipeIds.Remove(recipeId); evt.RecipeType = RecipeType.FoodRecipe; if (removed) { var foodData = DataManager.Instance.GetDataSo().GetDataById(recipeData.RecipeResult); foodData.RefundIngredients(refundCount); } } } else if (recipeData.RecipeType == RecipeType.DrinkRecipe) { if (_drinkRecipeIds.TryGetValue(recipeId, out refundCount)) { removed = _drinkRecipeIds.Remove(recipeId); evt.RecipeType = RecipeType.DrinkRecipe; if (removed) { var drinkData = DataManager.Instance.GetDataSo().GetDataById(recipeData.RecipeResult); drinkData.RefundIngredients(refundCount); } } } if (!removed) return false; EventBus.Broadcast(evt); return true; } public bool IsContainTodayMenu(string recipeId)=> _foodRecipeIds.ContainsKey(recipeId) || _drinkRecipeIds.ContainsKey(recipeId); } }