private void ProcessSynthesisEvent(EDEvent updateEvent)
        {
            // We need to check what the synthesis is - if it is repair or refuel outside pits, this could be disqualification
            if (updateEvent.AdditionalData.StartsWith("Repair"))
            {
                Hull = 1;
                AddRaceHistory(updateEvent.AdditionalData);
                if (!AllowPitStops() || _inPits)
                {
                    return;
                }

                // We aren't in pits and pit stops are required... This is elimination
                Eliminate("Synthesis repair used outside pits");
            }
            else if (updateEvent.AdditionalData.StartsWith("Fuel"))
            {
                AddRaceHistory(updateEvent.AdditionalData);
                if (!AllowPitStops() || _inPits)
                {
                    return;
                }

                // We aren't in pits and pit stops are required... This is elimination
                Eliminate("Synthesis refuel used outside pits");
            }
        }
Exemple #2
0
 public void UpdateStatus(EDEvent edEvent)
 {
     if (Statuses != null)
     {
         if (Statuses.ContainsKey(edEvent.Commander))
         {
             Statuses[edEvent.Commander].UpdateStatus(edEvent);
             if (StartTimeFromFirstWaypoint && !_firstWaypointPassed)
             {
                 if (Statuses[edEvent.Commander].WaypointIndex > 0)
                 {
                     _firstWaypointPassed = true;
                     Start = edEvent.TimeStamp;
                     foreach (string commander in Statuses.Keys)
                     {
                         Statuses[commander].StartTime    = Start;
                         Statuses[commander].LapStartTime = Start;
                     }
                 }
             }
             if (!_commanderEventHistory.ContainsKey(edEvent.Commander))
             {
                 _commanderEventHistory.Add(edEvent.Commander, new List <EDEvent>());
             }
             _commanderEventHistory[edEvent.Commander].Add(edEvent);
         }
     }
 }
 private void ProcessTouchdownEvent(EDEvent updateEvent)
 {
     _lastTouchDown = updateEvent.TimeStamp;
     if (DateTime.UtcNow.Subtract(_pitStopStartTime).TotalSeconds > 120)
     {
         _pitStopStartTime = _lastTouchDown;
     }
 }
Exemple #4
0
        private bool ProcessLocationUpdate(EDEvent edEvent)
        {
            EDLocation currentLocation = edEvent.Location();

            if (currentLocation == null)
            {
                return(false);
            }

            if (SessionStartLocation == null)
            {
                SessionStartLocation = currentLocation;
            }

            _telemetry["CurrentAltitude"] = EDLocation.DistanceToString(edEvent.Altitude);
            if ((int)edEvent.Altitude > MaximumAltitude)
            {
                MaximumAltitude = (int)edEvent.Altitude;
                _telemetry["MaximumAltitude"] = EDLocation.DistanceToString(MaximumAltitude);
            }
            else if (!_playerIsInSRV && (int)edEvent.Altitude < MinimumAltitude)
            {
                MinimumAltitude = (int)edEvent.Altitude;
                _telemetry["MinimumAltitude"] = EDLocation.DistanceToString(MinimumAltitude);
            }



            if (_lastLocation == null)
            {
                _lastLocation = currentLocation;
                return(false);
            }
            if (_lastLocation.Latitude.Equals(currentLocation.Latitude) && _lastLocation.Longitude.Equals(currentLocation.Longitude))
            {
                return(false);
            }

            _telemetry["CurrentLatitude"]  = currentLocation.Latitude.ToString();
            _telemetry["CurrentLongitude"] = currentLocation.Longitude.ToString();

            // Update distance/speed statistics
            if (CalculateDistances(currentLocation))
            {
                CalculateSpeed(currentLocation, edEvent.TimeStamp);
                if (SessionStartTime == DateTime.MinValue)
                {
                    // We set session start time on first detected movement
                    SessionStartTime = DateTime.UtcNow;
                    _telemetry["SessionStartTime"] = SessionStartTime.ToString("HH:mm:ss");
                    _telemetry["SessionDate"]      = SessionStartTime.ToShortDateString();
                }
                return(true);
            }
            return(false);
        }
Exemple #5
0
        private bool ProcessFlags(EDEvent edEvent)
        {
            if (edEvent.Flags < 1)
            {
                return(false);
            }

            bool statsChanged = false;

            if ((Pips[0] != edEvent.Pips[0]) || (Pips[1] != edEvent.Pips[1]) || (Pips[2] != edEvent.Pips[2]))
            {
                Pips = (byte[])edEvent.Pips.Clone();
                _telemetry["Pips"] = String.Join(",", Pips);
                statsChanged       = true;
            }

            if (edEvent.shieldsAreUp() != ShieldsUp)
            {
                ShieldsUp = edEvent.shieldsAreUp();
                if (ShieldsUp)
                {
                    _telemetry["Shield"] = "Up";
                }
                else
                {
                    _telemetry["Shield"] = "Down";
                }
                statsChanged = true;
            }

            if (edEvent.CargoScoopIsDeployed() == CargoScoopUp)
            {
                CargoScoopUp = !edEvent.CargoScoopIsDeployed();
                if (CargoScoopUp)
                {
                    _telemetry["CargoScoop"] = "Up";
                }
                else
                {
                    _telemetry["CargoScoop"] = "Down";
                }
                statsChanged = true;
            }

            if (((edEvent.Flags & (long)StatusFlags.In_MainShip) == (long)StatusFlags.In_MainShip) ||
                ((edEvent.Flags & (long)StatusFlags.In_Fighter) == (long)StatusFlags.In_Fighter))
            {
                _playerIsInSRV = false;
            }

            if (((edEvent.Flags & (long)StatusFlags.In_SRV) == (long)StatusFlags.In_SRV))
            {
                _playerIsInSRV = true;
            }
            return(statsChanged);
        }
 public EDRaceStatus(EDEvent baseEvent)
 {
     // This constructor should only ever be called by the server
     Flags     = baseEvent.Flags;
     Heading   = baseEvent.Heading;
     TimeStamp = baseEvent.TimeStamp;
     Commander = baseEvent.Commander;
     if (baseEvent.HasCoordinates())
     {
         Location = baseEvent.Location();
     }
 }
        private void ProcessShipTargetedEvent(EDEvent updateEvent)
        {
            string commanderName = Commander;

            if (commanderName.StartsWith("cmdr", StringComparison.OrdinalIgnoreCase))
            {
                commanderName = commanderName.Substring(5);
            }
            if (updateEvent.TargetedShipName.EndsWith($"{commanderName};", StringComparison.OrdinalIgnoreCase) && (_pitStopStartTime == DateTime.MinValue))
            {
                _pitStopStartTime = updateEvent.TimeStamp;
            }
        }
 private void ProcessDockSRVEvent(EDEvent updateEvent)
 {
     if (!Finished && !Eliminated && AllowPitStops())
     {
         // We only increase pitstop count on DockSRV
         _lastDockSRV = updateEvent.TimeStamp;
         PitStopCount++;
         Hull = 1;
         notableEvents?.AddStatusEvent("PitstopNotification", Commander);
         _inPits = true;
         if (_pitStopStartTime == DateTime.MinValue)
         {
             _pitStopStartTime = _lastDockSRV;
         }
     }
 }
        private bool ProcessFlags(EDEvent edEvent)
        {
            if (edEvent.Flags < 1)
            {
                return(false);
            }

            if (((edEvent.Flags & (long)StatusFlags.In_MainShip) == (long)StatusFlags.In_MainShip) ||
                ((edEvent.Flags & (long)StatusFlags.In_Fighter) == (long)StatusFlags.In_Fighter))
            {
                _playerIsInSRV = false;
            }

            if (((edEvent.Flags & (long)StatusFlags.In_SRV) == (long)StatusFlags.In_SRV))
            {
                _playerIsInSRV = true;
            }
            return(false);
        }
Exemple #10
0
        public EDEvent Replay()
        {
            EDEvent edEvent = new EDEvent();

            edEvent.Altitude         = Altitude;
            edEvent.BodyName         = BodyName;
            edEvent.Commander        = Commander;
            edEvent.EventName        = EventName;
            edEvent.Flags            = Flags;
            edEvent.Heading          = Heading;
            edEvent.Health           = Health;
            edEvent.Latitude         = Latitude;
            edEvent.Longitude        = Longitude;
            edEvent.PlanetRadius     = PlanetRadius;
            edEvent.PlayerControlled = PlayerControlled;
            edEvent.TargetedShipName = TargetedShipName;
            edEvent.Pips             = (byte[])Pips.Clone();
            edEvent.TimeStamp        = DateTime.UtcNow;
            return(edEvent);
        }
        private bool ProcessLocationUpdate(EDEvent edEvent)
        {
            EDLocation currentLocation = edEvent.Location();

            if (currentLocation == null)
            {
                return(false);
            }

            if (SessionStartLocation == null)
            {
                SessionStartLocation = currentLocation;
            }

            _telemetry["CurrentAltitude"] = EDLocation.DistanceToString(edEvent.Altitude);
            if ((int)edEvent.Altitude > MaximumAltitude)
            {
                MaximumAltitude = (int)edEvent.Altitude;
                _telemetry["MaximumAltitude"] = EDLocation.DistanceToString(MaximumAltitude);
            }

            if (_lastLocation == null)
            {
                _lastLocation    = currentLocation;
                SessionStartTime = edEvent.TimeStamp;
                return(false);
            }
            if (_lastLocation.Latitude.Equals(currentLocation.Latitude) && _lastLocation.Longitude.Equals(currentLocation.Longitude))
            {
                return(false);
            }

            // Update distance/speed statistics
            if (CalculateDistances(currentLocation))
            {
                CalculateSpeed(currentLocation, edEvent.TimeStamp);
                return(true);
            }
            return(false);
        }
Exemple #12
0
 private void CommanderWatcher_UpdateReceived(object sender, EDEvent edEvent)
 {
     Task.Run(new Action(() => { UpdateStatus(edEvent); }));
 }
        public void ProcessEvent(EDEvent edEvent)
        {
            if (SessionStartTime == DateTime.MinValue)
            {
                SessionStartTime = new DateTime(edEvent.TimeStamp.Year, edEvent.TimeStamp.Month, edEvent.TimeStamp.Day, edEvent.TimeStamp.Hour, edEvent.TimeStamp.Minute, edEvent.TimeStamp.Second);
                _telemetry["SessionStartTime"] = SessionStartTime.ToString("HH:mm:ss");
                _telemetry["SessionDate"]      = SessionStartTime.ToShortDateString();
            }

            bool statsUpdated = ProcessFlags(edEvent);

            switch (edEvent.EventName)
            {
            case "DockSRV":
                TotalShipRepairs++;
                HullHealth = 1;
                _telemetry["HullStrength"]        = "100%";
                _telemetry["TotalSRVShipRepairs"] = TotalShipRepairs.ToString();
                statsUpdated   = true;
                _playerIsInSRV = false;
                break;

            case "LaunchSRV":
                _playerIsInSRV = true;
                break;

            case "Shutdown":
                SaveSession();
                break;

            case "SRVDestroyed":
                _playerIsInSRV = false;
                TotalSRVsDestroyed++;
                _telemetry["TotalSRVsDestroyed"] = TotalSRVsDestroyed.ToString();
                statsUpdated = true;
                break;

            case "HullDamage":
                HullHealth = edEvent.Health;
                _telemetry["HullStrength"] = $"{(HullHealth * 100).ToString("F1")}%";
                statsUpdated = true;
                break;

            case "Synthesis":
                TotalSynthRepairs++;
                _telemetry["TotalSRVSynthRepairs"] = TotalSynthRepairs.ToString();
                statsUpdated = true;
                break;

            case "Status":
                if (_playerIsInSRV && ProcessLocationUpdate(edEvent))
                {
                    statsUpdated = true;
                }
                break;
            }

            _lastEventTime = edEvent.TimeStamp;
            if (statsUpdated)
            {
                SessionHistory.Add(edEvent);
                _srvTelemetryDisplay?.UpdateTargetData(Telemetry());
            }
        }
        public void UpdateStatus(EDEvent updateEvent)
        {
            // Update our status based on the passed event

            if (updateEvent.TimeStamp > DateTime.MinValue)
            {
                TimeStamp = updateEvent.TimeStamp;
            }

            if (Finished)  // We keep tracking when eliminated in case of mistake (racers can be restored)
            {
                return;
            }

            if ((updateEvent.Flags > 0) && (Flags != updateEvent.Flags))
            {
                _lastFlags = Flags;
                Flags      = updateEvent.Flags;
            }
            Flags2 = updateEvent.Flags2;

            Pips    = (byte[])updateEvent.Pips.Clone();
            Heading = updateEvent.Heading;

            if (updateEvent.Health >= 0)
            {
                Hull = updateEvent.Health;
                AddRaceHistory($"Hull percentage: {Hull*100:F1}");
            }

            if (updateEvent.HasCoordinates())
            {
                _previousLocation = Location;
                Location          = updateEvent.Location();
                ProcessLocationChange();
                CalculateSpeed();
            }

            if (!Started)
            {
                return;
            }

            ProcessFlags();

            switch (updateEvent.EventName)
            {
            case "SRVDestroyed":
                ProcessSRVDestroyedEvent();
                break;

            case "FighterDestroyed":
                ProcessFighterDestroyedEvent();
                break;

            case "ShipTargeted":
                ProcessShipTargetedEvent(updateEvent);
                break;

            case "Touchdown":
                ProcessTouchdownEvent(updateEvent);
                break;

            case "Liftoff":
                _lastTouchDown = DateTime.MinValue;
                break;

            case "DockSRV":
                ProcessDockSRVEvent(updateEvent);
                break;

            case "LaunchSRV":
                ProcessLaunchSRVEvent();
                break;

            case "Synthesis":
                ProcessSynthesisEvent(updateEvent);
                break;
            }

            GenerateStatus();
            if (_status.Equals(_lastStatus))
            {
                return;
            }

            AddRaceHistory(_status);
            _lastStatus = _status;
            StatusChanged?.Invoke(null, Commander, _status);
        }
Exemple #15
0
        public void ProcessEvent(EDEvent edEvent, bool noHistory = false)
        {
            bool statsUpdated = ProcessFlags(edEvent);

            switch (edEvent.EventName)
            {
            case "DockSRV":
                TotalShipRepairs++;
                HullHealth = 1;
                _telemetry["HullStrength"]        = "100%";
                _telemetry["TotalSRVShipRepairs"] = TotalShipRepairs.ToString();
                statsUpdated   = true;
                _playerIsInSRV = false;
                ResetSpeedCalc();
                break;

            case "LaunchSRV":
                _playerIsInSRV = true;
                ResetSpeedCalc();
                break;

            case "Shutdown":
                SaveSession();
                break;

            case "SRVDestroyed":
                _playerIsInSRV = false;
                TotalSRVsDestroyed++;
                _telemetry["TotalSRVsDestroyed"] = TotalSRVsDestroyed.ToString();
                ResetSpeedCalc();
                statsUpdated = true;
                break;

            case "HullDamage":
                HullHealth = edEvent.Health;
                _telemetry["HullStrength"] = $"{(HullHealth * 100).ToString("F1")}%";
                statsUpdated = true;
                break;

            case "Synthesis":
                if (edEvent.AdditionalData.StartsWith("Repair"))
                {
                    TotalSynthRepairs++;
                    _telemetry["TotalSRVSynthRepairs"] = TotalSynthRepairs.ToString();
                    HullHealth = 1;
                    _telemetry["HullStrength"] = "100%";
                    statsUpdated = true;
                }
                break;

            case "Status":
                // We only process location updates if the event is for the correct vehicle (ship or SRV)
                if ((_playerIsInSRV == TrackSRV) && ProcessLocationUpdate(edEvent))
                {
                    statsUpdated = true;
                }
                break;
            }

            _lastEventTime = edEvent.TimeStamp;
            if (statsUpdated)
            {
                if (!noHistory)
                {
                    SessionHistory.Add(edEvent);
                }
                _srvTelemetryDisplay?.UpdateTargetData(Telemetry());
            }
        }