public bool CanApplyFreeBuildingToCity(IEnumerable <IBuildingTemplate> validTemplates, ICity city)
        {
            var hasValidTemplates = validTemplates.Any(
                template => BuildingProductionValidityLogic.IsTemplateValidForCity(template, city)
                );

            var alreadyReceivedBuilding = BestowedFreeBuildingsOfCity[city].Intersect(validTemplates).Any();

            return(hasValidTemplates && !alreadyReceivedBuilding);
        }
        private void OnCityGainedBuilding(System.Tuple <ICity, IBuilding> data)
        {
            foreach (var otherCity in CityFactory.AllCities.Where(city => city != data.Item1))
            {
                var buildingInProgress = otherCity.ActiveProject == null ? null : otherCity.ActiveProject.BuildingToConstruct;

                if (buildingInProgress != null && !BuildingValidityLogic.IsTemplateValidForCity(buildingInProgress, otherCity))
                {
                    otherCity.ActiveProject = null;
                }
            }
        }
Ejemplo n.º 3
0
        private void OnCityGainedBuilding(Tuple <ICity, IBuilding> data)
        {
            var city             = data.Item1;
            var buildingTemplate = data.Item2.Template;

            foreach (var freeTemplate in buildingTemplate.FreeBuildings)
            {
                if (BuildingValidityLogic.IsTemplateValidForCity(freeTemplate, city))
                {
                    BuildingFactory.BuildBuilding(freeTemplate, city);
                }
            }
        }
        private void AddBuildingProjects(
            ICivilization cityOwner, IEnumerable <IBuildingTemplate> validTemplates,
            Action <IBuildingTemplate> recordSelectionAction
            )
        {
            foreach (var buildingTemplate in validTemplates)
            {
                var newRecord = BuildRecord();

                newRecord.BuildingTemplate = buildingTemplate;

                newRecord.SelectionButton.interactable = BuildingValidityLogic.IsTemplateValidForCity(buildingTemplate, ObjectToDisplay);
                newRecord.SelectionButton.onClick.AddListener(() => recordSelectionAction(buildingTemplate));

                newRecord.Refresh();

                InstantiatedProjectRecords.Add(newRecord);
            }
        }