public static void RunPointTool(UnturnedPlayer Player, PlayerSession Session, UnturnedPlayerEvents.PlayerGesture gesture)
 {
     if (Session.PointTool == PointToolMode.Destroy)
     {
         RaycastResult Raycast = RaycastUtility.RayCastPlayer(Player, RayMasks.BARRICADE | RayMasks.STRUCTURE | RayMasks.VEHICLE);
         if (Raycast.RaycastHit)
         {
             RunDestroyTool(Player, Raycast);
         }
     }
     else if (Session.PointTool == PointToolMode.Utility)
     {
         RaycastResult Raycast = RaycastUtility.RayCastPlayer(Player, RayMasks.BARRICADE | RayMasks.STRUCTURE | RayMasks.VEHICLE);
         if (Raycast.RaycastHit)
         {
             RunUtilityTool(Player, Raycast);
         }
     }
     else if (Session.PointTool == PointToolMode.Repair)
     {
         RaycastResult Raycast = RaycastUtility.RayCastPlayer(Player, RayMasks.BARRICADE | RayMasks.STRUCTURE | RayMasks.VEHICLE);
         if (Raycast.RaycastHit)
         {
             RunRepairTool(Player, Raycast);
         }
     }
     else if (Session.PointTool == PointToolMode.Kill)
     {
         RaycastResult CloseEnemyCheck  = RaycastUtility.RayCastPlayer(Player, RayMasks.AGENT | RayMasks.ENEMY, 7);
         RaycastResult ClosePlayerCheck = RaycastUtility.RayCastPlayer(Player, RayMasks.PLAYER, 10);
         if (ClosePlayerCheck.RaycastHit && ClosePlayerCheck.ParentHasComponent <Player>() && ClosePlayerCheck.TryGetEntity <Player>().channel.owner.playerID.steamID.m_SteamID != Player.CSteamID.m_SteamID)
         {
             RunKillTool(Player, ClosePlayerCheck);
         }
         else if (CloseEnemyCheck.RaycastHit)
         {
             RunKillTool(Player, CloseEnemyCheck);
         }
         else
         {
             Vector3       RaycastSpot = Player.Player.look.aim.position + (Player.Player.look.aim.forward.normalized * 0.5f);
             RaycastResult Raycast     = RaycastUtility.Raycast(RaycastSpot, Player.Player.look.aim.forward, RayMasks.ENEMY | RayMasks.PLAYER | RayMasks.AGENT);
             if (Raycast.RaycastHit)
             {
                 RunKillTool(Player, Raycast);
             }
         }
     }
     else if (Session.PointTool == PointToolMode.Jump)
     {
         RaycastResult Raycast = RaycastUtility.RayCastPlayerAll(Player, 5000);
         if (Raycast.RaycastHit)
         {
             RunJumpTool(Player, Raycast, gesture);
         }
     }
 }
        private bool VectorInWorld(Vector3 Vector)
        {
            RaycastResult DownCast = RaycastUtility.Raycast(new Vector3(Vector.x, 900, Vector.z), Vector3.down, RayMasks.GROUND, 1500);

            if (DownCast.RaycastHit)
            {
                return(Vector.y > (DownCast.Raycast.point.y + 0.1));
            }
            else
            {
                return(false);
            }
        }
        private void NoClipTick()
        {
            while (Active)
            {
                RaycastResult ClipCast = RaycastUtility.RayCastPlayer(Player, RayMasks.AGENT | RayMasks.BARRICADE | RayMasks.STRUCTURE | RayMasks.SMALL | RayMasks.MEDIUM | RayMasks.LARGE | RayMasks.ENVIRONMENT, 10);

                if (ClipCast.RaycastHit && ClipCast.Raycast.distance <= 2)
                {
                    Vector3 TargetPoint = new Vector3(ClipCast.Raycast.point.x, ClipCast.Raycast.point.y - Player.Player.look.heightLook, ClipCast.Raycast.point.z);


                    if (VectorInWorld(TargetPoint))
                    {
                        TaskDispatcher.QueueOnMainThread(delegate { Player.Player.teleportToLocationUnsafe(TargetPoint, Player.Rotation); });
                    }
                }
                Thread.Sleep(ClipUpdateRate);
            }
        }
 public static RaycastResult GetDropPlacement(Vector3 Origin)
 {
     return(RaycastUtility.RaycastAll(Origin, Vector3.down, 20));
 }
        public static void RunJumpTool(UnturnedPlayer Player, RaycastResult Raycast, UnturnedPlayerEvents.PlayerGesture gesture)
        {
            if (gesture == UnturnedPlayerEvents.PlayerGesture.PunchRight)
            {
                int   RunMode = 0;
                float Pitch   = Player.Player.look.pitch;

                if (Player.Stance == EPlayerStance.STAND)
                {
                    if (Pitch <= 5)
                    {
                        RunMode = 1;
                    }
                    else if (Pitch >= 175)
                    {
                        RunMode = 2;
                    }
                    else
                    {
                        RunMode = 0;
                    }
                }
                else if (Player.Stance == EPlayerStance.CROUCH)
                {
                    if (Pitch <= 22)
                    {
                        RunMode = 1;
                    }
                    else if (Pitch >= 155)
                    {
                        RunMode = 2;
                    }
                    else
                    {
                        RunMode = 0;
                    }
                }

                if (RunMode == 0)
                {
                    Player.Player.teleportToLocationUnsafe(Raycast.Raycast.point, Player.Rotation);
                }
                else if (RunMode == 1)
                {
                    if (Raycast.Raycast.distance < 300)
                    {
                        Vector3 Target = new Vector3(Raycast.Raycast.point.x, Raycast.Raycast.point.y + (float)1.75, Raycast.Raycast.point.z);
                        Player.Player.teleportToLocationUnsafe(Target, Player.Rotation);
                    }
                    else
                    {
                        Player.Player.teleportToLocationUnsafe(Raycast.Raycast.point, Player.Rotation);
                    }
                }
                else if (RunMode == 2)
                {
                    if (Raycast.Raycast.distance > 300)
                    {
                        Player.Player.teleportToLocationUnsafe(Raycast.Raycast.point, Player.Rotation);
                    }
                    else
                    {
                        Vector3 ViewDir = Vector3.down;

                        RaycastResult FloorCast        = RaycastUtility.Raycast(Player.Position, Vector3.down, RayMasks.GROUND, 1500);
                        float         DistanceToGround = 9999;
                        if (FloorCast.RaycastHit)
                        {
                            DistanceToGround = FloorCast.Raycast.distance - (float)0.5;
                        }

                        RaycastResult DownCast     = RaycastUtility.RaycastAll(new Vector3(Raycast.Raycast.point.x, Raycast.Raycast.point.y - 3, Raycast.Raycast.point.z), ViewDir, 300);
                        bool          Cont         = !DownCast.RaycastHit;
                        int           Displacement = 3;
                        while (Cont)
                        {
                            DownCast      = RaycastUtility.RaycastAll(new Vector3(Raycast.Raycast.point.x, Raycast.Raycast.point.y - Displacement, Raycast.Raycast.point.z), ViewDir, 300);
                            Displacement += 3;
                            if (Displacement > 15 || DownCast.RaycastHit)
                            {
                                Cont = false;
                            }
                        }

                        if (DownCast.RaycastHit && DownCast.Raycast.distance != 0 && DownCast.Raycast.distance < DistanceToGround)
                        {
                            Player.Player.teleportToLocationUnsafe(new Vector3(DownCast.Raycast.point.x, DownCast.Raycast.point.y + 0.2f, DownCast.Raycast.point.z), Player.Rotation);
                        }
                        else
                        {
                            UnturnedChat.Say(Player, "PointTool_Jump_NoPlatformBelow".Translate());
                        }
                    }
                }
            }
            else if (gesture == UnturnedPlayerEvents.PlayerGesture.PunchLeft)
            {
                Vector3         TargetPos = Raycast.Raycast.point;
                float           Height    = 15;
                RaycastResult[] Placings  =
                {
                    GetDropPlacement(new Vector3(TargetPos.x,     TargetPos.y + Height, TargetPos.z)),
                    GetDropPlacement(new Vector3(TargetPos.x + 1, TargetPos.y + Height, TargetPos.z)),
                    GetDropPlacement(new Vector3(TargetPos.x - 1, TargetPos.y + Height, TargetPos.z)),
                    GetDropPlacement(new Vector3(TargetPos.x,     TargetPos.y + Height, TargetPos.z + 1)),
                    GetDropPlacement(new Vector3(TargetPos.x,     TargetPos.y + Height, TargetPos.z - 1))
                };
                Vector3[] Placing = Placings.Where(X => X.RaycastHit && X.Raycast.distance != 0).OrderByDescending(V => V.Raycast.point.y).CastEnumeration(E => E.Raycast.point).ToArray();

                if (Placing.Count() != 0)
                {
                    Player.Player.teleportToLocationUnsafe(new Vector3(Placing[0].x, Placing[0].y + 0.5f, Placing[0].z), Player.Rotation);
                }
                else
                {
                    Player.Player.teleportToLocationUnsafe(new Vector3(TargetPos.x, TargetPos.y + 0.5f, TargetPos.z), Player.Rotation);
                }
            }
            else if (gesture == UnturnedPlayerEvents.PlayerGesture.Point)
            {
                Vector3 TargetPos  = Raycast.Raycast.point;
                Vector3 CurrentPos = Player.Position;
                Vector3 ResultPos  = Vector3.MoveTowards(TargetPos, CurrentPos, 1);
                Player.Player.teleportToLocationUnsafe(new Vector3(ResultPos.x, ResultPos.y + 0.5f, ResultPos.z), Player.Rotation);
            }
        }