I'm currently working on a crafting system - this systems works fine when the disired item has only one requirement. If there is more then one requirement the system is broke.
Short description of how the system (should work) works before talking about code.
Every object has a monobehaviour-script which holds an scriptable object.
This scriptable object contains all the statistics and has a list of required items.
The warehouse has a monobehaviour-script and this has a list of content items.
To craft a new item it should compare the content with the requirements.
Based on the output the object will spawn. The right output is my problem!
**Item Class:**
[System.Serializable]
public class Item
{
public ScripableTradegood scripableTradegood;
public int amount;
}
**Warehouse**:
[Header("Warehouse Content")]
public List<Item> warehouseContent;
**Scriptable Object:**
[Header("Requirements")]
public List<Item> tradegoodRequirements;
**Here the problem:**
// Loop through the requirements
foreach (Item requirement in tradegoodRequirements)
{
// For each requirement check content in warehouse
foreach (Item content in warehouse.warehouseContent)
{
// When content is not requirement skip the check
if (content.scripableTradegood != requirement.scripableTradegood) continue;
// When right content was found
if (content.scripableTradegood == requirement.scripableTradegood)
{
// If required content amount isnt present return
if (content.amount < requirement.amount) return;
/*
* When the tradegood has only one requirement - I could just substract the requirements and exit out of the function.
* But when if I have more then one requirement - how can I check if all requirements a present before substracting them?
* Logically I would have to leave the second loop and continue to check the requirements from the first loop - But how can I achieve that?
* */
}
}
}
Where is mistake? Do I pursue the right approach?
I appreciate all of your help! :)