ProjectDDD/Assets/_DDD/_Scripts/GameState/RestaurantManagementSo.cs

164 lines
6.4 KiB
C#
Raw Normal View History

2025-07-27 22:55:07 +00:00
using System;
2025-07-27 19:32:41 +00:00
using System.Collections.Generic;
using System.Threading.Tasks;
using Sirenix.OdinInspector;
using UnityEngine;
namespace DDD
{
2025-07-27 19:51:11 +00:00
[CreateAssetMenu(fileName = "RestaurantManagementSo", menuName = "GameState/RestaurantManagementSo")]
public class RestaurantManagementSo : GameFlowTask
2025-07-27 19:32:41 +00:00
{
2025-07-30 07:46:11 +00:00
// TODO : 체크리스트 기능
// TODO : 조리도구 등록, 해제 기능
2025-07-27 22:55:07 +00:00
public ItemSlotUi ItemSlotUiPrefab;
[Title("선택된 메뉴 상세 내용")]
public TasteHashTagSlotUi TasteHashTagSlotUiPrefab;
public Color FoodTasteOutlineColor = Color.magenta;
public Color DrinkTasteOutlineColor = Color.magenta;
2025-08-03 23:09:01 +00:00
[Title("오늘의 레스토랑 상태")]
2025-07-27 22:55:07 +00:00
public int MaxFoodCount = 8;
public int MaxDrinkCount = 6;
2025-08-03 23:09:01 +00:00
public int MaxCookwareCount = 6;
2025-07-27 22:55:07 +00:00
2025-08-03 23:09:01 +00:00
[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();
2025-07-27 19:32:41 +00:00
2025-08-03 23:09:01 +00:00
public IReadOnlyDictionary<string, int> TodayFoodRecipeIds => _todayFoodRecipeIds;
public IReadOnlyDictionary<string, int> TodayDrinkRecipeIds => _todayDrinkRecipeIds;
public IReadOnlyList<string> TodayWorkerIds => _todayWorkerIds;
public IReadOnlyList<string> TodayCookwareIds => _todayCookwareIds;
2025-07-27 19:32:41 +00:00
public override Task OnReadyNewFlow(GameFlowState newFlowState)
{
2025-08-03 23:09:01 +00:00
_todayFoodRecipeIds.Clear();
_todayDrinkRecipeIds.Clear();
_todayWorkerIds.Clear();
_todayCookwareIds.Clear();
2025-07-27 19:32:41 +00:00
return Task.CompletedTask;
}
2025-07-29 15:56:47 +00:00
public bool TryAddTodayMenu(ItemSlotUi itemSlotUi)
2025-07-27 19:32:41 +00:00
{
string recipeId = itemSlotUi.Model.Id;
2025-07-28 11:33:04 +00:00
if (itemSlotUi.Model.ItemType != ItemType.Recipe) return false;
if (!DataManager.Instance.GetDataSo<RecipeDataSo>().TryGetDataById(recipeId, out RecipeData recipeData)) return false;
2025-07-29 15:56:47 +00:00
bool added = false;
2025-07-28 11:33:04 +00:00
if (recipeData.RecipeType == RecipeType.FoodRecipe)
2025-07-27 19:32:41 +00:00
{
2025-08-03 23:09:01 +00:00
if (_todayFoodRecipeIds.Count >= MaxFoodCount || _todayFoodRecipeIds.ContainsKey(recipeId)) return false;
2025-07-29 15:56:47 +00:00
var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(recipeData.RecipeResult);
2025-07-29 15:56:47 +00:00
var craftableCount = foodData.GetCraftableCount();
foodData.ConsumeAllCraftableIngredients();
2025-07-28 11:33:04 +00:00
2025-08-03 23:09:01 +00:00
_todayFoodRecipeIds[recipeId] = craftableCount;
2025-07-29 15:56:47 +00:00
added = true;
2025-07-28 11:33:04 +00:00
}
else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{
2025-08-03 23:09:01 +00:00
if (_todayDrinkRecipeIds.Count >= MaxDrinkCount || _todayDrinkRecipeIds.ContainsKey(recipeId)) return false;
2025-07-29 15:56:47 +00:00
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(recipeData.RecipeResult);
2025-07-29 15:56:47 +00:00
var craftableCount = drinkData.GetCraftableCount();
drinkData.ConsumeAllCraftableIngredients();
2025-07-28 11:33:04 +00:00
2025-08-03 23:09:01 +00:00
_todayDrinkRecipeIds[recipeId] = craftableCount;
2025-07-29 15:56:47 +00:00
added = true;
2025-07-27 19:32:41 +00:00
}
2025-07-29 15:56:47 +00:00
if (added)
{
EventBus.Broadcast(RestaurantEvents.TodayMenuAddedEvent);
}
return added;
2025-07-27 19:32:41 +00:00
}
2025-07-29 15:56:47 +00:00
public bool TryRemoveTodayMenu(ItemSlotUi itemSlotUi)
2025-07-27 19:32:41 +00:00
{
string recipeId = itemSlotUi.Model.Id;
var evt = RestaurantEvents.TodayMenuRemovedEvent;
if (!DataManager.Instance.GetDataSo<RecipeDataSo>().TryGetDataById(recipeId, out RecipeData recipeData)) return false;
2025-07-28 11:33:04 +00:00
bool removed = false;
int refundCount = 0;
if (recipeData.RecipeType == RecipeType.FoodRecipe)
2025-07-27 19:32:41 +00:00
{
2025-08-03 23:09:01 +00:00
if (_todayFoodRecipeIds.TryGetValue(recipeId, out refundCount))
2025-07-28 11:33:04 +00:00
{
2025-08-03 23:09:01 +00:00
removed = _todayFoodRecipeIds.Remove(recipeId);
2025-07-28 11:33:04 +00:00
evt.RecipeType = RecipeType.FoodRecipe;
if (removed)
{
var foodData = DataManager.Instance.GetDataSo<FoodDataSo>().GetDataById(recipeData.RecipeResult);
2025-07-29 15:56:47 +00:00
foodData.RefundIngredients(refundCount);
2025-07-28 11:33:04 +00:00
}
}
2025-07-27 19:32:41 +00:00
}
2025-07-28 11:33:04 +00:00
else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
2025-07-27 19:32:41 +00:00
{
2025-08-03 23:09:01 +00:00
if (_todayDrinkRecipeIds.TryGetValue(recipeId, out refundCount))
2025-07-28 11:33:04 +00:00
{
2025-08-03 23:09:01 +00:00
removed = _todayDrinkRecipeIds.Remove(recipeId);
2025-07-28 11:33:04 +00:00
evt.RecipeType = RecipeType.DrinkRecipe;
if (removed)
{
var drinkData = DataManager.Instance.GetDataSo<DrinkDataSo>().GetDataById(recipeData.RecipeResult);
2025-07-29 15:56:47 +00:00
drinkData.RefundIngredients(refundCount);
2025-07-28 11:33:04 +00:00
}
}
2025-07-27 19:32:41 +00:00
}
2025-07-28 11:33:04 +00:00
if (!removed) return false;
2025-07-27 19:32:41 +00:00
EventBus.Broadcast(evt);
return true;
}
2025-08-03 23:09:01 +00:00
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);
2025-07-27 19:32:41 +00:00
}
}