public void UpdateVehicleFull(Client sender) { ExtendedVehicle extendedVehicle = _vehicleHandler.CreateExtendedVehicle(sender.vehicle); extendedVehicle.FullUpdate(); extendedVehicle.Save(); }
private async void Save(ExtendedVehicle extendedVehicle) { if (extendedVehicle != null) { if (!await this.CheckIfContainsSameName(extendedVehicle)) { try { await this.clientOperationManager.Save(VehiclesMapping.ToVehicle(extendedVehicle)); extendedVehicle.IsItemSaved = true; MessageBox.Show("Vehicle saved successfuly", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } catch (EndpointNotFoundException e) { Trace.WriteLine(e); MessageBox.Show("Error: Connection lost", "Information", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception e) { Trace.WriteLine(e); MessageBox.Show("Failed to save vehicle, for extended info watch log", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } } else { MessageBox.Show("Such vehicle already exists", "Information", MessageBoxButton.OK, MessageBoxImage.Exclamation); } } }
public async void RepairVehicle(ExtendedVehicle extendedVehicle) { if (extendedVehicle != null) { this.CarStation.RepairVehicle(extendedVehicle); if (extendedVehicle.IsItemSaved) { try { await this.clientOperationManager.Repare(VehiclesMapping.ToVehicle(extendedVehicle)); MessageBox.Show("Vehicle Repared successfuly", "Information", MessageBoxButton.OK, MessageBoxImage.Information); } catch (EndpointNotFoundException e) { Trace.WriteLine(e); MessageBox.Show("Error: Connection lost", "Information", MessageBoxButton.OK, MessageBoxImage.Error); } catch (Exception e) { Trace.WriteLine(e); MessageBox.Show("Failed to repare vehicle, for extended info watch log", "Information", MessageBoxButton.OK, MessageBoxImage.Warning); } } } }
protected override void OnExecute() { if (!_vehicle.value) { Debug.LogError("Vehicle is null.", agent); } else { vehicle = _vehicle.value; seat = vehicle.seats.FirstOrDefault(s => !s.user); if (seat != null) { agent.transform.parent = seat.transform; agent.transform.localPosition = Vector3.zero; agent.transform.localRotation = Quaternion.identity; characterController.enabled = false; vehicle.handBrake = false; vehicle.Team = agent.Team; } else { EndAction(false); } } }
public void RepairVehicle(ExtendedVehicle extendedVehicle) { if (extendedVehicle != null) { extendedVehicle.VehiclePartsList.ToList().ForEach(part => part.State = Part.MaxStateValue); extendedVehicle.AddOnsCollection.ToList().ForEach(addOn => addOn.NeedsRepare = false); } }
public int RepairPrice(ExtendedVehicle extendedVehicle) { int sum = 0; if (extendedVehicle != null) { sum = extendedVehicle.VehiclePartsList.Sum(p => Part.MaxStateValue - p.State) * 10; sum += extendedVehicle.AddOnsCollection.Where(addOn => addOn.NeedsRepare).Sum(a => a.Price); } return(sum); }
} //check db for existanse of the same name in it #endregion #region Procedures private async void InnitListOfVehiclesFromDataBase() { this.CarStation.Vehicles.Clear(); var vehiclesFromXml = await this.clientOperationManager.Read(); if (vehiclesFromXml != null) { foreach (var current in vehiclesFromXml) { ExtendedVehicle container = new ExtendedVehicle(current); container.IsItemSaved = true; Application.Current.Dispatcher.Invoke(() => { this.CarStation.AddVehicle(container); }); } } MessageBox.Show("LOaded"); } //innit from xml
public void AddVehicle(ExtendedVehicle extendedVehicle) { this.Vehicles.Add(extendedVehicle); }
public void SpawnVehicle(Client sender, int vehicleId) { ExtendedVehicle extendedVehicle = _vehicleHandler.CreateExtendedVehicle(vehicleId); extendedVehicle.Create(); }
public void DestroyVehicle(Client sender) { ExtendedVehicle extendedVehicle = _vehicleHandler.CreateExtendedVehicle(sender.vehicle); extendedVehicle.Destroy(true); }
public override void Update() { if (routes == null) { throw new NullReferenceException(); } Thread[] tmpThreads = new Thread[ApiRequest.apiRequests.Length]; for (int i = 0; i < ApiRequest.apiRequests.Length; i++) { List <ExtendedRoute> extendedRoutesCurrentPart = extendedRoutes[i]; metka: foreach (ExtendedVehicle ev in extendedVehicles[i]) { if (DateTime.Now - ev.LastUpdatingMomentOnThisBase > TimeSpan.FromMinutes(3)) { RemoveVehicle(ev.vehicle); extendedVehicles[i].Remove(ev); goto metka; } } List <ExtendedVehicle> extendedVehiclesCurrentPart = extendedVehicles[i]; ApiRequest currentApiRequest = ApiRequest.apiRequests[i]; int index = i; tmpThreads[i] = new Thread(delegate() { StringBuilder tmp = new StringBuilder(); foreach (ExtendedRoute r in extendedRoutesCurrentPart) { tmp.Append(r.idForvard + "-0," + r.idReverse + "-0,"); } tmp.Remove(tmp.Length - 1, 1); string str = tmp.ToString(); //str = "159-0,210-0,208-0,209-0,161-0,160-0,163-0,164-0,211-0,162-0,1-0,2-0,4-0,3-0,140-0,139-0,142-0,141-0,6-0,5-0,8-0,7-0,10-0,9-0,11-0,12-0,14-0,13-0,144-0,143-0,16-0,15-0,18-0,17-0,61-0,62-0,19-0,20-0,73-0,74-0,184-0,183-0,165-0,167-0,166-0,168-0,169-0,170-0,22-0,21-0,146-0,145-0,28-0,27-0,26-0,25-0,147-0,148-0,30-0,29-0,32-0,31-0,136-0,135-0,133-0,134-0,138-0,137-0,34-0,33-0,214-0,173-0,212-0,171-0,213-0,172-0,215-0,175-0,176-0,174-0,97-0,95-0,94-0,99-0,96-0,107-0,106-0,150-0,149-0,189-0,188-0,38-0,37-0,119-0,120-0,121-0,122-0,40-0,39-0,178-0,207-0,204-0,205-0,206-0,182-0,181-0,42-0,41-0,93-0,90-0,89-0,91-0,92-0,124-0,123-0,44-0,43-0,100-0,102-0,101-0,108-0,109-0,151-0,152-0,126-0,125-0,46-0,45-0,128-0,127-0,48-0,47-0,104-0,105-0,103-0,110-0,111-0,50-0,49-0,52-0,51-0,153-0,154-0,54-0,53-0,156-0,155-0,55-0,56-0,157-0,158-0,58-0,57-0,130-0,129-0,60-0,59-0,66-0,65-0,67-0,68-0,132-0,131-0,186-0,185-0,69-0,70-0,72-0,71-0,76-0,75-0,77-0,187-0,78-0,80-0,79-0,82-0,81-0,84-0,83-0,86-0,85-0,87-0,88-0,309-0,308-0"; dynamic returnedInfo = Request.SendRequest(currentApiRequest.markersRequest + str); //if (returnedInfo == null) //throw new Exception(); //{ // Thread.Sleep(5000); // returnedInfo = Request.SendRequest(currentApiRequest.markersRequest + str); // if (returnedInfo == null) throw new Exception(); //} while (returnedInfo == null) { Thread.Sleep(GlobalVehiclesProvider.UpdatingPeriodMilliseconds); returnedInfo = Request.SendRequest(currentApiRequest.markersRequest + str); } dynamic objects = returnedInfo.anims; //ExtendedVehicle extendedVehicle = null; DateTime lastUpdatingMoment; OptimalRoute.GeoCoords coords = null; //MessageBox.Show((objects as IEnumerable<dynamic>).Count().ToString()); foreach (dynamic obj in objects) { ExtendedVehicle newExtendedVehicle = new ExtendedVehicle(obj, this, index); bool ok = true; lastUpdatingMoment = DateTime.Parse((string)obj.lasttime); coords = new OptimalRoute.GeoCoords(Math.Round((double)obj.lat / 1000000, 4), Math.Round((double)obj.lon / 1000000, 4)); foreach (ExtendedVehicle v in extendedVehiclesCurrentPart) { if (v.id == newExtendedVehicle.id) { ok = false; //foreach (ExtendedVehicle extendedVehicle in extendedVehiclesCurrentPart) //{ // if (extendedVehicle.id == int.Parse((string)obj.id)) // { Vehicle veh = v.vehicle; // extendedVehicle.vehicle; if (veh != null) { vehiclesInfo[veh] = new Group(coords, lastUpdatingMoment); } v.Updated(); break; // } //} //break; } } if (ok) { extendedVehiclesCurrentPart.Add(newExtendedVehicle); newExtendedVehicle.Updated(); vehiclesInfo.TryAdd(newExtendedVehicle.vehicle, new Group(coords, lastUpdatingMoment)); //vehiclesInfo.Add(newExtendedVehicle.vehicle, new Group(coords, lastUpdatingMoment)); } } }); //tmpThreads[i].Start(); } foreach (Thread t in tmpThreads) { t.Start(); } foreach (Thread t in tmpThreads) { t.Join(); } }