ProjectDDD/Assets/_DDD/_Scripts/GameUi/New/DrinkDataExtensions.cs
2025-07-28 07:55:07 +09:00

78 lines
2.4 KiB
C#

using System.Collections.Generic;
namespace DDD
{
public static class DrinkDataExtensions
{
public static List<IngredientEntry> GetIngredients(this DrinkData data)
{
return ExtractIngredients(
data.IngredientKey1, data.IngredientAmount1,
data.IngredientKey2, data.IngredientAmount2,
data.IngredientKey3, data.IngredientAmount3,
data.IngredientKey4, data.IngredientAmount4
);
}
private static List<IngredientEntry> ExtractIngredients(params string[] values)
{
var list = new List<IngredientEntry>();
for (int i = 0; i < values.Length; i += 2)
{
var key = values[i];
var amountStr = values[i + 1];
if (string.IsNullOrEmpty(key) || string.IsNullOrEmpty(amountStr)) continue;
if (int.TryParse(amountStr, out int amount))
{
list.Add(new IngredientEntry
{
IngredientId = key,
Amount = amount
});
}
}
return list;
}
public static List<TasteData> GetTasteDatas(this DrinkData data)
{
var tasteDatas = new List<TasteData>();
string[] tasteKeys = new[] { data.TasteKey1, data.TasteKey2, data.TasteKey3, data.TasteKey4 };
TasteDataSo tasteSo = DataManager.Instance.TasteDataSo;
foreach (var key in tasteKeys)
{
if (string.IsNullOrWhiteSpace(key)) continue;
if (tasteSo.TryGetDataById(key, out TasteData taste))
{
tasteDatas.Add(taste);
}
}
return tasteDatas;
}
public static int GetCraftableCount(this DrinkData data)
{
var ingredients = data.GetIngredients();
if (ingredients.Count == 0) return 0;
int minCraftable = int.MaxValue;
foreach (var ingredient in ingredients)
{
int owned = InventoryManager.Instance.GetItemCount(ingredient.IngredientId);
int craftable = owned / ingredient.Amount;
if (craftable < minCraftable)
minCraftable = craftable;
}
return minCraftable;
}
}
}