Exemple #1
0
        public void OnLapCompleted(MsgLapCompleted msg, int totalLaps)
        {
            // Logging.Debug("New lap: " + msg.CarId + ", time: " + TimeSpan.FromMilliseconds(msg.LapTime).ToMillisecondsString());
            if (msg.CarId >= Leaderboard.Count)
            {
                return;
            }
            var item    = Leaderboard[msg.CarId];
            var lapTime = TimeSpan.FromMilliseconds(msg.LapTime);

            if ((item.BestLapTime == TimeSpan.Zero || lapTime < item.BestLapTime) && msg.Cuts == 0)
            {
                item.BestLapTime = lapTime;
            }
            _positionHelperList.Sort(_lapProgressComparer);
            item.CurrentRacePosition = _positionHelperList.IndexOf(item) + 1;
            item.CurrentLapStart     = DateTime.Now;
            item.LastLapTime         = lapTime;
            item.CurrentLapValid     = true;
            item.TotalLaps++;
            if (item.TotalLaps == totalLaps)
            {
                item.FinishedPosition = Leaderboard.Count(x => x.FinishedPosition.HasValue);
            }
        }