예제 #1
0
        /// <summary>
        /// Finds the path.
        /// </summary>
        /// <param name="from">From.</param>
        /// <param name="to">To.</param>
        /// <param name="continentNameMpq">The continent name MPQ.</param>
        /// <param name="resultSuccess">if set to <c>true</c> [result success].</param>
        /// <param name="addFromAndStart">if set to <c>true</c> [add from and start].</param>
        /// <param name="loadAllTile"></param>
        /// <returns></returns>
        private static List <Point> FindPath(Point from, Point to, string continentNameMpq, out bool resultSuccess,
                                             bool addFromAndStart, bool loadAllTile, bool ShortPath, bool hideMe = false)
        {
            // Prevent Z modified with "GetZ" to be passed as reference to original points/lists.
            from = new Point(from);
            to   = new Point(to);
            if (!hideMe)
            {
                // should be run only from the function that allow pathfinder patchwerk, nowhere else
                Logging.WriteError("FindPath: Error, accessed from unknown location.");
            }
            if (from.DistanceTo(to) <= 1f)
            {
                resultSuccess = true;
                return(new List <Point> {
                    from, to
                });
            }
            if (from.Type.ToLower() == "swimming")
            {
                if (TraceLine.TraceLineGo(new Point(to.X, to.Y, to.Z + 1000), to, Enums.CGWorldFrameHitFlags.HitTestLiquid))
                {
                    // The destination is in water
                    if (!TraceLine.TraceLineGo(from, to))
                    {
                        Logging.WriteNavigator("Swimmming right to the destination");
                        resultSuccess = true;
                        return(new List <Point> {
                            from, to
                        });
                    }
                    Logging.WriteNavigator("Swimming to the destination using the PathFinder");
                }
                else
                {
                    from.Z = GetZPosition(from); // get to the bottom of the ocean to avoid infinite 0 count path
                    Logging.WriteNavigator("Using the PathFinder to destination out of water");
                }
            }
            if (from.Type.ToLower() == "flying")
            {
                from.Z = GetZPosition(from);
                Logging.WriteNavigator("Using the PathFinder while flying");
            }
            List <Point> locList = new List <Point>();

            resultSuccess = true;
            try
            {
                if (!UsePatherFind || continentNameMpq == "None")
                {
                    locList.Add(from);
                    locList.Add(to);
                    return(locList);
                }

                if (_pather == null)
                {
                    _pather = new Pather(continentNameMpq);
                }
                if (_pather.Continent != continentNameMpq)
                {
                    _pather.Dispose();
                    _pather = new Pather(continentNameMpq);
                }

                if (addFromAndStart)
                {
                    locList.Add(from);
                }

                if (loadAllTile)
                {
                    _pather.LoadAllTiles();
                }

                bool failedPolyref;
                locList = ShortPath ? _pather.FindPathSimple(from, to, out resultSuccess, out failedPolyref, true) : _pather.FindPath(from, to, out resultSuccess, out failedPolyref);
                if (addFromAndStart && resultSuccess)
                {
                    locList.Add(to);
                }

                if (!resultSuccess && failedPolyref)
                {
                    /*Logging.WriteDebug("Reloading PathFinder...");
                     * _pather.Dispose();
                     * _pather = new Pather(continentNameMpq);
                     * locList = ShortPath ? _pather.FindPathSimple(from, to, out resultSuccess, out failedPolyref, true) : _pather.FindPath(from, to, out resultSuccess, out failedPolyref);
                     * if (addFromAndStart && resultSuccess)
                     *  locList.Add(to);*/
                }

                // Clean list:
                for (int i = 0; i <= locList.Count - 2; i++)
                {
                    if (locList[i].DistanceTo(locList[i + 1]) < 0.5 || !locList[i + 1].IsValid)
                    {
                        locList.RemoveAt(i + 1);
                        i--;
                    }
                }
                // Offset all points except origin and end to pass around obstacles by some distance.
                // We stop at 2.0 before each point in MovementManager and the meshes are done for a player of 0.6 in diameter.
                // So 2.0-0.6=1.4 is the strick minimum offset needed. Since 'click to point' has a precision of 0.5,
                // 1.4+0.5=1.9 is a pretty good value here.
                for (int i = locList.Count - 2; i > 0; i--)
                {
                    Point offset = Helpful.Math.GetPositionOffsetBy3DDistance(locList[i - 1], locList[i], 1.9f);
                    locList[i] = offset;
                }

                Logging.WriteNavigator("Path Count: " + locList.Count() + (resultSuccess ? "" : " but incomplete"));

                return(locList);
            }
            catch (Exception e)
            {
                Logging.WriteError("ToRecast(this Point v): PATH FIND ERROR: " + e);
                Console.WriteLine("Path find ERROR.");

                resultSuccess = false;
                locList       = new List <Point>();

                if (addFromAndStart)
                {
                    if (from != null)
                    {
                        if (from.X != 0 || from.Y != 0 || from.Z != 0)
                        {
                            locList.Add(from);
                        }
                    }

                    if (to != null)
                    {
                        if (to.X != 0 || to.Y != 0 || to.Z != 0)
                        {
                            locList.Add(to);
                        }
                    }
                }

                return(locList);
            }
        }
예제 #2
0
파일: Fight.cs 프로젝트: zneel/TheNoobBot
        public static UInt128 StartFight(UInt128 guid = default(UInt128))
        {
            MovementManager.StopMove();
            WoWUnit targetNpc = null;

            try
            {
                if (guid == 0)
                {
                    targetNpc =
                        new WoWUnit(
                            ObjectManager.ObjectManager.GetNearestWoWUnit(
                                ObjectManager.ObjectManager.GetHostileUnitAttackingPlayer()).GetBaseAddress);
                }
                else
                {
                    targetNpc =
                        new WoWUnit(ObjectManager.ObjectManager.GetObjectByGuid(guid).GetBaseAddress);
                }

                if (!targetNpc.Attackable)
                {
                    nManagerSetting.AddBlackList(targetNpc.Guid, 20000); // blacklist 20 sec
                }

                if (ObjectManager.ObjectManager.Me.IsMounted &&
                    (CombatClass.InAggroRange(targetNpc) || CombatClass.InRange(targetNpc)))
                {
                    MountTask.DismountMount();
                }

                InFight = true;

                if (!ObjectManager.ObjectManager.Me.IsCast)
                {
                    Interact.InteractWith(targetNpc.GetBaseAddress);
                }
                Thread.Sleep(100);
                if (ObjectManager.ObjectManager.Me.GetMove && !ObjectManager.ObjectManager.Me.IsCast)
                {
                    MovementManager.StopMoveTo();
                }

                Point positionStartTarget = targetNpc.Position;

                int timer = 0;
figthStart:
                // If pos start is very different
                if (targetNpc.Position.DistanceTo(positionStartTarget) > 50)
                {
                    return(0);
                }
                if (!targetNpc.Attackable)
                {
                    nManagerSetting.AddBlackList(targetNpc.Guid, 20000); // blacklist 20 sec
                    // Some become unattackable instead of being dead.
                    // Some will evade.
                }
                if (Usefuls.IsInBattleground && !Battleground.IsFinishBattleground())
                {
                    List <WoWUnit> tLUnit = ObjectManager.ObjectManager.GetHostileUnitAttackingPlayer();
                    if (tLUnit.Count > 0)
                    {
                        if (ObjectManager.ObjectManager.GetNearestWoWUnit(tLUnit).GetDistance < targetNpc.GetDistance &&
                            ObjectManager.ObjectManager.GetNearestWoWUnit(tLUnit).SummonedBy == 0)
                        {
                            return(0);
                        }
                    }
                }
                if ((ObjectManager.ObjectManager.Me.InCombat && !CombatClass.InRange(targetNpc)) || TraceLine.TraceLineGo(targetNpc.Position)) // If obstacle or not in range
                {
                    bool         resultSucces;
                    List <Point> points = PathFinder.FindPath(targetNpc.Position, out resultSucces);
                    if (!resultSucces && !Usefuls.IsFlying && MountTask.GetMountCapacity() >= MountCapacity.Fly)
                    {
                        MountTask.Mount(true, true);
                    }

                    // TODO: Code a FindTarget that includes CombatClass.GetRange here or we will often do wierd thing with casters.
                    MovementManager.Go(points);
                    timer = Others.Times + (int)(Math.DistanceListPoint(points) / 3 * 1000) + 15000;

                    while (!ObjectManager.ObjectManager.Me.IsDeadMe && !targetNpc.IsDead && targetNpc.Attackable && !targetNpc.IsLootable &&
                           targetNpc.Health > 0 && targetNpc.IsValid &&
                           MovementManager.InMovement && InFight && Usefuls.InGame &&
                           (TraceLine.TraceLineGo(targetNpc.Position) || !CombatClass.InAggroRange(targetNpc))
                           )
                    {
                        // Mob already in fight
                        if (targetNpc.Type != Enums.WoWObjectType.Player && !(targetNpc.IsTargetingMe || targetNpc.Target == 0 || ((WoWUnit)ObjectManager.ObjectManager.GetObjectByGuid(targetNpc.Target)).
                                                                              SummonedBy == ObjectManager.ObjectManager.Me.Guid || targetNpc.Target == ObjectManager.ObjectManager.Pet.Guid))
                        {
                            return(targetNpc.Guid);
                        }

                        // Timer
                        if (Others.Times > timer && TraceLine.TraceLineGo(targetNpc.Position))
                        {
                            return(targetNpc.Guid);
                        }

                        // Target Pos Verif
                        if (!targetNpc.Position.IsValid)
                        {
                            return(targetNpc.Guid);
                        }

                        // If pos start is very different
                        if (targetNpc.Position.DistanceTo(positionStartTarget) > 50)
                        {
                            return(0);
                        }

                        // Return if player/pet is attacked by another unit
                        if (ObjectManager.ObjectManager.GetNumberAttackPlayer() > 0 && !targetNpc.IsTargetingMe && !(targetNpc.Target == ObjectManager.ObjectManager.Pet.Guid && targetNpc.Target > 0))
                        {
                            return(0);
                        }
                        Thread.Sleep(50);
                    }
                }
                timer = Others.Times + (int)(ObjectManager.ObjectManager.Me.Position.DistanceTo(targetNpc.Position) / 3 * 1000) + 5000;
                if (MovementManager.InMovement)
                {
                    MovementManager.StopMove();
                }

                if (!ObjectManager.ObjectManager.Me.IsCast && ObjectManager.ObjectManager.Me.Target != targetNpc.Guid)
                {
                    Interact.InteractWith(targetNpc.GetBaseAddress);
                }

                InFight = true;
                Thread.Sleep(200);
                if (CombatClass.InAggroRange(targetNpc))
                {
                    if (ObjectManager.ObjectManager.Me.GetMove && !ObjectManager.ObjectManager.Me.IsCast)
                    {
                        MovementManager.StopMoveTo();
                    }
                    if (!ObjectManager.ObjectManager.Me.GetMove && ObjectManager.ObjectManager.Me.IsMounted)
                    {
                        MountTask.DismountMount();
                    }
                }

                // If target died after only 0.2sec of fight, let's find a new target.
                if (targetNpc.IsDead || !targetNpc.IsValid || targetNpc.Attackable)
                {
                    WoWUnit newTargetNpc = new WoWUnit(ObjectManager.ObjectManager.GetNearestWoWUnit(ObjectManager.ObjectManager.GetHostileUnitAttackingPlayer()).GetBaseAddress);
                    if (newTargetNpc.IsValid && !ObjectManager.ObjectManager.Me.IsCast && ObjectManager.ObjectManager.Me.Target != newTargetNpc.Guid)
                    {
                        targetNpc = newTargetNpc;
                        Interact.InteractWith(targetNpc.GetBaseAddress);
                        // Face the new target
                        MovementManager.Face(targetNpc);
                    }
                }

                while (!ObjectManager.ObjectManager.Me.IsDeadMe && !targetNpc.IsDead && targetNpc.Attackable && targetNpc.IsValid && InFight &&
                       targetNpc.IsValid && !ObjectManager.ObjectManager.Me.InTransport)
                {
                    // Return if player attacked and this target not attack player
                    if (targetNpc.Type != Enums.WoWObjectType.Player && !targetNpc.IsTargetingMe && !(targetNpc.Target == ObjectManager.ObjectManager.Pet.Guid && targetNpc.Target > 0) &&
                        ObjectManager.ObjectManager.GetNumberAttackPlayer() > 0)
                    {
                        return(0);
                    }

                    // Cancel fight if the mob was tapped by another player
                    if (targetNpc.IsTapped)
                    {
                        return(0);
                    }

                    // Target Pos Verif
                    if (!targetNpc.Position.IsValid)
                    {
                        InFight = false;
                        return(targetNpc.Guid);
                    }

                    // Target mob if not target
                    if (ObjectManager.ObjectManager.Me.Target != targetNpc.Guid && !targetNpc.IsDead && !ObjectManager.ObjectManager.Me.IsCast)
                    {
                        Interact.InteractWith(targetNpc.GetBaseAddress);
                    }

                    // Move to target if out of range
                    if (!ObjectManager.ObjectManager.Me.IsCast &&
                        ((!ObjectManager.ObjectManager.Me.InCombat && !CombatClass.InAggroRange(targetNpc)) ||
                         ((ObjectManager.ObjectManager.Me.InCombat && !CombatClass.InRange(targetNpc)))))
                    {
                        int rJump = Others.Random(1, 20);
                        MovementManager.MoveTo(targetNpc);
                        if (rJump == 5)
                        {
                            MovementsAction.Jump();
                        }
                    }
                    // Create path if the mob is out of sight or out of range
                    if ((!CombatClass.InRange(targetNpc) && !ObjectManager.ObjectManager.Me.IsCast) ||
                        TraceLine.TraceLineGo(targetNpc.Position))
                    {
                        goto figthStart;
                    }
                    // Stop move if in range
                    if (CombatClass.InRange(targetNpc) && ObjectManager.ObjectManager.Me.GetMove &&
                        !ObjectManager.ObjectManager.Me.IsCast)
                    {
                        MovementManager.StopMoveTo();
                    }
                    if (ObjectManager.ObjectManager.Me.IsMounted)
                    {
                        MountTask.DismountMount();
                        Interact.InteractWith(targetNpc.GetBaseAddress);
                    }

                    // Face player to mob
                    MovementManager.Face(targetNpc);

                    // If obstacle between us and the target after this timer expires then stop the fight and blacklist
                    if (Others.Times > timer && TraceLine.TraceLineGo(targetNpc.Position) &&
                        targetNpc.HealthPercent > 90)
                    {
                        InFight = false;
                        return(targetNpc.Guid);
                    }

                    Thread.Sleep(75 + Usefuls.Latency);

                    // If timer expires and still not in fight, then stop the fight and blacklist
                    if (Others.Times > timer && !ObjectManager.ObjectManager.Me.InCombat && !targetNpc.IsDead)
                    {
                        InFight = false;
                        return(targetNpc.Guid);
                    }
                }

                MovementManager.StopMoveTo();
                InFight = false;
            }
            catch (Exception exception)
            {
                Logging.WriteError("StartFight(UInt128 guid = 0, bool inBg = false): " + exception);
                InFight = false;
            }
            try
            {
                if (targetNpc != null)
                {
                    return(targetNpc.Guid);
                }
            }
            catch
            {
                return(0);
            }
            return(0);
        }
예제 #3
0
        public static void LongMoveGo(Point point)
        {
            try
            {
                //MovementManager.StopMove();
                int timer = Others.Times;

                if (_used)
                {
                    _used = false;
                    while (_usedLoop)
                    {
                        Thread.Sleep(5);
                    }
                }
                _used     = true;
                _usedLoop = true;

                //MovementManager.StopMove();
                MountTask.Mount(false, true);

                Point pTemps = ObjectManager.ObjectManager.Me.Position;

                Timer timerSit         = new Timer(2500);
                bool  flyingPathFinder = false;

                while (Products.Products.IsStarted && (ObjectManager.ObjectManager.Me.IsMounted || MountTask.GetMountCapacity() == MountCapacity.Feet) &&
                       ObjectManager.ObjectManager.Me.Position.DistanceTo(point) > 3.5f && _used && _usedLoop)
                {
                    bool forceGround = false;
                    if (Usefuls.IsFlying)
                    {
                        Point pos = ObjectManager.ObjectManager.Me.Position;
                        if (point.DistanceTo2D(pos) <= 60 || flyingPathFinder && point.DistanceTo2D(pos) <= 110)
                        {
                            Point p           = new Point(ObjectManager.ObjectManager.Me.Position.LerpByDistance(point, 3f));
                            bool  failed      = false;
                            Point targetPoint = new Point();
                            if (p.IsValid && TraceLine.TraceLineGo(ObjectManager.ObjectManager.Me.Position, p, CGWorldFrameHitFlags.HitTestAllButLiquid))
                            {
                                if ((point.DistanceTo2D(pos) <= 60 || flyingPathFinder && point.DistanceTo2D(pos) <= 110))
                                {
                                    float degree     = 0f;
                                    bool  doContinue = false;
                                    try
                                    {
                                        LongMoveIsLanding = true;
                                        while (degree < 360)
                                        {
                                            var   rnd         = new Random();
                                            float radius      = rnd.Next(25, 50);
                                            float x           = (float)(pos.X + radius * System.Math.Cos(Math.DegreeToRadian(degree)));
                                            float y           = (float)(pos.Y + radius * System.Math.Sin(Math.DegreeToRadian(degree)));
                                            Point topPoint    = new Point(x, y, pos.Z);
                                            Point bottomPoint = new Point(x, y, PathFinder.GetZPosition(x, y));
                                            if (!TraceLine.TraceLineGo(topPoint, new Point(topPoint.LerpByDistance(point, 3f)), CGWorldFrameHitFlags.HitTestAllButLiquid))
                                            {
                                                targetPoint = topPoint;
                                                MovementManager.MoveTo(targetPoint);
                                                Thread.Sleep(2500);
                                                flyingPathFinder = true;
                                                doContinue       = true;
                                                break;
                                                // we want to go to topPoint and directly go to point.
                                            }
                                            else if (!TraceLine.TraceLineGo(topPoint, bottomPoint, CGWorldFrameHitFlags.HitTestAllButLiquid))
                                            {
                                                bool success;
                                                PathFinder.FindPath(bottomPoint, point, Usefuls.ContinentNameMpq, out success);
                                                if (success)
                                                {
                                                    targetPoint = topPoint;
                                                    MovementManager.MoveTo(targetPoint);
                                                    Thread.Sleep(2500);
                                                    flyingPathFinder = true;
                                                    break;
                                                    // we want to go to topPoint then dismount down to bottomPoint, then findPath to target.
                                                }
                                            }

                                            float randomDegree = rnd.Next(20, 30);
                                            degree += randomDegree;
                                            if (degree >= 360f)
                                            {
                                                failed = true;
                                            }
                                        }
                                    }
                                    finally
                                    {
                                        LongMoveIsLanding = false;
                                    }
                                    if (doContinue)
                                    {
                                        Thread.Sleep(1000);
                                        continue;
                                    }
                                }
                                if (!failed)
                                {
                                    if (ObjectManager.ObjectManager.Me.Position.DistanceTo(targetPoint) > 5f)
                                    {
                                        Thread.Sleep(2500);
                                    }
                                    if (ObjectManager.ObjectManager.Me.Position.DistanceTo(targetPoint) > 5f)
                                    {
                                        continue;
                                    }
                                    MountTask.DismountMount();
                                    _used     = false;
                                    _usedLoop = false;
                                    return;
                                }
                            }
                            else
                            {
                                MovementManager.MoveTo(p);
                                flyingPathFinder = false;
                            }
                        }
                    }
                    if (MountTask.GetMountCapacity() <= MountCapacity.Ground || forceGround)
                    {
                        if (RegenPath.IsReady && ObjectManager.ObjectManager.Me.Position.DistanceTo(point) > 3.5f)
                        {
                            RegenPath = new Timer(1000 * 60);
                            List <Point> getFullPath = PathFinder.FindPath(point);
                            MovementManager.Go(getFullPath);
                            RegenPath.Reset();
                        }
                        else
                        {
                            Thread.Sleep(1000);
                        }
                    }
                    else
                    {
                        if (!MovementManager.IsUnStuck)
                        {
                            if (ObjectManager.ObjectManager.Me.IsDeadMe)
                            {
                                return;
                            }
                            const int checkInFront   = 130; // was 100
                            const int checkCollision = 60;  // was 40
                            if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(point) > 15)
                            {
                                Point meTemps = ObjectManager.ObjectManager.Me.Position;
                                meTemps.Z = meTemps.Z - 2;

                                Point temps = new Point(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z - 2.5f);
                                if (point.DistanceTo(ObjectManager.ObjectManager.Me.Position) > checkInFront)
                                {
                                    temps = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position, point,
                                                                               checkInFront);
                                    temps.Z = ObjectManager.ObjectManager.Me.Position.Z - 2.5f;
                                }
                                if (TraceLine.TraceLineGo(meTemps, temps) ||
                                    (ObjectManager.ObjectManager.Me.Position.Z + 10 < point.Z &&
                                     point.DistanceTo2D(ObjectManager.ObjectManager.Me.Position) < 100))
                                {
                                    MovementsAction.Descend(false);
                                    MovementsAction.Ascend(true);
                                    timerSit = new Timer(1000);
                                    // If distance to colission < checkCollision stop moveto
                                    temps = new Point(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z - 2.5f);
                                    if (point.DistanceTo(ObjectManager.ObjectManager.Me.Position) > checkInFront)
                                    {
                                        temps = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position,
                                                                                   point, checkCollision);
                                        temps.Z = ObjectManager.ObjectManager.Me.Position.Z - 2.5f;
                                    }
                                    if (TraceLine.TraceLineGo(meTemps, temps))
                                    {
                                        MovementManager.StopMoveTo(false);
                                    }
                                    // End Stop move to
                                    Thread.Sleep(800);
                                    if (pTemps.DistanceTo(ObjectManager.ObjectManager.Me.Position) < 1f)
                                    {
                                        MovementManager.UnStuckFly();
                                    }
                                    else
                                    {
                                        pTemps = ObjectManager.ObjectManager.Me.Position;
                                    }
                                }
                                else
                                {
                                    MovementsAction.Ascend(false);

                                    if (timerSit.IsReady)
                                    {
                                        // If distance to ground > 100
                                        temps = new Point(ObjectManager.ObjectManager.Me.Position.X,
                                                          ObjectManager.ObjectManager.Me.Position.Y,
                                                          ObjectManager.ObjectManager.Me.Position.Z - altitude);
                                        Point tempsMe = new Point(ObjectManager.ObjectManager.Me.Position.X,
                                                                  ObjectManager.ObjectManager.Me.Position.Y,
                                                                  ObjectManager.ObjectManager.Me.Position.Z + 5f);
                                        Point temps2 = Math.GetPosition2DOfLineByDistance(tempsMe, point, 80);
                                        temps2.Z = ObjectManager.ObjectManager.Me.Position.Z - altitude;
                                        if (!TraceLine.TraceLineGo(tempsMe, temps))
                                        {
                                            if (!TraceLine.TraceLineGo(tempsMe, temps2))
                                            {
                                                MovementsAction.Descend(true);
                                            }
                                            else
                                            {
                                                timerSit = new Timer(1000);
                                                MovementsAction.Descend(false);
                                            }
                                        }
                                        else
                                        {
                                            timerSit = new Timer(1000);
                                            MovementsAction.Descend(false);
                                        }
                                        // End Stop move ground
                                    }
                                    MovementManager.MoveTo(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z);
                                    if (Others.Times > (timer + 1500))
                                    {
                                        MovementManager.MoveTo(point.X, point.Y, ObjectManager.ObjectManager.Me.Position.Z);
                                        timer = Others.Times;
                                    }
                                }
                            }
                            else
                            {
                                MovementsAction.Descend(false);
                                MovementsAction.Ascend(false);

                                if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(point) <= 5f && ObjectManager.ObjectManager.Me.Position.DistanceZ(point) > 2f)
                                {
                                    MovementsAction.Descend(false);
                                    MovementsAction.Ascend(false);
                                    MovementManager.StopMove();
                                    MovementManager.StopMove();
                                    MountTask.Land();
                                }
                                else
                                {
                                    MovementManager.MoveTo(point);
                                }
                            }
                        }

                        if (ObjectManager.ObjectManager.Me.IsMounted && !Usefuls.IsFlying)
                        {
                            MovementsAction.Descend(false);
                            MovementsAction.Ascend(false);
                            MountTask.Mount(false, true);
                            MovementsAction.Ascend(true);
                            Thread.Sleep(1300);
                            MovementsAction.Ascend(false);
                        }
                    }
                    Thread.Sleep(150); //50
                }
                MovementsAction.Descend(false);
                MovementsAction.Ascend(false);
                _used     = false;
                _usedLoop = false;
                RegenPath.ForceReady();
            }
            catch (Exception exception)
            {
                MovementsAction.Descend(false);
                MovementsAction.Ascend(false);
                Logging.WriteError("LongMove > LongMoveGo(Point point): " + exception);
                _used     = false;
                _usedLoop = false;
                RegenPath.ForceReady();
            }
        }
예제 #4
0
        /// <summary>
        /// Find a point around the fishing hole from where we can land to fish
        /// </summary>
        /// <typeparam></typeparam>
        /// <param></param>
        /// <param name="fishingHole"> </param>
        /// <returns name="TheBestPoint"></returns>
        public static Point FindTheUltimatePoint(Point fishingHole)
        {
            const float MinRing = 13.0f; //13
            const float MaxRing = 20.0f; //19

            const CGWorldFrameHitFlags hitFlags = CGWorldFrameHitFlags.HitTestBoundingModels |
                                                  CGWorldFrameHitFlags.HitTestWMO |
                                                  CGWorldFrameHitFlags.HitTestUnknown |
                                                  CGWorldFrameHitFlags.HitTestGround;

            for (float diameter = MinRing; diameter <= MaxRing; diameter = diameter + 3.0f)
            {
                for (double angle = 0; angle <= System.Math.PI / 2; angle = angle + System.Math.PI / 10)
                {
                    float offset1 = diameter * (float)System.Math.Sin(angle);
                    float offset2 = diameter * (float)System.Math.Cos(angle);
                    Point to      = new Point(fishingHole.X + offset1, fishingHole.Y - offset2, fishingHole.Z);
                    to.Z = to.Z - 0.8f;
                    Point from = new Point(to)
                    {
                        Z = fishingHole.Z + 20.0f
                    };
                    bool res = TraceLine.TraceLineGo(@from, to, hitFlags);
                    if (res)
                    {
                        float nz = PathFinder.GetZPosition(to);
                        if (nz == 0)
                        {
                            continue;
                        }
                        to.Z = nz + 1.0f;
                        return(to);
                    }

                    to   = new Point(fishingHole.X + offset2, fishingHole.Y + offset1, fishingHole.Z);
                    to.Z = to.Z - 1.0f;
                    from = new Point(to)
                    {
                        Z = fishingHole.Z + 20.0f
                    };
                    res = TraceLine.TraceLineGo(from, to, hitFlags);
                    if (res)
                    {
                        float nz = PathFinder.GetZPosition(to);
                        if (nz == 0)
                        {
                            continue;
                        }
                        to.Z = nz + 1.0f;
                        return(to);
                    }
                    to   = new Point(fishingHole.X - offset1, fishingHole.Y + offset2, fishingHole.Z);
                    to.Z = to.Z - 1.0f;
                    from = new Point(to)
                    {
                        Z = fishingHole.Z + 20.0f
                    };
                    res = TraceLine.TraceLineGo(from, to, hitFlags);
                    if (res)
                    {
                        float nz = PathFinder.GetZPosition(to);
                        if (nz == 0)
                        {
                            continue;
                        }
                        to.Z = nz + 1.0f;
                        return(to);
                    }
                    to   = new Point(fishingHole.X - offset2, fishingHole.Y - offset1, fishingHole.Z);
                    to.Z = to.Z - 1.0f;
                    from = new Point(to)
                    {
                        Z = fishingHole.Z + 20.0f
                    };
                    res = TraceLine.TraceLineGo(from, to, hitFlags);
                    if (res)
                    {
                        float nz = PathFinder.GetZPosition(to);
                        if (nz == 0)
                        {
                            continue;
                        }
                        to.Z = nz + 1.0f;
                        return(to);
                    }
                }
            }

            Point pt = new Point(0, 0, 0, "invalid");

            return(pt);
        }