Пример #1
0
        private void RemoveUsedResources(Building b, WorldObject obj)
        {
            if (obj.ElementType == MapElementType.Meal)
            {
                int removedCount = 0;
                Meal meal = (Meal)b.GetCraftSlot();
                meal.NutritionalValue = 0;

                List<MapElementType> toBeRemoved = new List<MapElementType>();
                foreach (KeyValuePair<MapElementType, List<WorldObject>> keyValue in b.DepositedWorldObjects)
                {
                    foreach (WorldObject depobj in keyValue.Value)
                    {
                        if (depobj.GetType().IsSubclassOf(typeof(Food)) && depobj.ElementType != MapElementType.Meal)
                        {
                            if (removedCount == 2)
                                break;

                            Food food = (Food)depobj;
                            // Adds the double of the foods nutritional value to the meal
                            meal.NutritionalValue = meal.NutritionalValue + food.NutritionalValue * TimeRules.MealMultiplier;
                            // Adds the buffs of the food to the meal, and multiply effect by 2
                            foreach (StatBuff buff in food.StatBuffs)
                            {
                                meal.StatBuffs.Add(new StatBuff() { Type = buff.Type, Value = buff.Value  });
                            }

                            toBeRemoved.Add(depobj.ElementType);
                            removedCount++;
                        }
                    }
                }

                foreach (MapElementType type in toBeRemoved)
                {
                    b.RemoveDepositedWorldObject(type, 1);
                }

                //throw new Exception("Two food items should be available to make a meal");
            }
            else
            {
                foreach (KeyValuePair<MapElementType, int> resource in obj.NeededForCrafting)
                {
                    for (int i = 0; i < resource.Value; i++)
                    {
                        b.RemoveDepositedWorldObject(resource.Key, obj.Level);
                    }
                }
            }
        }