Well I need help with my checking if inventory contains the itemID and the itemAmount,
my code works just fine but it checks for only one of the materials at a time.
Lets say I need: 3 wood and 5 rocks to make a firepit.
So I run this:
//Getting all the recipes.
for (int i = 0; i < recipes.Count; i++)
{
//Getting the materials for the recipe.
foreach (KeyValuePair<int, int> materials in recipes*.materials)*
{
//Splitting up the materials in the recipe [itemID = materials.Key, itemAmount = materials.Value]
//And checking if the inventory contains the itemID and the itemAmount.
print("Material: " + materials.Key + " Amount: " + materials.Value);
if (inventory.CheckForItemIDAndItemAmount(materials.Key, materials.Value))
{
//If inventory contains the itemID and itemAmount add blank item to the craftible list.
craftableItems.Add(new ItemTest());
}
}
}
The proplem is lets say I do have the 3 wood. it returns true and adds the blank item even though I don’t have the 5 rocks. or vise versa
Because its only checking for the materials one at a time and returning true.
public bool CheckForItemIDAndItemAmount(int itemID, int itemAmount)
{
//Checks how many items are in the inventory
for (int i = 0; i < inventoryItems.Count; i++)
{
//For every item in the inventory it checks the itemID and the itemAmount
if (inventoryItems_.item.itemID == itemID && inventoryItems*.itemAmount >= itemAmount)
{
//So the inventory does contain the item and the right amount*
return true;
}
}
//The inventory either doesn’t have that item or not enough of that item
return false;
}
So how could I check if the inventory contains all the materials and amounts before adding the blank item._