using System.Collections.Generic; namespace DDD { public static class DrinkDataExtensions { public static List 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 ExtractIngredients(params string[] values) { var list = new List(); 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 GetTasteDatas(this DrinkData data) { var tasteDatas = new List(); 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; } } }