Beispiel #1
0
        private GuiQuadVehicle AddVehicle(long vehicleId)
        {
            foreach (var vehicle in Vehicles.Where(vehicle => vehicle.ID == vehicleId))
            {
                return(vehicle as GuiQuadVehicle);
            }

            var newVehicle = new GuiQuadVehicle(vehicleId);

            Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Normal, new Action(() =>
            {
                bool find = Vehicles.Any(vehicle => vehicle.ID == vehicleId);
                if (!find)
                {
                    Vehicles.Add(newVehicle);
                    Map.EntitysItemsSource.Add(newVehicle.MapEntity);

                    /*if (MissionComponent == null)
                     *  MissionComponent = ServiceLocator.Current.GetInstance<IMissionComponent>();
                     * if (MissionComponent != null)
                     *  MissionComponent.ReadMission(vehicleId);*/
                }
            }));

            Messenger.Default.Send(new NewVehicleMessenger {
                Vehicle = vehicleId
            });
            return(newVehicle);
        }
Beispiel #2
0
 public override void Update(IEnumerable <VehicleUpdate> updates = null)
 {
     base.Update(updates);
     if (Alive && !Vehicles.Any())
     {
         Alive = false;
     }
 }
Beispiel #3
0
 /// <summary>
 /// Fleets are as visible as their most visible space object. Not that the others will actually be that visible...
 /// </summary>
 /// <param name="emp"></param>
 /// <returns></returns>
 public Visibility CheckVisibility(Empire emp)
 {
     if (!Vehicles.Any(v => v != null))
     {
         return(Visibility.Unknown);
     }
     return(Vehicles.Where(v => v != null).Max(sobj => sobj.CheckVisibility(emp)));
 }
        public void AddVehicleToCarshop(Client sender, VehicleHash hash, VehicleClass vehicleClass, decimal cost, string type, string type2 = "Empty")
        {
            if (!sender.HasRank(ServerRank.AdministratorRozgrywki2))
            {
                sender.SendWarning("Nie posiadasz uprawnień do tworzenia pojazdu w salonie.");
                return;
            }

            if (Vehicles.Any(v => v.Hash == hash))
            {
                sender.SendError("Podany pojazd jest już dodany.");
                return;
            }

            MoneyValidator validator = new MoneyValidator();

            if (!validator.IsValid(cost))
            {
                sender.SendError("Wprowadzona kwota gotówki jest nieprawidłowa.");
                return;
            }

            CarshopType endType      = CarshopType.Empty;
            CarshopType endType2     = CarshopType.Empty;
            var         carshopTypes = ((CarshopType[])Enum.GetValues(typeof(CarshopType))).ToList();

            if (carshopTypes.All(carshopType => carshopType.GetDescription() != type && carshopType.GetDescription() != type2))
            {
                sender.SendError("Wprowadzony typ salonu jest nieprawidłowy.");
            }

            foreach (CarshopType item in carshopTypes)
            {
                if (item.GetDescription() == type)
                {
                    endType = item;
                }
                if (item.GetDescription() == type2)
                {
                    endType2 = item;
                }
            }

            if (endType2 != CarshopType.Empty)
            {
                endType = endType | endType2;
            }

            CarshopVehicleModel vehicle =
                new CarshopVehicleModel(hash.ToString(), hash, vehicleClass, cost, endType)
            {
                CreatorForumName = sender.GetAccountEntity().DbModel.Name
            };

            XmlHelper.AddXmlObject(vehicle, Path.Combine(Utils.XmlDirectory, "CarshopVehicles"), vehicle.Name);
        }
Beispiel #5
0
        public Race UpdateVehicleInfo(UpsertVehicle vehicle)
        {
            if (Status == RaceStatusType.Running)
                throw new Exception("Cannot update vehicle info while the race is running.");
            if (Vehicles.Any(v => v.TeamName.Equals(vehicle.TeamName)))
                throw new Exception($"Team name '{vehicle.TeamName}' is already taken.");

            Vehicles.FirstOrDefault(v => v.Id.Equals(vehicle.Id)).UpdateInfo(vehicle);

            return this;
        }
Beispiel #6
0
        public Race AddVehicle(UpsertVehicle vehicle)
        {
            if (Status == RaceStatusType.Running)
                throw new Exception("Cannot add vehicle to the race that is running.");
            if (Vehicles.Any(v => v.TeamName.Equals(vehicle.TeamName)))
                throw new Exception($"Team name '{vehicle.TeamName}' is already taken.");

            Vehicles.Add(new Vehicle(vehicle.Id, vehicle.TeamName, vehicle.Model, vehicle.ManufacturingDate, vehicle.Type, VehicleStatus.Pending, 0, string.Empty));

            return this;
        }
        public async Task LoadData(string userId, User userProfile)
        {
            this.userProfile = userProfile;
            currentVehicle   = null;
            Vehicles.Clear();
            bool isAuthenticated       = !string.IsNullOrWhiteSpace(userId) && InternetAccessIsAvailable;
            bool replaceCurrentVehicle = false;
            IMobileServiceTable <Vehicle> vehicleTable = isAuthenticated ? App.MobileService.GetTable <Vehicle>() : null;

            if (isAuthenticated)
            {
                IEnumerable <Vehicle> serverVehicles = await vehicleTable.Where(v => v.UserName == userId).ToEnumerableAsync();

                // If the vehicle is not the default and it does not already exist on the server then insert it
                if (CurrentVehicle != null && CurrentVehicle.Model != DEFAULT_VEHICLE.Model && !serverVehicles.Any(v => v.Key == CurrentVehicle.Key))
                {
                    var vehicleModel = CurrentVehicle.AsModel();
                    await vehicleTable.InsertAsync(vehicleModel);

                    CurrentVehicle.Id = vehicleModel.id;
                    Vehicles.Add(CurrentVehicle);
                }
                else
                {
                    replaceCurrentVehicle = true;
                }
                foreach (var serverVehicle in serverVehicles)
                {
                    Vehicles.Add(serverVehicle.AsViewModel());
                }
            }
            else if (CurrentVehicle != null)
            {
                Vehicles.Add(currentVehicle);
            }

            if (!Vehicles.Any())
            {
                Vehicles.Add(DEFAULT_VEHICLE);
                CurrentVehicle = DEFAULT_VEHICLE;
            }
            else if (CurrentVehicle == null || replaceCurrentVehicle)
            {
                // Either select the first vehicle OR refresh the current vehicle details from the server
                CurrentVehicle = CurrentVehicle == null?Vehicles.First() : Vehicles.SingleOrDefault(v => v.Key == CurrentVehicle.Key) ?? Vehicles.First();
            }
        }
Beispiel #8
0
 public virtual void Update(IEnumerable <VehicleUpdate> updates = null)
 {
     if (updates != null)
     {
         foreach (var update in updates)
         {
             if (update.Durability <= 0)
             {
                 Vehicles.Remove(update.Id);
             }
         }
     }
     Rect       = Vehicles.Any() ? new Rect(Vehicles.Values) : new Rect(0, 0, 0, 0);
     MassCenter = Vehicles.Any()
         ? new Point(Vehicles.Values.Average(i => i.X), Vehicles.Values.Average(i => i.Y))
         : Point.Zero;
 }
Beispiel #9
0
        public async Task OnGetAsync()
        {
            Stopwatch watch = Stopwatch.StartNew();

            Lights = await _hueConnector.GetLightsAsync();

            Lights = Lights.OrderBy(l => l.Name).ToList();

            System.Console.WriteLine($"Hue took {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            Thermostat = await _ecobeeConnector.GetThermostatAsync();

            System.Console.WriteLine($"Thermostat took {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            RemoteSensors = Thermostat.RemoteSensors.Select(s => (IRemoteSensor)s).ToList();
            System.Console.WriteLine($"Thermo Sensors took {watch.ElapsedMilliseconds}ms");
            watch.Restart();
            //add garage sensors
            RemoteSensors.AddRange(await _garageSensorConnector.GetSensorsAsync());
            System.Console.WriteLine($"Garage Sensors took {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            Vehicles = (await _teslaConnector.GetVehiclesAsync())?.Vehicles ?? new TeslaVehicle[] { };

            System.Console.WriteLine($"Vehicles took {watch.ElapsedMilliseconds}ms");
            watch.Restart();

            VehicleData = new Dictionary <string, VehicleData>();
            if (Vehicles.Any())
            {
                foreach (TeslaVehicle vehicle in Vehicles)
                {
                    TeslaVehicleDataResponse response = await _teslaConnector.GetVehicleDataAsync(vehicle.IdS);

                    if (response != null)
                    {
                        VehicleData[vehicle.IdS] = response.VehicleData;
                    }
                }
            }

            System.Console.WriteLine($"Vehicle Data took {watch.ElapsedMilliseconds}ms");
            watch.Stop();
        }
Beispiel #10
0
        public GroupTask FormTask(ArmyInfo opponent, StrategyType strategy)
        {
            var task = GetTaskByStrategy(opponent, strategy);

            GroupTask scaleTask = null;

            if (task != null && Target != null && Target.variance > 1.5 * initVariance)
            {
                var scaletask2 = CreateScaleTask(0.1, (opp, strat) => GetTaskByStrategy(opp, strat), task.priority, task.order, 10);
                var rotatetask = CreateRotateTask(-PI / 4, (opp, strat) => scaletask2, task.priority, task.order, 10);
                var scaletask1 = CreateScaleTask(0.1, (opp, strat) => rotatetask, task.priority, task.order, 10);
                scaleTask = CreateMoveTask(new Coordinate(), (opp, strat) => scaletask1, task.priority, task.order);
                //scaleTask = CreateScaleTask(0.1, (opp, strat) => GetTaskByStrategy(opp, strat), task.priority, task.order, (int)Min(10, Max(60, Target.variance / initVariance * 10d)));
            }
            if (task != null && Vehicles.Any(v => !v.Value.IsSelected))
            {
                return(CreateSelectTask((opp, strat) => scaleTask ?? GetTaskByStrategy(opponent, strategy), task.priority, task.order));
            }

            return(scaleTask ?? task);
        }
Beispiel #11
0
 public void ReturnFalseIfTheSequenceContainsNoElementsThatSatisfyThePredicate()
 {
     Assert.False(Vehicles.Any(v => v.FuelEconomy.Combined > 100));
 }
Beispiel #12
0
 public void ReturnTrueIfTheSequenceContainsAnyElementsThatSatisfyThePredicate()
 {
     Assert.True(Vehicles.Any(v => v.FuelEconomy.Combined > 50));
 }
Beispiel #13
0
 public void ReturnTrueIfTheSequenceContainsAnyElements()
 {
     Assert.True(Vehicles.Any());
 }
 public List <string> ReadLocationsLessThanPassengers(int passengers)
 {
     return(_manufacturers.Where(m => _vehicles.Any(x => x.Passengers < passengers && x.ManufacturerID == m.ID)).Select(m => m.Location).ToList());
     //return _manufacturers.Where(manufacturerName).ToList();
     //throw new NotImplementedException();
 }
Beispiel #15
0
 public bool CanTarget(ITargetable target)
 {
     return(Vehicles.Any(sobj => sobj.CanTarget(target)));
 }
Beispiel #16
0
        public override string ToString()
        {
            var items = new List <string>();

            if (TreatyClauses.Any())
            {
                if (TreatyClauses.Count == 1)
                {
                    items.Add(TreatyClauses.Single().ToString());
                }
                else
                {
                    items.Add(TreatyClauses.Count + " treaty clauses");
                }
            }
            if (Planets.Any())
            {
                if (Planets.Count == 1)
                {
                    items.Add(Planets.Single().ToString());
                }
                else
                {
                    items.Add(Planets.Count + " planets");
                }
            }
            if (Vehicles.Any())
            {
                if (Vehicles.Count == 1)
                {
                    items.Add(Vehicles.Single().ToString());
                }
                else
                {
                    items.Add(Vehicles.Count + " vehicles");
                }
            }
            if (Resources.Any(kvp => kvp.Value != 0))
            {
                items.Add(Resources.ToString());
            }
            if (Technology.Any())
            {
                if (Technology.Count == 1)
                {
                    var kvp = Technology.Single();
                    items.Add(kvp.Key + " to level " + kvp.Value);
                }
                else
                {
                    items.Add(Technology.Count + " technologies");
                }
            }
            if (StarCharts.Any())
            {
                if (StarCharts.Count == 1)
                {
                    items.Add("the star chart for " + StarCharts.Single().ToString());
                }
                else
                {
                    items.Add(StarCharts.Count + " star charts");
                }
            }
            if (CommunicationChannels.Any())
            {
                if (CommunicationChannels.Count == 1)
                {
                    items.Add("comm channels to " + CommunicationChannels.Single().ToString());
                }
                else
                {
                    items.Add(CommunicationChannels.Count + " comm channels");
                }
            }
            if (!items.Any())
            {
                return("nothing");
            }
            return(string.Join(", ", items.ToArray()));
        }