Пример #1
0
    public void Craft(Item item, int quantity)
    {
        ParserUtil parserUtil = SingletonFactory.GetInstance <ParserUtil>();
        ItemUtil   itemUtil   = SingletonFactory.GetInstance <ItemUtil>();
        Dictionary <Resource, int> requiredResources = itemUtil.GetRequiredResources(item);

        int numCrafted = 0;

        for (int i = 0; i < quantity; i++)
        {
            if (HasRequiredResources(requiredResources))
            {
                foreach (KeyValuePair <Resource, int> requiredResource in requiredResources)
                {
                    resourceInventory[requiredResource.Key] -= requiredResource.Value;
                }

                AddItem(item);
                numCrafted++;
            }
            else
            {
                parserUtil.PrintResponse("Not enough resources to craft '" + item.ToString() + "'");
                break;
            }
        }

        if (numCrafted > 0)
        {
            parserUtil.PrintResponse("Crafted " + numCrafted + " '" + item.ToString() + (numCrafted > 1 ? "s" : "") + "'");
        }
    }