//Will not find the number craftable for more complex items when the ingredients are not already in inventory //ex. A House will show 0 craftable unless Door, Roof, and Walls(4) are ALREADY in inventory, even if the base materials for the components ARE in inventory. public int NumberCraftable(Craftable craftable) { //Find the max number craftable given a desired item int lowest = int.MaxValue; for (int i = 0; i < craftable.NumberOfIngredients; ++i) { Item ingredient = craftable.GetIngredientAt(i); int numNeeded = craftable.GetNumberNeededAt(i); if (inventory.HasNumberOfItem(ingredient, numNeeded)) { int numCraftable = inventory.NumberHeldOf(ingredient) / numNeeded; if (numCraftable < lowest) { lowest = numCraftable; } } else //There isnt enough of the ingredient, therefore 0 can be made { return(0); } } return(lowest); }
public void LearnNewCraftable(Craftable c) { craftables.Add(c); AddToCraftables(c); onCraftablesChange?.Invoke(); }
private Item CraftItem(Craftable craftable) { for (int i = 0; i < craftable.NumberOfIngredients; i++) { inventory.RemoveFromInventory(craftable.GetIngredientAt(i), craftable.GetNumberNeededAt(i)); } return(craftable); }
private void AddToCraftables(Craftable c, int count = 0) { if (!craftingInventory.ContainsKey(c)) { craftingInventory.Add(c, count); onLearnNewCraftable?.Invoke(c); } else { craftingInventory[c] += count; } }
private bool CanCraftItem(Craftable craftable) { Item ingredient; int numNeeded; for (int i = 0; i < craftable.NumberOfIngredients; ++i) { ingredient = craftable.GetIngredientAt(i); numNeeded = craftable.GetNumberNeededAt(i); if (!inventory.HasNumberOfItem(ingredient, numNeeded)) { return(false); } } return(true); }
public bool TryCraftItem(Craftable item) { if (!CanCraftItem(item)) { Debug.LogWarning("Not enough materials to craft " + item.ItemName); return(false); } Item craftedItem = CraftItem(item); if (craftedItem != null) { inventory.AddToInventory(craftedItem); return(true); } return(false); }
private void ShowCraftable(Craftable c) { GUILayout.Space(24f); GUIContent content = new GUIContent(c.ItemName, c.Icon.texture, c.Description); GUILayout.Label(content, craftableInfoStyle); GUILayout.Label("The ingredients needed to make " + c.ItemName + ": ", craftableInfoStyle); GUILayout.Space(24f); GUILayout.BeginHorizontal(); for (int i = 0; i < c.NumberOfIngredients; ++i) { Item ingreditent = c.GetIngredientAt(i); GUILayout.BeginVertical(); GUILayout.Label(ingreditent.Icon.texture); GUILayout.Label(ingreditent.ItemName + ": " + c.GetNumberNeededAt(i).ToString(), ingredientStyle); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); newIngredient = EditorGUILayout.ObjectField(newIngredient, typeof(Item), true); if (newIngredient != null && newIngredient as Item) { if (GUILayout.Button("Add Ingredient")) { c.AddIngredient(newIngredient as Item, 1); } } }
private void SetInspectedCraftable(Craftable c) { inspectedCraftable = c; inspectingAllCraftables = false; }