private void AddYoungCyclists() { var teams = _teamService.GetTeams(); var cyclists = _cyclistService.GetCyclists().Where(c => c.TeamId >= 0).ToList(); foreach (var team in teams) { if (team.Id == Configuration.UserTeamId) { continue; } while (cyclists.Where(c => c.TeamId == team.Id).Count() < Configuration.NumberOfCyclistsInTeam) { var newCyclist = _cyclistService.CreateYoungCyclist(team.Id); cyclists.Add(newCyclist); } } foreach (var message in _cyclistService.GetAllMessages()) { AddMessage(message); } }
public void NextRace() { _cyclists = _cyclistService.GetCyclists().Where(c => c.SelectedForRace).ToList(); if (_cyclists.Where(c => c.TeamId == PlayerTeamId()).Count() != Configuration.NumberOfCyclistsPerTeamForRace) { AddMessage("The number of cyclists in your team has to be " + Configuration.NumberOfCyclistsPerTeamForRace); return; } if (_justStartedUp) { _tracks = _trackService.GetTracks(); _teams = _teamService.GetTeams(); _divisions = _divisionService.GetDivisions(); _aiManagerService.AtEndOfSeason(PlayerTeamId()); ResetRanking(); _justStartedUp = false; } if (!_tracks.Any(t => t.Id == _saveGame.NextRaceId)) { throw new Exception($"{_saveGame.NextRaceId}: This race id does not exist"); } if (!_divisions.Any(d => d.Id == _saveGame.NextDivisionId)) { throw new Exception($"{_saveGame.NextDivisionId}: This division id does not exist"); } var divisionForThisRace = _divisions.Where(d => d.Id == _saveGame.NextDivisionId).FirstOrDefault(); var teamsForThisRace = _teams.Where(tm => divisionForThisRace.TeamsId.Contains(tm.Id)).ToList(); var cyclistsForThisRace = _cyclists.Where(c => teamsForThisRace.Any(tm => tm.Id == c.TeamId)).ToList(); _raceService.StartRace(_tracks.Where(t => t.Id == _saveGame.NextRaceId).FirstOrDefault().TrackTiles, cyclistsForThisRace, teamsForThisRace, teamsForThisRace.Any(t => t.Id == _saveGame.PlayerTeamId)); UpdateAfterRace(); }