public MatchResultViewModel() { PlayerResults = new PlayerResult[22]; for (int i = 0; i < 22; i++) { PlayerResults[i] = new PlayerResult(); } FCP = new FinalClassificationPacketPlus(); // replaced with new packet class PP = new ParticipantPacket(); }
public void LoadSummary(Packet[] packets, byte driver_index) { if (packets.Length == 0) { throw new Exception("The length of the supplied packet array was 0!"); } SessionId = packets[0].UniqueSessionId; //Get circuit foreach (Packet p in packets) { if (p.PacketType == PacketType.Session) { SessionPacket sp = (SessionPacket)p; //Circuit Circuit = sp.SessionTrack; //Session mode SessionMode = sp.SessionTypeMode; } if (p.PacketType == PacketType.Participants) { ParticipantPacket pp = (ParticipantPacket)p; //Selected team SelectedTeam = pp.FieldParticipantData[driver_index].ManufacturingTeam; //Selected Driver SelectedDriver = pp.FieldParticipantData[driver_index].PilotingDriver; //Name string driver_name = pp.FieldParticipantData[driver_index].Name.TrimEnd('\0'); string driver_name_clean = ""; foreach (char c in driver_name) { int as_int = Convert.ToInt32(c); if ((as_int < 127 && as_int != 92) == true || as_int == 160) //It is in the normal character range and not a backward slash OR it is a blank space. { driver_name_clean = driver_name_clean + c.ToString(); } } DriverName = driver_name_clean; } } SessionCreatedAt = DateTimeOffset.Now; }
public void IngestPacket(Packet p) { if (Initialized == false) //We have not set up the array of live driver data yet { if (p.PacketType == PacketType.Participants) //We wait for the participant packets to set up { ParticipantPacket pp = (ParticipantPacket)p; List <LiveDriverSessionData> NewData = new List <LiveDriverSessionData>(); for (int t = 0; t < pp.NumberOfActiveCars; t++) { LiveDriverSessionData ldsd = new LiveDriverSessionData(); ldsd.SelectedDriver = pp.FieldParticipantData[t].PilotingDriver; ldsd.TeamColor = CodemastersToolkit.GetTeamColorByTeam(pp.FieldParticipantData[t].ManufacturingTeam); ldsd.SelectedTeam = pp.FieldParticipantData[t].ManufacturingTeam; //The driver display name ldsd.DriverDisplayName = CodemastersToolkit.GetDriverDisplayNameFromDriver(pp.FieldParticipantData[t].PilotingDriver); //If the driver is not recognized (it is a real player, index 100, 101, 102, etc) this will return "Unknown" if (pp.FieldParticipantData[t].IsAiControlled == false) //If it is a player (the above most likely made the displat name 'Unknown', use the player name instead) { ldsd.DriverDisplayName = ApexVisualToolkit.CleanseString(pp.FieldParticipantData[t].Name); } NewData.Add(ldsd); } LiveDriverData = NewData.ToArray(); Initialized = true; } } else //We already have established a list of live driver session data { //If it is a lap packet, plug them in one by one if (p.PacketType == PacketType.Lap) { LapPacket lp = (LapPacket)p; for (int t = 0; t < LiveDriverData.Length; t++) { LiveDriverData[t].FeedLapData(lp.FieldLapData[t], lp.SessionTime); } //Supply the driver ahead distance for all cars (except first place) foreach (LiveDriverSessionData ldsd in LiveDriverData) { if (ldsd.Position != 1) //Only do this for cars that are NOT in first place { //Find the car that is directly ahead foreach (LapPacket.LapData ld in lp.FieldLapData) { if (ld.CarPosition == ldsd.Position - 1) //If it is the car ahead { ldsd.SetDriverAheadData(ld.TotalDistance); } } } } } else if (p.PacketType == PacketType.Session) //if it is a session packet, we have to plug the session type into each { SessionPacket sp = (SessionPacket)p; foreach (LiveDriverSessionData ldsd in LiveDriverData) { ldsd.SetSessionType(sp.SessionTypeMode); } } else if (p.PacketType == PacketType.CarStatus) { CarStatusPacket csp = (CarStatusPacket)p; for (int t = 0; t < LiveDriverData.Length; t++) { LiveDriverData[t].FeedCarStatusData(csp.FieldCarStatusData[t]); } } } }