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

125 lines
4.6 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-27 22:55:07 +00:00
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;
2025-07-28 11:33:04 +00:00
private Dictionary<string, int> _foodRecipeIds = new();
private Dictionary<string, int> _drinkRecipeIds = new();
2025-07-27 19:32:41 +00:00
2025-07-28 11:33:04 +00:00
public IReadOnlyDictionary<string, int> FoodRecipeIds => _foodRecipeIds;
public IReadOnlyDictionary<string, int> DrinkRecipeIds => _drinkRecipeIds;
2025-07-27 19:32:41 +00:00
public override Task OnReadyNewFlow(GameFlowState newFlowState)
{
_foodRecipeIds.Clear();
_drinkRecipeIds.Clear();
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;
2025-07-29 15:56:47 +00:00
if (!DataManager.Instance.RecipeDataSo.TryGetDataById(recipeId, out RecipeData recipeData)) return false;
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-07-29 15:56:47 +00:00
if (_foodRecipeIds.Count >= MaxFoodCount || _foodRecipeIds.ContainsKey(recipeId)) return false;
var foodData = DataManager.Instance.FoodDataSo.GetDataById(recipeData.RecipeResult);
var craftableCount = foodData.GetCraftableCount();
foodData.ConsumeAllCraftableIngredients();
2025-07-28 11:33:04 +00:00
2025-07-29 15:56:47 +00:00
_foodRecipeIds[recipeId] = craftableCount;
added = true;
2025-07-28 11:33:04 +00:00
}
else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{
2025-07-29 15:56:47 +00:00
if (_drinkRecipeIds.Count >= MaxDrinkCount || _drinkRecipeIds.ContainsKey(recipeId)) return false;
var drinkData = DataManager.Instance.DrinkDataSo.GetDataById(recipeData.RecipeResult);
var craftableCount = drinkData.GetCraftableCount();
drinkData.ConsumeAllCraftableIngredients();
2025-07-28 11:33:04 +00:00
2025-07-29 15:56:47 +00:00
_drinkRecipeIds[recipeId] = craftableCount;
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;
2025-07-28 11:33:04 +00:00
if (!DataManager.Instance.RecipeDataSo.TryGetDataById(recipeId, out RecipeData recipeData)) return false;
bool removed = false;
int refundCount = 0;
if (recipeData.RecipeType == RecipeType.FoodRecipe)
2025-07-27 19:32:41 +00:00
{
2025-07-28 11:33:04 +00:00
if (_foodRecipeIds.TryGetValue(recipeId, out refundCount))
{
removed = _foodRecipeIds.Remove(recipeId);
evt.RecipeType = RecipeType.FoodRecipe;
if (removed)
{
var foodData = DataManager.Instance.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-07-28 11:33:04 +00:00
if (_drinkRecipeIds.TryGetValue(recipeId, out refundCount))
{
removed = _drinkRecipeIds.Remove(recipeId);
evt.RecipeType = RecipeType.DrinkRecipe;
if (removed)
{
var drinkData = DataManager.Instance.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-07-28 11:33:04 +00:00
public bool IsContainTodayMenu(string recipeId)=> _foodRecipeIds.ContainsKey(recipeId) || _drinkRecipeIds.ContainsKey(recipeId);
2025-07-27 19:32:41 +00:00
}
}