public void OnPlayerBoughtVehicleHandler(Client sender, params object[] arguments)
        {
            //arguments[0] to nazwa pojazdu

            if (!Enum.TryParse(arguments[0].ToString(), out VehicleHash vehicleHash))
            {
                return;
            }

            CarshopVehicleModel vehicle = Vehicles.First(v => v.Name == arguments[0].ToString());

            CharacterEntity character = sender.GetAccountEntity().CharacterEntity;

            if (character.HasMoney(vehicle.Cost))
            {
                character.RemoveMoney(vehicle.Cost);

                VehicleEntity.Create(new FullPosition(new Vector3(-50, -1680, 29.5), new Vector3(0, 0, 0)),
                                     vehicleHash, "", 0, null, ApiExtensions.GetRandomColor(), ApiExtensions.GetRandomColor(), 0f, 0f, sender.GetAccountEntity().CharacterEntity.DbModel);
                sender.SendInfo($"Pojazd {vehicleHash.ToString()} zakupiony pomyślnie.");
            }
            else
            {
                sender.SendError("Nie posiadasz wystarczającej ilości gotówki.");
            }
        }
示例#2
0
        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();
            }
        }
示例#3
0
        public async Task Load()
        {
            try
            {
                WorkingViewModel.Instance.Working = true;

                await _repository.Load();

                foreach (var v in _repository.Vehicles)
                {
                    Vehicles.Add(_vehicleFactory.Create(v));
                }

                SelectedVehicle = Vehicles.First();

                _log.Info("MainViewModel loaded.");
            }
            finally
            {
                WorkingViewModel.Instance.Working = false;
            }
        }