78 lines
2.4 KiB
C#
78 lines
2.4 KiB
C#
using System.Collections.Generic;
|
|
|
|
namespace DDD
|
|
{
|
|
public static class FoodDataExtensions
|
|
{
|
|
public static List<IngredientEntry> GetIngredients(this FoodData 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 FoodData data)
|
|
{
|
|
var tasteDatas = new List<TasteData>();
|
|
var 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 FoodData 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;
|
|
}
|
|
}
|
|
} |