ProjectDDD/Assets/_DDD/_Scripts/GameUi/New/DrinkDataExtensions.cs
2025-07-25 16:58:53 +09:00

59 lines
1.8 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 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;
}
}
}