private void CalculateByComponentAmount(IProductionComponent component, double componentAmount,
                                                CalculationResult calculationResult)
        {
            var factoryMultiplier = CalculateFactoryMultiplier(component.OutputPerHour, componentAmount);

            AggregateComponentAmounts(component, calculationResult, factoryMultiplier);
        }
        private void CalculateByComponentAmountUpScaled(IProductionComponent component, double componentAmount,
                                                        CalculationResult calculationResult)
        {
            calculationResult.CalculationComponentResults.Add(new CalculationComponentResult
            {
                Component    = component,
                NeededAmount = componentAmount
            });

            var factoryMultiplier = Math.Ceiling(CalculateFactoryMultiplier(component.OutputPerHour, componentAmount));

            AggregateComponentAmounts(component, calculationResult, factoryMultiplier);
        }
        private CalculationResult AggregateComponentAmounts(IProductionComponent component,
                                                            CalculationResult calculationResult, double factoryMultiplier)
        {
            foreach (var neededComponent in component.NeededComponents)
            {
                var neededAmount = neededComponent.Value * factoryMultiplier;

                var currentComponent =
                    calculationResult.CalculationComponentResults.FirstOrDefault(result
                                                                                 => result.Component.Id == neededComponent.Key.Id);
                if (currentComponent == null)
                {
                    currentComponent = new CalculationComponentResult
                    {
                        Component = neededComponent.Key
                    };
                    calculationResult.CalculationComponentResults.Add(currentComponent);
                }

                currentComponent.NeededAmount += neededAmount;

                var currentComponentFactoryMultiplier =
                    CalculateFactoryMultiplier(neededComponent.Key.OutputPerHour, neededAmount);
                AggregateComponentAmounts(neededComponent.Key, calculationResult, currentComponentFactoryMultiplier);
            }

            foreach (var neededResource in component.NeededResources)
            {
                var neededResourceAmount = neededResource.Value * factoryMultiplier;
                var presentResourceKey   =
                    calculationResult.NeededResources.Keys.FirstOrDefault(key => key.Id == neededResource.Key.Id);
                if (presentResourceKey != null)
                {
                    calculationResult.NeededResources[presentResourceKey] += neededResourceAmount;
                }
                else
                {
                    calculationResult.NeededResources[neededResource.Key] = neededResourceAmount;
                }
            }

            return(calculationResult);
        }
 private CalculationResult CalculateByFactoryCount(IProductionComponent component, int factoryCount,
                                                   CalculationResult calculationResult)
 => AggregateComponentAmounts(component, calculationResult, factoryCount);