ProjectDDD/Assets/_DDD/_Scripts/GameState/RestaurantManagementSo.cs
2025-08-04 08:09:01 +09:00

164 lines
6.4 KiB
C#

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;
public int MaxCookwareCount = 6;
[Title("실시간 데이터")]
[ReadOnly, ShowInInspector] private Dictionary<string, int> _todayFoodRecipeIds = new();
[ReadOnly, ShowInInspector] private Dictionary<string, int> _todayDrinkRecipeIds = new();
[ReadOnly, ShowInInspector] private List<string> _todayWorkerIds = new();
[ReadOnly, ShowInInspector] private List<string> _todayCookwareIds = new();
public IReadOnlyDictionary<string, int> TodayFoodRecipeIds => _todayFoodRecipeIds;
public IReadOnlyDictionary<string, int> TodayDrinkRecipeIds => _todayDrinkRecipeIds;
public IReadOnlyList<string> TodayWorkerIds => _todayWorkerIds;
public IReadOnlyList<string> TodayCookwareIds => _todayCookwareIds;
public override Task OnReadyNewFlow(GameFlowState newFlowState)
{
_todayFoodRecipeIds.Clear();
_todayDrinkRecipeIds.Clear();
_todayWorkerIds.Clear();
_todayCookwareIds.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<RecipeDataSo>().TryGetDataById(recipeId, out RecipeData recipeData)) return false;
bool added = false;
if (recipeData.RecipeType == RecipeType.FoodRecipe)
{
if (_todayFoodRecipeIds.Count >= MaxFoodCount || _todayFoodRecipeIds.ContainsKey(recipeId)) return false;
var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(recipeData.RecipeResult);
var craftableCount = foodData.GetCraftableCount();
foodData.ConsumeAllCraftableIngredients();
_todayFoodRecipeIds[recipeId] = craftableCount;
added = true;
}
else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{
if (_todayDrinkRecipeIds.Count >= MaxDrinkCount || _todayDrinkRecipeIds.ContainsKey(recipeId)) return false;
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(recipeData.RecipeResult);
var craftableCount = drinkData.GetCraftableCount();
drinkData.ConsumeAllCraftableIngredients();
_todayDrinkRecipeIds[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<RecipeDataSo>().TryGetDataById(recipeId, out RecipeData recipeData)) return false;
bool removed = false;
int refundCount = 0;
if (recipeData.RecipeType == RecipeType.FoodRecipe)
{
if (_todayFoodRecipeIds.TryGetValue(recipeId, out refundCount))
{
removed = _todayFoodRecipeIds.Remove(recipeId);
evt.RecipeType = RecipeType.FoodRecipe;
if (removed)
{
var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(recipeData.RecipeResult);
foodData.RefundIngredients(refundCount);
}
}
}
else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{
if (_todayDrinkRecipeIds.TryGetValue(recipeId, out refundCount))
{
removed = _todayDrinkRecipeIds.Remove(recipeId);
evt.RecipeType = RecipeType.DrinkRecipe;
if (removed)
{
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(recipeData.RecipeResult);
drinkData.RefundIngredients(refundCount);
}
}
}
if (!removed) return false;
EventBus.Broadcast(evt);
return true;
}
public bool TryAddTodayCookware(ItemSlotUi itemSlotUi)
{
var itemId = itemSlotUi.Model.Id;
if (itemSlotUi.Model.Count <= 0 || DataManager.Instance.GetDataSo<CookwareDataSo>().TryGetDataById(itemId, out CookwareData cookwareData) == false) return false;
if (_todayCookwareIds.Count >= MaxCookwareCount || _todayCookwareIds.Contains(itemId)) return false;
_todayCookwareIds.Add(itemId);
EventBus.Broadcast(RestaurantEvents.TodayMenuAddedEvent);
return true;
}
public bool TryRemoveTodayCookware(ItemSlotUi itemSlotUi)
{
var itemId = itemSlotUi.Model.Id;
if (DataManager.Instance.GetDataSo<CookwareDataSo>().TryGetDataById(itemId, out CookwareData cookwareData) == false) return false;
if (_todayCookwareIds.Remove(itemId) == false) return false;
EventBus.Broadcast( RestaurantEvents.TodayMenuRemovedEvent);
return true;
}
public bool IsContainTodayMenu(string recipeId)=> _todayFoodRecipeIds.ContainsKey(recipeId) || _todayDrinkRecipeIds.ContainsKey(recipeId);
}
}