CapersProject/Assets/02.Scripts/DDD/ScriptableObject/Class/CraftRecipeData.cs
2025-02-10 11:13:46 +09:00

123 lines
4.5 KiB
C#

using System;
using System.Collections.Generic;
using DDD.Interfaces;
using DDD.Uis.Tycoon;
using Newtonsoft.Json;
using Sirenix.OdinInspector;
using UnityEngine;
namespace DDD.ScriptableObjects
{
/// <summary>
/// 제작 도구 열거형
/// 1: 손질, 2: 솥, 3: 튀김, 4: 플레이팅
/// </summary>
public enum CraftingTool
{
Cutting = 1,
Pot = 2,
Frying = 3,
Plating = 4
}
[Serializable]
public class CraftRecipeData : IIdx
{
[BoxGroup("Json 데이터 영역")]
[JsonProperty]
[field: SerializeField, Tooltip("Idx"), BoxGroup("Json 데이터 영역")]
public string Idx { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("이름"), BoxGroup("Json 데이터 영역")]
public string Name { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("설명"), BoxGroup("Json 데이터 영역")]
public string Description { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("가격"), BoxGroup("Json 데이터 영역")]
public int Price { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("1번 재료 Idx"), BoxGroup("Json 데이터 영역")]
public string IngredientIdx1 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("1번 재료 갯수"), BoxGroup("Json 데이터 영역")]
public int IngredientCount1 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("2번 재료 Idx"), BoxGroup("Json 데이터 영역")]
public string IngredientIdx2 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("2번 재료 갯수"), BoxGroup("Json 데이터 영역")]
public int IngredientCount2 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("3번 재료 Idx"), BoxGroup("Json 데이터 영역")]
public string IngredientIdx3 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("3번 재료 갯수"), BoxGroup("Json 데이터 영역")]
public int IngredientCount3 { get; set; }
[JsonProperty]
[field: SerializeField, Tooltip("제작 순서"), BoxGroup("Json 데이터 영역")]
public int CraftOrder { get; set; }
[BoxGroup("직접 추가하는 영역")]
[JsonIgnore]
[field: SerializeField, BoxGroup("직접 추가하는 영역")]
public Sprite Sprite { get; set; }
[JsonIgnore]
[field: SerializeField]
public List<CraftingIngredient> ValidIngredients { get; set; } = new(3);
[JsonIgnore]
[field: ShowInInspector]
public Queue<CraftingTool> CraftingToolQueue { get; set; } = new(4);
public List<CraftingIngredient> GetValidIngredients()
{
List<CraftingIngredient> newList = new List<CraftingIngredient>();
if (!string.IsNullOrEmpty(IngredientIdx1)) newList.Add(new CraftingIngredient(IngredientIdx1, IngredientCount1));
if (!string.IsNullOrEmpty(IngredientIdx2)) newList.Add(new CraftingIngredient(IngredientIdx2, IngredientCount2));
if (!string.IsNullOrEmpty(IngredientIdx3)) newList.Add(new CraftingIngredient(IngredientIdx3, IngredientCount3));
return newList;
}
/// <summary>
/// 제작 순서 큐
/// CraftOrder의 각 자리 숫자를 제작 도구(CraftingTool)로 변환하여 순서대로 큐에 저장합니다.
/// 예를 들어 CraftOrder가 213이면, 큐에는 [솥, 손질, 튀김] 순으로 저장됩니다.
/// </summary>
public Queue<CraftingTool> GetCraftingToolQueue()
{
Queue<CraftingTool> newQueue = new Queue<CraftingTool>();
string orderString = CraftOrder.ToString();
foreach (char c in orderString)
{
if (int.TryParse(c.ToString(), out int step))
{
// Enum에 정의된 값인지 확인
if (Enum.IsDefined(typeof(CraftingTool), step))
{
newQueue.Enqueue((CraftingTool)step);
}
else
{
Debug.LogError($"유효하지 않은 제작 순서 단계: {step}");
}
}
}
return newQueue;
}
}
}