Пример #1
0
        private bool DoesBuildingHaveNecessaryMaterialsForCrafting(Building b, WorldObject obj)
        {
            bool does = true;
            bool haveRequested = TaskManager.IsAlreadyGettingNecessaryBuildingMaterials(b, obj);

            int counter = 0;

            if (obj.ElementType == MapElementType.Meal)
            {
                // If the building has some kind of food depsited, we have enough materials to make a meal
                foreach (KeyValuePair<MapElementType, List<WorldObject>> keyValue in b.DepositedWorldObjects)
                {
                    foreach (WorldObject depobj in keyValue.Value)
                    {
                        if (depobj.GetType().IsSubclassOf(typeof(Food)))
                        {
                            return true;
                        }
                    }
                }

                return false;
            }
            else
            {
                foreach (KeyValuePair<MapElementType, int> materials in obj.NeededForCrafting)
                {
                    // If the building does not contains the material needed, request a delivery
                    if (b.DepositedWorldObjects.ContainsKey(materials.Key) == false)
                    {
                        // Multiple instances of the material may be needed
                        for (int i = 0; i < materials.Value; i++)
                        {
                            if (haveRequested == false)
                            {
                                // Request a delivery of the material
                                TaskManager.AddTask(new GetBuildingMaterialTask(materials.Key, obj.Level, b));
                                counter++;
                            }
                            does = false;
                        }
                    }
                    // Else, if the building does contain the material, does it contain enough?
                    else
                    {
                        // Request the missing material instaces, if any
                        for (int i = 0; i < materials.Value - b.GetNumberOfDepositedMaterial(materials.Key, obj.Level); i++)
                        {
                            if (haveRequested == false)
                            {
                                TaskManager.AddTask(new GetBuildingMaterialTask(materials.Key, obj.Level, b));
                                counter++;
                            }
                            does = false;
                        }
                    }
                }
            }

            if (counter == 1)
            {

            }

            return does;
        }