Exemple #1
0
        private bool CanExecuteNextStep(IEnumerable <Step> pendingSteps, Step next)
        {
            if (next is CancelConstructBuildingStep && ExecutingSteps.Any())
            {
                return(false);
            }
            var currentResourcePrereqs = pendingSteps.SelectMany(s => s.Prerequisites).OfType <ResourcePrerequisite>().ToList();

            if (!currentResourcePrereqs.Any())
            {
                return(next.AllPrerequisitesMet());
            }
            var nextResourcePrereqs = next.Prerequisites.OfType <ResourcePrerequisite>().FirstOrDefault();

            if (nextResourcePrereqs == null)
            {
                return(next.AllPrerequisitesMet());
            }

            return(HasEnoughResources(currentResourcePrereqs.Sum(r => r.Minerals) + nextResourcePrereqs.Minerals,
                                      currentResourcePrereqs.Sum(r => r.Gas) + nextResourcePrereqs.Gas) &&
                   next.AllPrerequisitesMet());
        }