Beispiel #1
0
 //Static Methods
 #region Static Movement Methods
 ///<summary>
 ///Ray Cast -- if no navcellflags parameter is given then it will use Navigator.Raycast -- else it uses ZetaDia.Physics.Raycast to test navcellflags
 ///</summary>
 public static bool CanRayCast(Vector3 vStartLocation, Vector3 vDestination, NavCellFlags NavType = NavCellFlags.None, bool UseSearchGridProvider = false)
 {
     if (!NavType.Equals(NavCellFlags.None))
     {
         return(ZetaDia.Physics.Raycast(vStartLocation, vDestination, NavType));                //False means nothing hit
     }
     if (UseSearchGridProvider)
     {
         Vector2 hitVector;
         if (vStartLocation.Z >= vDestination.Z)
         {
             return(!Navigator.SearchGridProvider.Raycast(vStartLocation.ToVector2(), vDestination.ToVector2(), out hitVector));
         }
         return(!Navigator.SearchGridProvider.Raycast(vDestination.ToVector2(), vStartLocation.ToVector2(), out hitVector));
     }
     return(!Navigator.Raycast(vStartLocation, vDestination));            //True means nothing hit
 }
Beispiel #2
0
        ///<summary>
        ///Runs raycasting and intersection tests to validate LOS.
        ///</summary>
        public bool LOSTest(Vector3 PositionToTestFrom, Vector3 objposition, bool NavRayCast = true, bool searchGridRayCast = false, bool ServerObjectIntersection = true, NavCellFlags Flags = NavCellFlags.None, bool ContinueOnFailures = true)
        {
            LastLOSCheck=DateTime.Now;
              bool Failed=false;

              if (NavRayCast)
              {//This is a basic raycast test to see if we have clear view of the object.

                    if (PositionToTestFrom.Z > objposition.Z)
                        RayCast = Navigation.Navigation.CanRayCast(PositionToTestFrom, objposition);
                    else
                        RayCast = Navigation.Navigation.CanRayCast(objposition, PositionToTestFrom);

                    if (!RayCast.Value)
                    {
                         Failed=true;
                         if (!ContinueOnFailures) return false;
                    }

              }

             if (searchGridRayCast)
             {
                 Vector2 hitpos;

                 //Must check the Z difference.. (so we don't get false-positive result)
                 if (PositionToTestFrom.Z > objposition.Z)
                     SearchGridRayCast = !Navigator.SearchGridProvider.Raycast(PositionToTestFrom.ToVector2(), objposition.ToVector2(), out hitpos);
                 else
                     SearchGridRayCast = !Navigator.SearchGridProvider.Raycast(objposition.ToVector2(), PositionToTestFrom.ToVector2(), out hitpos);

                 if (!SearchGridRayCast.Value)
                 {
                     Failed = true;
                     if (!ContinueOnFailures) return false;
                 }
             }

              if (ServerObjectIntersection)
              {//This test uses the obstacle cache to check objects for intersection

                    if (FunkyBaseExtension.Difference(FunkyGame.Hero.Position.Z, objposition.Z) > 1f)
                    {
                        //Get actual height using MGP
                        objposition.Z = Navigation.Navigation.MGP.GetHeight(objposition.ToVector2());
                    }

                    ObjectIntersection=ObjectCache.Obstacles.Values.OfType<CacheServerObject>()
                         .Any(obstacle =>
                              obstacle.RAGUID!=Obj.RAGUID&&
                              obstacle.Obstacletype.HasValue&&
                              obstacle.Obstacletype.Value==ObstacleType.ServerObject &&
                              obstacle.TestIntersection(PositionToTestFrom, objposition,false));

                    if (!Failed&&ObjectIntersection.Value)
                    {
                         Failed=true;
                         if (!ContinueOnFailures) return false;
                    }
              }

              if (!Flags.Equals(NavCellFlags.None))
              {//Raycast test to validate it can preform the path -- walk/projectile
                  bool NavTest = Navigation.Navigation.CanRayCast(PositionToTestFrom, objposition, Flags);

                    if (Flags.HasFlag(NavCellFlags.AllowWalk)) NavCellWalk=NavTest;
                    if (Flags.HasFlag(NavCellFlags.AllowProjectile)) NavCellProjectile=NavTest;
                    if (!Failed&&!NavTest)
                    {
                         Failed=true;
                    }
              }

              //this.LastVectorTested=PositionToTestFrom;
              return !Failed;
        }
Beispiel #3
0
 ///<summary>
 ///Ray Cast -- if no navcellflags parameter is given then it will use Navigator.Raycast -- else it uses ZetaDia.Physics.Raycast to test navcellflags
 ///</summary>
 public static bool CanRayCast(Vector3 vStartLocation, Vector3 vDestination, NavCellFlags NavType=NavCellFlags.None)
 {
     if (!NavType.Equals(NavCellFlags.None))
                   return ZetaDia.Physics.Raycast(vStartLocation, vDestination, NavType); //False means nothing hit
              else
                   return !Navigator.Raycast(vStartLocation, vDestination); //True means nothing hit
 }
Beispiel #4
0
        ///<summary>
        ///Runs raycasting and intersection tests to validate LOS.
        ///</summary>
        public bool LOSTest(Vector3 PositionToTestFrom, bool NavRayCast = true, bool ServerObjectIntersection = true, NavCellFlags Flags = NavCellFlags.None, bool ContinueOnFailures = true)
        {
            LastLOSCheck = DateTime.Now;
            bool Failed = false;


            if (NavRayCast)
            {              //This is a basic raycast test to see if we have clear view of the object.
                //Navigator.SearchGridProvider.Update();
                Vector2 hitpos;
                Vector3 ObjectPosition = Obj.Position;

                //Must check the Z difference.. (so we don't get false-positive result)
                if (PositionToTestFrom.Z >= ObjectPosition.Z)
                {
                    RayCast = !Navigator.SearchGridProvider.Raycast(PositionToTestFrom.ToVector2(), ObjectPosition.ToVector2(), out hitpos);
                }
                else
                {
                    RayCast = !Navigator.SearchGridProvider.Raycast(ObjectPosition.ToVector2(), PositionToTestFrom.ToVector2(), out hitpos);
                }

                if (!RayCast.Value)
                {
                    Failed = true;
                    if (!ContinueOnFailures)
                    {
                        return(false);
                    }
                }
            }

            if (ServerObjectIntersection)
            {              //This test uses the obstacle cache to check objects for intersection
                Vector3 TargetTestLocation = Obj.Position;
                if (Funky.Difference(Bot.Character.Data.Position.Z, TargetTestLocation.Z) > 1f)
                {
                    //Get actual height using MGP
                    TargetTestLocation.Z = Navigation.MGP.GetHeight(TargetTestLocation.ToVector2());
                }

                ObjectIntersection = ObjectCache.Obstacles.Values.OfType <CacheServerObject>()
                                     .Any(obstacle =>
                                          obstacle.RAGUID != Obj.RAGUID &&
                                          obstacle.Obstacletype.HasValue &&
                                          obstacle.Obstacletype.Value != ObstacleType.Monster &&
                                          obstacle.TestIntersection(PositionToTestFrom, TargetTestLocation));

                if (!Failed && ObjectIntersection.Value)
                {
                    Failed = true;
                    if (!ContinueOnFailures)
                    {
                        return(false);
                    }
                }
            }


            if (!Flags.Equals(NavCellFlags.None))
            {              //Raycast test to validate it can preform the path -- walk/projectile
                bool NavTest = Navigation.CanRayCast(PositionToTestFrom, Obj.Position, Flags);

                if (Flags.HasFlag(NavCellFlags.AllowWalk))
                {
                    NavCellWalk = NavTest;
                }
                if (Flags.HasFlag(NavCellFlags.AllowProjectile))
                {
                    NavCellProjectile = NavTest;
                }
                if (!Failed && !NavTest)
                {
                    Failed = true;
                }
            }

            //this.LastVectorTested=PositionToTestFrom;
            return(!Failed);
        }
Beispiel #5
0
        ///<summary>
        ///Ray Cast -- if no navcellflags parameter is given then it will use Navigator.Raycast -- else it uses ZetaDia.Physics.Raycast to test navcellflags
        ///</summary>
        public static bool CanRayCast(Vector3 vStartLocation, Vector3 vDestination, NavCellFlags NavType = NavCellFlags.None, bool UseSearchGridProvider = false)
        {
            if (!NavType.Equals(NavCellFlags.None))
                return ZetaDia.Physics.Raycast(vStartLocation, vDestination, NavType); //False means nothing hit

            if (UseSearchGridProvider)
            {
                Vector2 hitVector;
                if (vStartLocation.Z >= vDestination.Z)
                    return !Navigator.SearchGridProvider.Raycast(vStartLocation.ToVector2(), vDestination.ToVector2(), out hitVector);
                return !Navigator.SearchGridProvider.Raycast(vDestination.ToVector2(), vStartLocation.ToVector2(), out hitVector);
            }

            return !Navigator.Raycast(vStartLocation, vDestination); //True means nothing hit
        }
Beispiel #6
0
        ///<summary>
        ///Runs raycasting and intersection tests to validate LOS.
        ///</summary>
        public bool LOSTest(Vector3 PositionToTestFrom, bool NavRayCast=true, bool ServerObjectIntersection=true, NavCellFlags Flags=NavCellFlags.None)
        {
            this.LastLOSCheck=DateTime.Now;

                     Vector3 botmeleeVector=!this.IsBoss?this.BotMeleeVector:this.Position;

                     if (NavRayCast&&Zeta.Navigation.Navigator.Raycast(PositionToTestFrom, botmeleeVector))
                          return false;

                     if (ServerObjectIntersection&&ObjectCache.Obstacles.Values.OfType<CacheServerObject>().Any(obstacle => obstacle.Obstacletype.HasValue&&obstacle.Obstacletype.Value!=ObstacleType.Monster&&obstacle.TestIntersection(PositionToTestFrom, botmeleeVector)))
                          return false;

                     if (!Flags.Equals(NavCellFlags.None)&&!Navigation.CanRayCast(PositionToTestFrom, botmeleeVector, Flags))
                          return false;

                     return true;
        }