Ejemplo n.º 1
0
        private IEnumerator EnterVehicleAnimation(Vehicle.Seat seat, bool immediate)
        {
            var animIndex = seat.IsLeftHand ? AnimIndex.GetInLeft : AnimIndex.GetInRight;

            PlayerModel.VehicleParentOffset = Vector3.Scale(PlayerModel.GetAnim(AnimGroup.Car, animIndex).RootEnd, new Vector3(-1, -1, -1));

            if (!immediate)
            {
                var animState = PlayerModel.PlayAnim(AnimGroup.Car, animIndex, PlayMode.StopAll);
                animState.wrapMode = WrapMode.Once;

                while (animState.enabled)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }

            // player now completely entered the vehicle

            IsInVehicleSeat = true;

            if (seat.IsDriver)
            {
                PlayerModel.PlayAnim(AnimGroup.Car, AnimIndex.Sit, PlayMode.StopAll);
                CurrentVehicle.StartControlling();
            }
            else
            {
                PlayerModel.PlayAnim(AnimGroup.Car, AnimIndex.SitPassenger, PlayMode.StopAll);
                CurrentVehicle.StopControlling();
            }
        }
Ejemplo n.º 2
0
        public void ExitVehicle(bool immediate = false)
        {
            if (!IsInVehicle || !IsInVehicleSeat)
            {
                return;
            }

            // this should be done only if player was a driver ?
            CurrentVehicle.StopControlling();

            if (IsLocalPlayer)
            {
                /*
                 * SendToServer(_lastPassengerState = new PlayerPassengerState {
                 * Vechicle = null
                 * }, DeliveryMethod.ReliableOrdered, 1);
                 */
            }
            else
            {
                //    _snapshots.Reset();
            }

            StartCoroutine(ExitVehicleAnimation(immediate));
        }
Ejemplo n.º 3
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();
            }
        }
Ejemplo n.º 4
0
        public void ExitVehicle(bool immediate = false)
        {
            if (!IsInVehicle || !IsInVehicleSeat)
            {
                return;
            }

            CurrentVehicle.StopControlling();

            if (IsLocalPlayer)
            {
                SendToServer(_lastPassengerState = new PlayerPassengerState {
                    Vechicle = null
                }, DeliveryMethod.ReliableOrdered, 1);
            }
            else
            {
                _snapshots.Reset();
            }

            StartCoroutine(ExitVehicleAnimation(immediate));
        }
Ejemplo n.º 5
0
        public override int GetHashCode()
        {
            int hash = 1;

            if (header_ != null)
            {
                hash ^= Header.GetHashCode();
            }
            hash ^= modes_.GetHashCode();
            if (CurrentMode.Length != 0)
            {
                hash ^= CurrentMode.GetHashCode();
            }
            hash ^= maps_.GetHashCode();
            if (CurrentMap.Length != 0)
            {
                hash ^= CurrentMap.GetHashCode();
            }
            hash ^= vehicles_.GetHashCode();
            if (CurrentVehicle.Length != 0)
            {
                hash ^= CurrentVehicle.GetHashCode();
            }
            hash ^= Modules.GetHashCode();
            hash ^= MonitoredComponents.GetHashCode();
            if (DockerImage.Length != 0)
            {
                hash ^= DockerImage.GetHashCode();
            }
            if (UtmZoneId != 0)
            {
                hash ^= UtmZoneId.GetHashCode();
            }
            if (PassengerMsg.Length != 0)
            {
                hash ^= PassengerMsg.GetHashCode();
            }
            return(hash);
        }
Ejemplo n.º 6
0
        private IEnumerator ExitVehicleAnimation(bool immediate)
        {
            IsDrivingVehicle = false;
            IsInVehicleSeat  = false;

            var seat = CurrentVehicle.GetSeat(_currentVehicleSeatAlignment);

            var animIndex = seat.IsLeftHand ? AnimIndex.GetOutLeft : AnimIndex.GetOutRight;

            PlayerModel.VehicleParentOffset = Vector3.Scale(PlayerModel.GetAnim(AnimGroup.Car, animIndex).RootStart, new Vector3(-1, -1, -1));

            if (!immediate)
            {
                var animState = PlayerModel.PlayAnim(AnimGroup.Car, animIndex, PlayMode.StopAll);
                animState.wrapMode = WrapMode.Once;

                while (animState.enabled)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }

            PlayerModel.IsInVehicle = false;

            CurrentVehicle = null;
            _currentVehicleSeatAlignment = Vehicle.SeatAlignment.None;

            transform.localPosition = PlayerModel.VehicleParentOffset;
            transform.localRotation = Quaternion.identity;

            Camera.transform.SetParent(null, true);
            transform.SetParent(null);

            _controller.enabled = true;

            PlayerModel.VehicleParentOffset = Vector3.zero;
        }
Ejemplo n.º 7
0
        public VehicleOptionsMenu() : base(SubMenuTitle("VEHICLE OPTIONS"))
        {
            repair            = new UIMenuItem("Repair");
            repair.Activated += (s, i) => { if (CurrentVehicle)
                                            {
                                                CurrentVehicle.Repair();
                                            }
            };

            driveForce = new UIMenuNumericScrollerItem <float>("Drive Force", "", 0.0f, 1000.0f, 0.01f)
            {
                Value = 0.0f
            }.WithTextEditing();
            driveForce.IndexChanged += (s, o, n) => { if (CurrentVehicle)
                                                      {
                                                          CurrentVehicle.DriveForce = driveForce.Value;
                                                      }
            };

            topSpeed = new UIMenuNumericScrollerItem <float>("Top Speed (m/s)", "", 0.0f, 1000.0f, 0.01f)
            {
                Value = 0.0f
            }.WithTextEditing();
            topSpeed.IndexChanged += (s, o, n) => { if (CurrentVehicle)
                                                    {
                                                        CurrentVehicle.TopSpeed = topSpeed.Value;
                                                    }
            };

            dirtLevel = new UIMenuNumericScrollerItem <float>("Dirt Level", "", 0.0f, 15.0f, 0.01f)
            {
                Value = 0.0f
            }.WithTextEditing();
            dirtLevel.IndexChanged += (s, o, n) => { if (CurrentVehicle)
                                                     {
                                                         CurrentVehicle.DirtLevel = dirtLevel.Value;
                                                     }
            };

            doors = new UIMenuNumericScrollerItem <int>("Doors", "Select which door to open and close.", -1, 0, 1)
            {
                Value = DoorIdAll
            };
            doors.Formatter = i => doors.Maximum == DoorIdNone ? "" : i switch
            {
                DoorIdAll => "All",
                _ => Game.GetLocalizedString($"PM_DPV{i}") ?? i.ToString()
            };
            doors.IndexChanged += (s, o, n) => doors.Description = doors.Maximum == DoorIdNone ? "" : doors.Value switch
            {
                DoorIdAll => "Select to open all doors.",
                DoorIdNone => "Select to close all doors.",
                _ => "Select which door to open and close."
            };
            doors.Activated += (s, i) => DoorActivated(doors.Value);

            speedBomb            = new UIMenuItem("Speed Bomb");
            speedBomb.Activated += (s, i) =>
            {
                if (!CurrentVehicle)
                {
                    return;
                }

                speedBomb.Enabled = false;
                speedBombFiber    = GameFiber.StartNew(SpeedBombRoutine);
            };

            AddItems(repair, driveForce, topSpeed, dirtLevel, doors, speedBomb);
            this.WithFastScrollingOn(driveForce, topSpeed, dirtLevel);
        }