Beispiel #1
0
        /// <summary>
        /// Get most isoleted country
        /// </summary>
        /// <returns></returns>
        public async Task <(string, int)> GetCountryByIsolation()
        {
            List <Mission> missions = await _missionRepository.GetMissions();

            Dictionary <int, List <string> > agentCountries = BuildAgentCountryDic(missions);

            //Get all agents with one mission (hence one country)
            Dictionary <string, int> groupedAgents = agentCountries.Where(a => a.Value.Count() == 1)
                                                     .GroupBy(a => a.Value.First()) //Group the agent by country
                                                     .ToDictionary(g => g.Key, g => g.ToList().Count());

            KeyValuePair <string, int> result = groupedAgents.FirstOrDefault(x => x.Value == groupedAgents.Values.Max());

            return(result.Key, result.Value);
        }
Beispiel #2
0
        private static async Task <List <MissionIdWithSetId> > CheckActiveMissionDependencies(
            MissionRequest missionRequest,
            bool success,
            IMissionRepository missionRepository)
        {
            var autoRemovedActiveMissions = new List <MissionIdWithSetId>();

            if (success)
            {
                return(autoRemovedActiveMissions);
            }

            var user = missionRequest.User;
            var declinedMissionId = missionRequest.Mission.Id;
            var activeMissionsIds = user.ActiveMissionIds.Select(m => m.MissionId).ToIList();
            var activeMissions    =
                (await
                 missionRepository.GetMissions(
                     new QueryOptions <Mission>
            {
                Filter =
                    ExpressionHelper.Expr((Mission x) => x.Id).In(activeMissionsIds),
                Select = mission => new { mission.Id, mission.DependsOn }
            }));

            AutoDeclineActiveMissions(
                declinedMissionId,
                activeMissions,
                user,
                autoRemovedActiveMissions);

            return(autoRemovedActiveMissions);
        }
Beispiel #3
0
        private static async Task LoadMissionsFromNewSet(
            IMissionRepository missionRepository,
            string newSetId,
            User user)
        {
            var newMissions =
                (await
                 missionRepository.GetMissions(
                     new QueryOptions <Mission>
            {
                Select = mission => new { mission.Id, mission.DependsOn },
                Filter = mission => mission.MissionSetId == newSetId
            }));

            AutoDeclineNewMissions(newSetId, newMissions, user);
        }
Beispiel #4
0
 private async Task SetStartMissions(User user)
 {
     user.MissionSetIds = new List <MissionSetIdWithOrder>
     {
         new MissionSetIdWithOrder
         {
             MissionSetId = GameConstants.MissionSet.FirstSetId,
             Order        = 0
         },
         new MissionSetIdWithOrder
         {
             MissionSetId = GameConstants.MissionSet.SecondSetId,
             Order        = 1
         },
         new MissionSetIdWithOrder
         {
             MissionSetId = GameConstants.MissionSet.ThirdSetId,
             Order        = 2
         }
     };
     user.ActiveMissionIds =
         (await
          _missionRepository.GetMissions(
              new QueryOptions <Mission>
     {
         Filter =
             mission =>
             mission.MissionSetId == GameConstants.MissionSet.FirstSetId ||
             mission.MissionSetId == GameConstants.MissionSet.SecondSetId ||
             mission.MissionSetId == GameConstants.MissionSet.ThirdSetId
     }))
         .Select(m => new MissionIdWithSetId {
         MissionId = m.Id, MissionSetId = m.MissionSetId
     }).ToList();
     user.ActiveMissionSetIds = new List <string>
     {
         GameConstants.MissionSet.FirstSetId, GameConstants.MissionSet.SecondSetId,
         GameConstants.MissionSet.ThirdSetId
     };
 }
Beispiel #5
0
 /// <summary>
 ///     Gets the missions.
 /// </summary>
 /// <param name="options">The options.</param>
 /// <returns>Task{IEnumerable{Mission}}.</returns>
 public Task <List <Mission> > GetMissions(QueryOptions <Mission> options = null)
 {
     return(_missionRepository.GetMissions(options));
 }