From 567c422f8cd42eba2437f9a8c2522716a1649be7 Mon Sep 17 00:00:00 2001 From: hazel Date: Mon, 26 Jan 2026 22:04:39 +0100 Subject: celesteia archive, last updated april 9th 2024 Signed-off-by: hazel --- source/resources/types/Recipe.cs | 48 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 source/resources/types/Recipe.cs (limited to 'source/resources/types/Recipe.cs') diff --git a/source/resources/types/Recipe.cs b/source/resources/types/Recipe.cs new file mode 100644 index 0000000..94dd9ba --- /dev/null +++ b/source/resources/types/Recipe.cs @@ -0,0 +1,48 @@ +using System.Collections.Generic; +using Celesteia.Game.Components.Items; + +namespace Celesteia.Resources.Types { + public class Recipe : IResourceType { + private byte id; + public readonly string Name; + public byte GetID() => id; + public void SetID(byte value) => id = value; + + public Part Result; + public List Ingredients; + + public Recipe(Part result, params Part[] ingredients) { + Result = result; + Ingredients = new List(ingredients); + } + + public bool Craftable(Inventory inventory) { + foreach (Part ingredient in Ingredients) + if (!inventory.ContainsAmount(ingredient.Key, ingredient.Amount)) return false; + + return true; + } + + public void Craft(Inventory inventory) { + if (!Craftable(inventory)) return; + + foreach (Part ingredient in Ingredients) + inventory.RemoveAmount(ingredient.Key, ingredient.Amount); + + inventory.AddItem(Result.Stack); + } + } + + public struct Part { + public NamespacedKey Key; + public int Amount; + + public Part(NamespacedKey key, int amount) { + Key = key; + Amount = amount; + } + + public ItemStack Stack => new ItemStack(Key, Amount); + public ItemType GetItemType() => ResourceManager.Items.GetResource(Key) as ItemType; + } +} \ No newline at end of file -- cgit v1.2.3