Ejemplo n.º 1
0
    public bool Craft(IBlueprint bp)
    {
        Dictionary <string, int> mats  = bp.getMaterials();
        List <ItemInfo>          items = inventory.getItems();

        foreach (string mat in mats.Keys)
        {
            ItemInfo inventoryItem = items.Find(x => x.itemName == mat);

            if (inventoryItem == null)
            {
                return(false);
            }

            int neededAmount;
            mats.TryGetValue(mat, out neededAmount);

            if (!enoughMats(inventoryItem.getAmount(), neededAmount))
            {
                return(false);
            }

            inventory.decreaseItemCountInInventory(inventoryItem, neededAmount);
        }
        addCraftedToInventory(bp);
        return(true);
    }
Ejemplo n.º 2
0
    private void drawCraftingMenu()
    {
        float menuTextH = 50f;

        GUI.Box(new Rect(0, 0, crftW, menuTextH), "Crafting");

        float buttonH = (crftH - menuTextH) / 2;

        for (int i = 0; i < blueprints.Count; i++)
        {
            IBlueprint bp = blueprints [i];
            Dictionary <string, int> mats = bp.getMaterials();
            string name = bp.getName();

            string textForButton = formCraftableMaterialString(name, mats);

            if (GUI.Button(new Rect(0, (i * buttonH) + menuTextH, crftW, buttonH), textForButton))
            {
                SendMessage("Craft", bp);
            }
        }
    }