Crafting Recipe

khaaki

New member
I have implemented a modular building system in my game. When a player places a new building part, I want the cost drawn from the player's inventory by crafting a new building part and then placing it.

To achieve this my thoughts are this:

1) When checking the placing conditions of the building part, I also check to see the player has the items needed in their inventory

var canCraft = myCrafter.Processor.CanCraft(craftingRecipe, inventory, amount);

My issue is that I'm unsure how to set the craftingRecipe before calling the method.

2) When the player places the building part actually craft it.

I have been looking through the Crafting Menu script, but sadly my coding skills are not good enough to understand how it works.

any help would be greatly appreciated :)
 
1)
So what I would do is before the game starts make a dictionary of <ItemDefinition, CraftingRecipe>. Where the ItemDefinition is the result of the Crafting Recipe.
You can do this by looping through all the crafting recipes in the InvetorySystemManager or InventorySystemDatabase.
This way when you are about to build something you can use the ItemDefinition to find the matching recipe.


2)
For that you need a Crafter component with it's CraftingProcessor. Then you can do
m_Crafter.Processor.CanCraft(craftingRecipe, inventory, amount)
and if that's true you can do:
m_Crafter.Processor.Craft(craftingRecipe, inventory, amount)

No need for a CraftingMenu if you don't need the UI part.

I hope that helps :)
 
Top