Пример #1
0
    public bool RegionalCompleteConditionsMet(RegionStatistics s)
    {
        bool conditionsMet = true;

        if (!(s.income >= questCompleteConditions.income || questCompleteConditions.income == 0))
        {
            conditionsMet = false;
        }
        if (!(s.prosperity >= questCompleteConditions.prosperity || questCompleteConditions.prosperity == 0))
        {
            conditionsMet = false;
        }
        if (!(s.ecoAwareness >= questCompleteConditions.ecoAwareness || questCompleteConditions.ecoAwareness == 0))
        {
            conditionsMet = false;
        }
        if (!(s.happiness >= questCompleteConditions.happiness || questCompleteConditions.happiness == 0))
        {
            conditionsMet = false;
        }
        if (!(s.avgPollution <= questCompleteConditions.avgPollution || questCompleteConditions.avgPollution == 0))
        {
            conditionsMet = false;
        }

        return(conditionsMet);
    }
Пример #2
0
    //checks if all statistics of the region are within the required range for this action to be available
    public void GetRegionalAvailability(int currentYear, int currentMonth, RegionStatistics rs)
    {
        int monthTotal         = currentYear * 12 + currentMonth;
        int startTimeCondition = startAvailableYear * 12 + startAvailableMonth;
        int endTimeCondition   = endAvailableYear * 12 + endAvailableMonth;

        if ((monthTotal >= startTimeCondition && monthTotal < endTimeCondition) &&
            (availableConditionsMinimum.income > rs.income || availableConditionsMinimum.income == 0) &&
            (availableConditionsMinimum.happiness > rs.happiness || availableConditionsMinimum.happiness == 0) &&
            (availableConditionsMinimum.ecoAwareness > rs.ecoAwareness || availableConditionsMinimum.ecoAwareness == 0) &&
            (availableConditionsMinimum.prosperity > rs.prosperity || availableConditionsMinimum.prosperity == 0) &&
            (availableConditionsMinimum.pollution.airPollution > rs.avgAirPollution || availableConditionsMinimum.pollution.airPollution == 0) &&
            (availableConditionsMinimum.pollution.naturePollution > rs.avgNaturePollution || availableConditionsMinimum.pollution.naturePollution == 0) &&
            (availableConditionsMinimum.pollution.waterPollution > rs.avgWaterPollution || availableConditionsMinimum.pollution.waterPollution == 0) &&
            (availableConditionsMaximum.income < rs.income || availableConditionsMaximum.income == 0) &&
            (availableConditionsMaximum.happiness < rs.happiness || availableConditionsMaximum.happiness == 0) &&
            (availableConditionsMaximum.ecoAwareness < rs.ecoAwareness || availableConditionsMaximum.ecoAwareness == 0) &&
            (availableConditionsMaximum.prosperity < rs.prosperity || availableConditionsMaximum.prosperity == 0) &&
            (availableConditionsMaximum.pollution.airPollution < rs.avgAirPollution || availableConditionsMaximum.pollution.airPollution == 0) &&
            (availableConditionsMaximum.pollution.naturePollution < rs.avgNaturePollution || availableConditionsMaximum.pollution.naturePollution == 0) &&
            (availableConditionsMaximum.pollution.waterPollution < rs.avgWaterPollution || availableConditionsMaximum.pollution.waterPollution == 0))
        {
            isAvailable = true;
        }
        else
        {
            isAvailable = false;
        }
    }
Пример #3
0
        public async Task GetRegionStatisticsPeriodStatisticsNotFound()
        {
            // Arrange
            _repositoryWrapper.Setup(r => r.Region.GetFirstOrDefaultAsync(It.IsAny <Expression <Func <DatabaseEntities.Region, bool> > >(),
                                                                          It.IsAny <Func <IQueryable <DatabaseEntities.Region>, IIncludableQueryable <DatabaseEntities.Region, object> > >()))
            .ReturnsAsync(new DatabaseEntities.Region());
            _repositoryWrapper.Setup(r => r.MembersStatistics.GetAllAsync(It.IsAny <Expression <Func <DatabaseEntities.MembersStatistic, bool> > >(),
                                                                          It.IsAny <Func <IQueryable <DatabaseEntities.MembersStatistic>, IIncludableQueryable <DatabaseEntities.MembersStatistic, object> > >()))
            .ReturnsAsync(Enumerable.Empty <DatabaseEntities.MembersStatistic>());
            _mapper.Setup(m => m.Map <DatabaseEntities.Region, DTOs.Region>(It.IsAny <DatabaseEntities.Region>()))
            .Returns(_regions.First());
            int minYear        = 2019;
            int maxYear        = 2020;
            var expectedResult = new RegionStatistics
            {
                Region         = _regions.First(),
                YearStatistics = new List <YearStatistics>
                {
                    new YearStatistics {
                        Year = minYear, StatisticsItems = _expectedStatisticsItems
                    },
                    new YearStatistics {
                        Year = maxYear, StatisticsItems = _expectedStatisticsItems
                    }
                }
            };

            // Act
            var result = await _statisticsService.GetRegionStatisticsAsync(It.IsAny <int>(), minYear, maxYear, _indicators);

            // Assert
            Assert.Equal(JsonConvert.SerializeObject(expectedResult), JsonConvert.SerializeObject(result));
        }
Пример #4
0
 public void GetAvailableActions(Game game, RegionStatistics rs)
 {
     if (conditionsAreRegional)
     {
         GetRegionalAvailability(game.currentYear, game.currentMonth, rs);
     }
     else
     {
         GetGlobalAvailability(game.currentYear, game.currentMonth, game.gameStatistics);
     }
 }