Exemplo n.º 1
0
        //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);
        }
Exemplo n.º 2
0
        private Item CraftItem(Craftable craftable)
        {
            for (int i = 0; i < craftable.NumberOfIngredients; i++)
            {
                inventory.RemoveFromInventory(craftable.GetIngredientAt(i), craftable.GetNumberNeededAt(i));
            }

            return(craftable);
        }
Exemplo n.º 3
0
        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);
        }
        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);
                }
            }
        }