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

112 lines
4.0 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;
}
public bool TryAddTodayMenu(IInventorySlotUi itemSlotUi)
{
string recipeId = itemSlotUi.Model.Id;
2025-07-28 11:33:04 +00:00
if (itemSlotUi.Model.ItemType != ItemType.Recipe) return false;
if (!DataManager.Instance.RecipeDataSo.TryGetDataById(recipeId, out RecipeData recipeData))
return false;
if (recipeData.RecipeType == RecipeType.FoodRecipe)
2025-07-27 19:32:41 +00:00
{
2025-07-28 11:33:04 +00:00
if (_foodRecipeIds.Count >= MaxFoodCount || _foodRecipeIds.ContainsKey(recipeId))
return false;
_foodRecipeIds[recipeId] = 1;
}
else if (recipeData.RecipeType == RecipeType.DrinkRecipe)
{
if (_drinkRecipeIds.Count >= MaxDrinkCount || _drinkRecipeIds.ContainsKey(recipeId))
return false;
_drinkRecipeIds[recipeId] = 1;
2025-07-27 19:32:41 +00:00
}
EventBus.Broadcast(RestaurantEvents.TodayMenuAddedEvent);
return true;
}
public bool TryRemoveTodayMenu(IInventorySlotUi itemSlotUi)
{
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);
CraftingHelper.RefundIngredients(foodData.GetIngredients(), refundCount);
}
}
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);
CraftingHelper.RefundIngredients(drinkData.GetIngredients(), refundCount);
}
}
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
}
}