using UnityEngine; using Ashwild.Inventory; namespace Ashwild.Crafting { /// /// Authoring data for one craftable result: what it produces, what it costs, and where it can be /// crafted. Pure data — the craft itself is performed by CraftingManager, which owns the player /// and discovery rules on top of what is declared here. /// [CreateAssetMenu(fileName = "NewRecipe", menuName = "Items/Crafting Recipe")] public class CraftingRecipe : ScriptableObject { [Header("Result")] [SerializeField] private string recipeName; [SerializeField] private ItemData resultItem; [SerializeField] private int resultQuantity = 1; [Header("Station")] [Tooltip("None = craftable bare-handed AND on every station. Any other value restricts this recipe to that station.")] [SerializeField] private CraftingStationType requiredStation = CraftingStationType.None; [Header("Ingredients")] [SerializeField] private CraftingIngredient[] ingredients; public string RecipeName => recipeName; public Sprite Icon => resultItem != null ? resultItem.Icon : null; public ItemData ResultItem => resultItem; public int ResultQuantity => resultQuantity; public CraftingIngredient[] Ingredients => ingredients; /// /// The station this recipe must be crafted on, or when it /// needs none. /// public CraftingStationType RequiredStation => requiredStation; /// /// Whether the given inventory holds enough of every ingredient to craft this recipe the given /// number of times. Purely a resource check — discovery and station rules are enforced by /// CraftingManager on top of it. /// public bool CanCraft(PlayerInventory inventory, int count = 1) { for (int i = 0; i < ingredients.Length; i++) { if (!inventory.HasItem(ingredients[i].item, ingredients[i].quantity * count)) return false; } return true; } } }