Files
Emberwild/Assets/GAME/Script/Crafting/CraftingRecipe.cs
Mathew 78bfdf2828 Merge remote-tracking branch 'origin/feat/inport-props' into feat/craft-discovery
# Conflicts:
#	Assets/External/Animated PBR Chest Demo/Materials/WoodChest.mat
#	Packages/com.distantlands.cozy.core/Content/Integration/Import for BiRP.unitypackage.meta
#	Packages/com.distantlands.cozy.core/Content/Integration/Import for HDRP.unitypackage.meta
#	Packages/com.distantlands.cozy.core/Content/Integration/Import for URP.unitypackage.meta
2026-07-25 19:42:26 +02:00

54 lines
2.2 KiB
C#

using UnityEngine;
using Ashwild.Inventory;
namespace Ashwild.Crafting
{
/// <summary>
/// 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.
/// </summary>
[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;
/// <summary>
/// The station this recipe must be crafted on, or <see cref="CraftingStationType.None"/> when it
/// needs none.
/// </summary>
public CraftingStationType RequiredStation => requiredStation;
/// <summary>
/// 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.
/// </summary>
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;
}
}
}