diff options
| author | hazel <hazel@hazelthats.me> | 2026-01-26 22:04:39 +0100 |
|---|---|---|
| committer | hazel <hazel@hazelthats.me> | 2026-01-26 22:04:39 +0100 |
| commit | 567c422f8cd42eba2437f9a8c2522716a1649be7 (patch) | |
| tree | 93c5b296f3b7c14b626d0aadf5cad37764c41c74 /source/resources/types/Recipe.cs | |
| download | celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.gz celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.tar.bz2 celesteia-567c422f8cd42eba2437f9a8c2522716a1649be7.zip | |
celesteia archive, last updated april 9th 2024
Signed-off-by: hazel <hazel@hazelthats.me>
Diffstat (limited to 'source/resources/types/Recipe.cs')
| -rw-r--r-- | source/resources/types/Recipe.cs | 48 |
1 files changed, 48 insertions, 0 deletions
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<Part> Ingredients; + + public Recipe(Part result, params Part[] ingredients) { + Result = result; + Ingredients = new List<Part>(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 |
