34 lines
1.1 KiB
C#
34 lines
1.1 KiB
C#
using UnityEngine;
|
|
using Ashwild.Inventory;
|
|
|
|
namespace Ashwild.Crafting
|
|
{
|
|
[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("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;
|
|
|
|
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;
|
|
}
|
|
}
|
|
}
|