Esempio n. 1
0
 float GetDistanceLineToPoint(Vector3 Po, Vector3 D, Vector3 P)
 {
     Vector3 S = P - Po;
     float Iner = D.X + S.X + D.Y * S.Y + D.Z + S.Z;
     float L = Iner / D.Length();
     L = Math.Abs(L);
     return L;
 }
Esempio n. 2
0
        private void ProcessControls(Vector3 shootCoord, Vector3 shootCoordSnap, Vector3 shootMissileCoord, Ped ped, Entity target)
        {
            var controllerState = _controllerEmulation.ControllerState;

            if (!_menuOpen
                && (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.DPadDown)
                || User32.IsKeyPressed(VirtualKeyStates.VK_LMENU)))
            {
                //character selection
            }
            else if (!_isInVehicle && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))
            {
                _radialMenu.Process(_lastNormalizedCenterDelta, _aspectRatio);
            }
            else
            {
                _freelook.Process(_lastNormalizedCenterDelta, ped, _aspectRatio);
            }

            var radialMenuActive = (!Game.Player.Character.IsInVehicle()
                                && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder));

            if (controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftThumb)
                && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.Start)
                && !_menuOpen)
            {
                _settingsMenu.OpenMenu();
            }

            if (shootCoord.Length() > 0 && Geometry.IsInFrontOfThePlayer(shootCoord))
            {
                var injectRightTrigger = 0;
                if (_settings.FreelookDevice == FeeelookDevice.Gamepad
                    && _settings.AimWithGazeEnabled
                    && !Game.Player.Character.IsInVehicle()
                    && Game.IsKeyPressed(Keys.B))
                {
                    injectRightTrigger += 1;
                }

                //if (_settings.FreelookDevice == FeeelookDevice.Mouse)
                //{
                //	Game.Player.Character.Task.AimAt(shootCoord, 250); //raise the gun
                //}

                if (_settings.FreelookDevice == FeeelookDevice.Gamepad
                    && _settings.ThirdPersonFreelookEnabled
                    && Game.Player.Character.IsInVehicle()
                    && Game.IsKeyPressed(Keys.W))
                {
                    _injectRightTrigger += 1; //TODO: block keyboard
                }

                _injectRightTrigger = injectRightTrigger;

                if (_settings.AimWithGazeEnabled
                    && ((!_isInVehicle
                        && ((!_menuOpen && User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON))
                            || (!radialMenuActive && controllerState.Gamepad.RightTrigger > 0))
                            || (Game.IsKeyPressed(Keys.B)))
                        || (_isInVehicle
                            && (!_menuOpen && User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON)))
                        ))
                {
                    var dir = shootCoord - Game.Player.Character.Position;
                    _headingToTarget = Geometry.DirectionToRotation(dir).Z;
                    //Game.Player.Character.Heading = _headingToTarget;

                    //Game.Player.Character.Rotation = new Vector3(Game.Player.Character.Rotation.X, Game.Player.Character.Rotation.Y, _headingToTarget);
                    //UI.ShowSubtitle("he " + Math.Round(Game.Player.Character.Heading,2));
                    Util.SetPedShootsAtCoord(Game.Player.Character, shootCoord);
                    //Game.Player.Character.Rotation = new Vector3(Game.Player.Character.Rotation.X, Game.Player.Character.Rotation.Y, _headingToTarget);
                }

                Vector2 screenCoords;
                if (Geometry.WorldToScreenRel(shootCoord, out screenCoords))
                {
                    _aiming.MoveCrosshair(screenCoords);
                }

                if (_settings.AimWithGazeEnabled
                    && _isInVehicle
                    && (Game.IsKeyPressed(Keys.B)
                        || (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON1))
                        || ( !_isInAircraft && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder))))
                {
                    _aiming.Shoot(shootCoord);
                }

                if (_settings.IncinerateAtGazeEnabled
                    && (Game.IsKeyPressed(Keys.J)
                        || (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON2))
                        || (!_isInAircraft && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A))
                        || (_isInAircraft && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.A))))
                {
                    _aiming.Incinerate(shootCoordSnap);
                }

                if (_settings.TaseAtGazeEnabled
                    && (Game.IsKeyPressed(Keys.H)
                        || Game.IsKeyPressed(Keys.PageUp)
                        || (!_isInAircraft && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.RightShoulder))))
                {
                    _aiming.Tase(shootCoordSnap);
                }

                if (Game.IsKeyPressed(Keys.U))
                {
                    _aiming.Water(shootCoord);
                }
            }

            if (shootMissileCoord.Length() > 0 && Geometry.IsInFrontOfThePlayer(shootMissileCoord))
            {
                if (_settings.MissilesAtGazeEnabled
                    && (Game.IsKeyPressed(Keys.N)
                    || Game.IsKeyPressed(Keys.PageDown)
                    || (!radialMenuActive && !_menuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B))))
                {
                    if (target != null)
                    {
                        _aiming.ShootMissile(target);
                    }
                    else
                    {
                        _aiming.ShootMissile(shootMissileCoord);
                    }
                }
            }
        }
Esempio n. 3
0
 float GetTheta(Vector3 P1, Vector3 P2)
 {
     float th = (P1.X * P2.X + P1.Y * P2.Y + P1.Z * P2.Z) / (P1.Length() * P2.Length());
     return (float)(Math.Acos(th) * 180.0 / Math.PI);
 }
        public void updateVehicle(uint id, UpdateDataStruct data, StreamedPed ped)
        {
            if (data.vehicle_id > 0)
            {
                var posnew = new Vector3(data.pos_x, data.pos_y, data.pos_z);
                StreamedVehicle veh = vehicleController.GetInstance(data.vehicle_id);
                if (veh != null)
                {
                    if (veh.IsStreamedIn())
                    {
                        if (ped != null && ped.IsStreamedIn() && !ped.gameReference.isInVehicle())
                        {
                            if ((data.state & PlayerState.IsPassenger1) != 0)
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.RightFront);
                            }
                            else if ((data.state & PlayerState.IsPassenger2) != 0)
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.LeftRear);
                            }
                            else if ((data.state & PlayerState.IsPassenger3) != 0)
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.RightFront);
                            }
                            else
                            {
                                ped.gameReference.WarpIntoVehicle(veh.gameReference, VehicleSeat.Driver);
                            }
                        }

                        int healthDelta = data.ped_health - ped.gameReference.Health;
                        ped.gameReference.Health = data.ped_health;
                        ped.last_game_health = data.ped_health;

                        if (healthDelta > 20 && healthDelta < 100)
                        {
                            var bpf = new BinaryPacketFormatter(Commands.Player_damage);
                            bpf.Add(id);
                            //Client.instance.chatController.writeChat("damaged " + healthDelta) ;
                            Client.instance.serverConnection.write(bpf.getBytes());
                        }

                        int vehicleHealthDelta = data.vehicle_health - veh.gameReference.Health;
                        veh.gameReference.Health = data.vehicle_health;
                        veh.last_game_health = data.vehicle_health;

                        if (vehicleHealthDelta > 20 && vehicleHealthDelta < 2000 && data.vehicle_id > 0)
                        {
                            var bpf = new BinaryPacketFormatter(Commands.Vehicle_damage, id, data.vehicle_id, vehicleHealthDelta);
                            Client.instance.serverConnection.write(bpf.getBytes());
                        }

                        if ((data.vstate & VehicleState.IsAsPassenger) != 0) return;
                        veh.position = posnew;
                        if (veh.gameReference.Position.DistanceTo(posnew) > 1.0f)
                        {
                            veh.gameReference.Position = posnew;
                        }
                        //veh.gameReference.Position = posnew;
                        veh.orientation = new Quaternion(data.rot_x, data.rot_y, data.rot_z, data.rot_a);
                        //veh.gameReference.ApplyForce(, Vector3.Zero);
                        veh.gameReference.RotationQuaternion = veh.orientation;
                        var vel = new Vector3(data.vel_x, data.vel_y, data.vel_z);
                        if (System.Math.Abs(veh.gameReference.Velocity.Length() - vel.Length()) > 6.0f)
                        {
                            veh.gameReference.ApplyForce(vel);
                        }
                        if ((data.vstate & VehicleState.IsBraking) == 0)
                        {
                            ped.gameReference.Task.DrivePointRoute(veh.gameReference, 999.0f, posnew - veh.gameReference.Velocity);
                        }
                        else
                        {
                            ped.gameReference.Task.DrivePointRoute(veh.gameReference, 999.0f, posnew + veh.gameReference.Velocity);
                        }
                        if ((data.state & PlayerState.IsShooting) != 0)
                        {
                            Vector3 pos = veh.gameReference.Position + veh.gameReference.Direction;
                            GTA.Native.Function.Call("FIRE_PED_WEAPON", ped.gameReference, pos.X, pos.Y, pos.Z);
                            GTA.Native.Function.Call("TASK_SHOOT_AT_COORD", ped.gameReference, pos.X, pos.Y, pos.Z, (Int32)4, 999992);
                        }
                    }
                }
            }
        }
 /// <summary>
 /// Gets the angle between two 3D vectors.
 /// </summary>
 /// <param name="v1">The first vector.</param>
 /// <param name="v2">The second vector.</param>
 /// <returns>A double representing the angle between the two vectors.</returns>
 public static double GetVectorAngle(this Vector3 v1, Vector3 v2)
 {
     return Math.Acos(Vector3.Dot(v1, v2) / (v1.Length() * v2.Length()));
 }
        private void ProcessMissileAtGaze(Vector3 shootMissileCoord, Entity missileTarget)
        {
            if (!_settings.MissilesAtGazeEnabled) return;

            if (!(shootMissileCoord.Length() > 0) || !Geometry.IsInFrontOfThePlayer(shootMissileCoord)) return;

            var controllerState = _controllerEmulation.ControllerState;

            if (Game.IsKeyPressed(Keys.N)
                || Game.IsKeyPressed(Keys.PageUp)
                || (!_gameState.IsInCharacterSelectionMenu && !_gameState.IsInRadialMenu && !_gameState.IsMenuOpen && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.B)))
            {
                if (missileTarget != null)
                {
                    _aiming.ShootMissile(missileTarget);
                }
                else
                {
                    _aiming.ShootMissile(shootMissileCoord);
                }
            }
        }
        private void ProcessFireAtGaze(Vector3 shootCoord, Vector3 gazeShootCoord)
        {
            if (!(shootCoord.Length() > 0) || !Geometry.IsInFrontOfThePlayer(shootCoord)) return;

            var controllerState = _controllerEmulation.ControllerState;

            if (!_gameState.IsInVehicle
                && !GameState.IsFirstPersonPedCameraActive()
                && !_gameState.IsSniperWeaponAndZoomed
                && !_gameState.IsThrowableWeapon
                && !_gameState.IsMeleeWeapon)
            {
                if (_gameState.IsShootingWithGamepad
                    || _gameState.IsShootingWithMouse)
                {
                    _aiming.Shoot(shootCoord);
                }
                else if (Game.IsKeyPressed(Keys.B)
                    || (User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON1)))

                {
                    _aiming.Shoot(gazeShootCoord);
                }
            }

            if (_gameState.IsInVehicle)
            {
                if ((!_gameState.IsMenuOpen && User32.IsKeyPressed(VirtualKeyStates.VK_LBUTTON))
                    || (!_gameState.IsInAircraft && controllerState.Gamepad.Buttons.HasFlag(GamepadButtonFlags.LeftShoulder)))
                {
                    _aiming.ShootBullet(gazeShootCoord);
                    //TODO: separate flag in settings
                }
                else if (Game.IsKeyPressed(Keys.B)
                    || User32.IsKeyPressed(VirtualKeyStates.VK_XBUTTON1))
                {
                    _aiming.ShootBullet(gazeShootCoord);
                }
            }
        }