예제 #1
0
        public void StartRace(bool asServer, NotableEvents notableEvents = null)
        {
            if (_raceStarted)
            {
                return;
            }

            Start    = DateTime.UtcNow;
            Statuses = new Dictionary <string, EDRaceStatus>();
            if (notableEvents != null)
            {
                _notableEvents = notableEvents;
            }
            else if (asServer)
            {
                _notableEvents = new NotableEvents("", false)
                {
                    CustomStatusMessages = CustomStatusMessages
                };
                _commanderEventHistory = new Dictionary <string, List <EDEvent> >();
            }

            _commanderEventHistory = new Dictionary <string, List <EDEvent> >();
            foreach (string contestant in Contestants)
            {
                EDRaceStatus raceStatus = new EDRaceStatus(contestant, this);
                raceStatus.StartTime    = Start;
                raceStatus.LapStartTime = Start;
                raceStatus.Lap          = 0;
                if (LapStartWaypoint == 0)
                {
                    raceStatus.Lap = 1;
                    LapEndWaypoint = Route.Waypoints.Count - 1;
                }
                if (asServer)
                {
                    raceStatus.notableEvents = _notableEvents;
                }
                Statuses.Add(contestant, raceStatus);
                _commanderEventHistory.Add(contestant, new List <EDEvent>());
            }
            InitLapCalculations();
            if (!asServer)
            {
                CommanderWatcher.UpdateReceived += CommanderWatcher_UpdateReceived;
            }

            _raceStarted = true;
        }
예제 #2
0
 private void ValidateRaceLeader()
 {
     if (_race != null && _race.Leader.Eliminated)
     {
         // We were the race leader, so we need to work out the new leader
         EDRaceStatus leader = null;
         foreach (EDRaceStatus status in _race.Statuses.Values)
         {
             if (!status.Eliminated)
             {
                 if (leader == null || status.TotalDistanceLeft < leader.TotalDistanceLeft)
                 {
                     leader = status;
                 }
             }
             if (status.Finished)
             {
                 break; // If someone has finished they'll be at the last waypoint, so no need to check further
             }
         }
         _race.Leader = leader;
     }
 }