private bool HasNeededResourcesForStage(Building.Stage stage)
        {
            Entity entity  = ConstructionSite.Entity;
            var    storage = entity.Components.Get <Storage>();

            foreach (string resource in stage.NeededResources.Keys)
            // Check if all resources are at or higher than the needed level.
            {
                if (!storage.Items.ContainsKey(resource) || storage.Items[resource] < stage.NeededResources[resource])
                {
                    return(false);
                }
            }

            return(true);
        }
        protected void SetNeededResources()
        {
            var storage                     = ConstructionSite.Entity.Get <Storage>();
            var neededResources             = new Dictionary <string, int>();
            int nextStageIndex              = ConstructionSite.CurrentStage - 1;
            var hasResourcesForCurrentStage = true;
            var hasResourcesForAllStages    = false;

            while (hasResourcesForCurrentStage && !hasResourcesForAllStages)
            {
                if (nextStageIndex < Building.Stages.Count)
                {
                    Building.Stage stage = Building.Stages[nextStageIndex];
                    foreach (KeyValuePair <string, int> resource in stage.NeededResources)
                    {
                        if (!neededResources.ContainsKey(resource.Key))
                        {
                            neededResources[resource.Key] = 0;
                        }

                        if (!storage.Items.ContainsKey(resource.Key) || storage.Items[resource.Key] <
                            resource.Value + neededResources[resource.Key])
                        {
                            hasResourcesForCurrentStage = false;
                        }

                        neededResources[resource.Key] += resource.Value;
                    }

                    nextStageIndex++;
                }
                else
                {
                    hasResourcesForAllStages = true;
                }
            }

            storage.RequestedItems.Clear();
            foreach (KeyValuePair <string, int> pair in neededResources)
            {
                storage.RequestedItems[pair.Key] = pair.Value;
            }
        }
 /// <summary>
 ///     Add a step to the progress of the construction site. Checks if the site is allowed to progress first.
 /// </summary>
 /// <param name="message"></param>
 public void HandleAdvanceProgressConstructing(AdvanceProgress message)
 {
     Building.Stage stage = Building.Stages[ConstructionSite.CurrentStage - 1];
     ConstructionSite.CurrentStageProgress += 1.0f / stage.Steps;
 }