public override void Tick() { base.Tick(); CheckCheckpointsBlips(); sprintGUI.Draw(Drivers.FirstOrDefault(x => x.IsPlayer)?.RacePosition, time); }
protected override void ComputerAI() { // Set first to cruise var firstPlace = Drivers.FirstOrDefault(x => x.RacePosition == 1); if (!firstPlace.IsPlayer) { if (firstPlace is ITask task) { task.Cruise(); } } // Set others to chase first foreach (var driver in Drivers.Where(x => !x.IsPlayer || x.RacePosition != 1)) { if (driver is ITask task) { if (driver.DistanceTo(firstPlace.Position) < 20f) { task.Cruise(); } else { task.Chase(firstPlace); } } } }
public void Finish() { IsRacing = false; var player = Drivers.FirstOrDefault(x => x.IsPlayer); BigMessageThread.MessageInstance.ShowRankupMessage("Finish", time.ToString(@"mm\:ss\:fff"), player.RacePosition); }
public PolicyValidationResult Validate() { if (StartDate < DateTime.UtcNow) { return(new PolicyValidationResult("Start Date of Policy")); } if (!Drivers.Any()) { return(new PolicyValidationResult("A minimum of 1 driver must be added to a policy")); } if (Drivers.Count > 5) { return(new PolicyValidationResult("A maximum of 5 drivers can be added to a policy")); } if (Drivers.Any(d => d.DateOfBirth > DateTime.UtcNow)) { return(new PolicyValidationResult("Date of Birth for all drivers must not be in the future")); } if (Drivers.SelectMany(d => d.Claims).Any(c => c.DateOfClaim > DateTime.UtcNow)) { return(new PolicyValidationResult("Claims must not have a date in the future")); } var youngestDriver = YoungestDriver; var ageOfYoungestDriver = youngestDriver.DateOfBirth.CalculateAgeOnDate(StartDate); if (ageOfYoungestDriver < 21) { return(new PolicyValidationResult(string.Format("Age of Youngest Driver: {0}", youngestDriver.Name))); } var oldestDriver = OldestDriver; var ageOfOldestDriver = oldestDriver.DateOfBirth.CalculateAgeOnDate(StartDate); if (ageOfOldestDriver > 75) { return(new PolicyValidationResult(string.Format("Age of Oldest Driver: {0}", oldestDriver.Name))); } var driverWithMoreThan2Claims = Drivers.FirstOrDefault(d => d.Claims.Count > 2); if (driverWithMoreThan2Claims != null) { return(new PolicyValidationResult(string.Format("Driver has more than 2 claims: {0}", driverWithMoreThan2Claims.Name))); } var totalClaims = Drivers.Sum(d => d.Claims.Count); if (totalClaims > 3) { return(new PolicyValidationResult("Policy has more than 3 claims")); } return(new PolicyValidationResult(PolicyValidResult.Succeeded)); }
/// <summary> /// Return driver. /// </summary> /// <param name="driverTypeId"> /// </param> /// <returns> /// The <see cref="IDriver"/>. /// </returns> public static IDriver ReturnDriver(Guid driverTypeId) { if (Drivers == null || !Drivers.Any()) { return(null); } return(Drivers.FirstOrDefault( d => d.Metadata["ValueMetaData"].ToString().ToLower() == driverTypeId.ToString().ToLower()).Value); }
private void Finish() { foreach (var driver in Drivers.Where(x => x.InRace)) { driver.Finish(); } IsRacing = false; var player = Drivers.FirstOrDefault(x => x.IsPlayer); BigMessageThread.MessageInstance.ShowRankupMessage("Finish", time.ToString(@"mm\:ss\:fff"), player.RacePosition); }
public override void Tick() { base.Tick(); CheckPlayState(); try { distanceRaceGUI.Draw(Drivers.FirstOrDefault(x => x.IsPlayer)?.RacePosition, time, GetDistance() / configuration.WinDistance); } catch (DivideByZeroException) { distanceRaceGUI.Draw(Drivers.FirstOrDefault(x => x.IsPlayer)?.RacePosition, time, 1f); } }
public TruckSmartContext(string connection) : base(connection) { if (System.Web.HttpContext.Current.User.Identity.IsAuthenticated) { var thisDriver = Drivers.FirstOrDefault(d => d.DriverID == this.driverID); if (thisDriver == null) { Drivers.Add(new Driver { DriverID = this.driverID, Name = this.driverID, Email = this.driverID }); SaveChanges(); } } }
private void refresh() { Task.Run(() => { try { using (var dp = SimpleIoc.Default.GetInstance <IUnitOfWorkFactory>().CreateUnitOfWork()) { var drivers = dp.DriverRepository.GetAll().OrderBy(t => t.Name); System.Windows.Application.Current.Dispatcher.Invoke(new Action(() => { Drivers.Clear(); foreach (var driver in drivers) { Drivers.Add(new ViewModels.ComboBoxItemViewModel { DisplayText = driver.Name, ID = driver.Id }); } var driverSetting = dp.SettingsRepository.FindSingle(s => s.Key == TruckClientSettingKeys.DRIVER_ID); if (driverSetting != null) { var savedDriver = Drivers.FirstOrDefault(d => d.ID == driverSetting.Value); if (savedDriver != null) { SelectedDriver = savedDriver; } else { SelectedDriver = Drivers[0]; } } else { SelectedDriver = Drivers[0]; } })); } } catch (Exception exc) { Logging.Logger.Log(exc); } }); }
private float GetDistance() { var player = Drivers.FirstOrDefault(x => x.IsPlayer); if (player != null) { if (player.RacePosition == 1) { var secondPlace = Drivers.FirstOrDefault(x => x.RacePosition == 2); if (secondPlace != null) { return(player.DistanceTo(secondPlace.Position)); } } else { return(player.DistanceTo(Drivers.FirstOrDefault(x => x.RacePosition == 1).Position)); } } return(configuration.WinDistance); }
private void CheckCheckpointsBlips() { var player = Drivers.FirstOrDefault(x => x.IsPlayer); if (player != null) { var nextCheckpoint = Checkpoints.FirstOrDefault(x => x.Number == player.Checkpoint + 1); if (nextCheckpoint != null) { if (player.DistanceTo(nextCheckpoint.Position) < 20f) { nextCheckpoint.Blip.Remove(); player.Checkpoint = nextCheckpoint.Number; } } if (player.Checkpoint == Checkpoints.Max(x => x.Number)) { player.Finish(); Finish(); } } }
private void CheckPlayState() { var firstPlace = Drivers.FirstOrDefault(x => x.RacePosition == 1); foreach (var driver in Drivers.Where(x => x.RacePosition != 1 && x.InRace)) { if (driver.DistanceTo(firstPlace.Position) > configuration.WinDistance) { if (!driver.IsPlayer) { UI.Notify($"{driver.ToString()} lose"); } driver.Finish(); } } // If 1 driver left then finish the race if (Drivers.Count(x => x.InRace) == 1 || !Drivers.FirstOrDefault(x => x.IsPlayer).InRace) { Finish(); } }