Esempio n. 1
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();
            }
        }
Esempio n. 2
0
        private static void Fly(IEnumerable <WoWGameObject> nodes, bool ignoreCanOpen = false)
        {
            try
            {
                nodes = nodes.OrderBy(x => x.GetDistance);
                foreach (WoWGameObject node in nodes.Where(node => node.IsValid))
                {
                    WoWGameObject inode = node;
                    if (_curNode != null && _curNode.IsValid && !nManagerSetting.IsBlackListed(_curNode.Guid))
                    {
                        inode = _curNode;
                    }
                    if (!inode.IsValid)
                    {
                        MovementManager.StopMove();
                        nManagerSetting.AddBlackList(inode.Guid, 2 * 60 * 1000);
                        Logging.Write("Current inode not valid, blacklist.");
                        continue;
                    }
                    _curNode = inode; // we save a inode we potentially bypassed to make sure we run the list.
                    if (!inode.CanOpen && !ignoreCanOpen)
                    {
                        nManagerSetting.AddBlackList(inode.Guid, 5000);
                        return;
                    }
                    float zT;
                    if (ObjectManager.ObjectManager.Me.Position.Z < inode.Position.Z)
                    {
                        zT = inode.Position.Z + 5.5f;
                    }
                    else
                    {
                        zT = inode.Position.Z + 2.5f;
                    }

                    Point aboveNode = new Point(inode.Position);
                    aboveNode.Z = aboveNode.Z + 2.5f;
                    Point farAboveNode = new Point(aboveNode);
                    farAboveNode.Z = farAboveNode.Z + 50;
                    if (TraceLine.TraceLineGo(farAboveNode, aboveNode, CGWorldFrameHitFlags.HitTestAllButLiquid))
                    {
                        MovementManager.StopMove();
                        if (TraceLine.TraceLineGo(ObjectManager.ObjectManager.Me.Position, aboveNode, CGWorldFrameHitFlags.HitTestAllButLiquid))
                        {
                            Logging.Write("Node stuck");
                            nManagerSetting.AddBlackList(inode.Guid, 1000 * 60 * 2);
                            return;
                        }
                    }
                    else
                    {
                        MovementManager.StopMove();
                    }
                    if (_lastnode != inode.Guid)
                    {
                        _lastnode = inode.Guid;
                        Logging.Write("Farm " + inode.Name + " (" + inode.Entry + ") > " + inode.Position);
                    }
                    MovementManager.MoveTo(inode.Position.X, inode.Position.Y, zT, true);

                    Helpful.Timer timer   = new Helpful.Timer((int)(ObjectManager.ObjectManager.Me.Position.DistanceTo(inode.Position) / 3 * 1000) + 5000);
                    bool          toMine  = false;
                    bool          landing = false;

                    while (inode.IsValid && !Usefuls.BadBottingConditions && !Usefuls.ShouldFight && !timer.IsReady)
                    {
                        if (!landing)
                        {
                            bool noDirectPath = TraceLine.TraceLineGo(aboveNode, ObjectManager.ObjectManager.Me.Position, CGWorldFrameHitFlags.HitTestAllButLiquid);
                            zT = noDirectPath ? ObjectManager.ObjectManager.Me.Position.Z : aboveNode.Z;

                            if (ObjectManager.ObjectManager.Me.Position.Z < aboveNode.Z)
                            {
                                // elevate in a 45° angle instead of 90°
                                Point direction = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position,
                                                                                     inode.Position,
                                                                                     (inode.Position.Z + 2.5f) - ObjectManager.ObjectManager.Me.Position.Z);
                                // if there is an obstacle, then go mostly vertical but not 90° to prevent spinning around
                                if (TraceLine.TraceLineGo(ObjectManager.ObjectManager.Me.Position,
                                                          direction,
                                                          CGWorldFrameHitFlags.HitTestAllButLiquid))
                                {
                                    direction = Math.GetPosition2DOfLineByDistance(ObjectManager.ObjectManager.Me.Position,
                                                                                   inode.Position, 1.0f);
                                }
                                MovementManager.MoveTo(direction.X, direction.Y, inode.Position.Z + 5.0f);
                            }
                            else
                            {
                                MovementManager.MoveTo(inode.Position.X, inode.Position.Y, zT);
                            }

                            if (!ObjectManager.ObjectManager.Me.IsMounted)
                            {
                                return;
                            }
                            if (!noDirectPath)
                            {
                                landing = true;
                            }
                        }

                        if (ObjectManager.ObjectManager.Me.Position.DistanceTo2D(inode.Position) < 4.0f &&
                            ObjectManager.ObjectManager.Me.Position.DistanceZ(inode.Position) >= 5.0f && !toMine)
                        {
                            toMine = true;

                            if (!ObjectManager.ObjectManager.Me.IsMounted)
                            {
                                return;
                            }
                            zT = inode.Position.Z + 1.5f;
                            MovementManager.MoveTo(inode.Position.X, inode.Position.Y, zT);
                            if (inode.GetDistance > 3.0f && TraceLine.TraceLineGo(ObjectManager.ObjectManager.Me.Position, inode.Position, CGWorldFrameHitFlags.HitTestAllButLiquid))
                            {
                                Logging.Write("Node outside view");
                                nManagerSetting.AddBlackList(inode.Guid, 1000 * 120);
                                break;
                            }
                        }
                        else if ((ObjectManager.ObjectManager.Me.Position.DistanceTo2D(inode.Position) < 1.1f ||
                                  (!Usefuls.IsFlying &&
                                   ObjectManager.ObjectManager.Me.Position.DistanceTo2D(inode.Position) < 3.0f)) &&
                                 ObjectManager.ObjectManager.Me.Position.DistanceZ(inode.Position) < 6)
                        {
                            Thread.Sleep(150);
                            MovementManager.StopMove();
                            if (Usefuls.IsFlying)
                            {
                                MountTask.Land();
                            }
                            if (ObjectManager.ObjectManager.Me.GetMove)
                            {
                                MovementManager.StopMove();
                            }
                            while (ObjectManager.ObjectManager.Me.GetMove)
                            {
                                Thread.Sleep(50);
                            }
                            if (!ObjectManager.ObjectManager.Me.HaveBuff(SpellManager.AllInteractMountId()) &&
                                (!inode.IsHerb || inode.IsHerb && !ObjectManager.ObjectManager.Me.HaveBuff(SpellManager.HerbsInteractMountId())))
                            {
                                if (!(SpellManager.HasSpell(169606) && Usefuls.ContinentId == 1116 || Usefuls.ContinentId == 1464)) // Passive Silver Dollar Club given by Stables.
                                {
                                    MountTask.DismountMount();
                                }
                            }
                            else if (inode.IsHerb && ObjectManager.ObjectManager.Me.HaveBuff(SpellManager.DruidMountId()))
                            {
                                Logging.WriteDebug("Druid IsFlying ? " + Usefuls.IsFlying);
                                if (Usefuls.IsFlying)
                                {
                                    MountTask.Land();
                                    MovementManager.StopMove();
                                    if (Usefuls.IsFlying)
                                    {
                                        Logging.Write("You are still flying after two attemps of Landing.");
                                        Logging.Write("Make sure you have binded the action \"SitOrStand\" on a keyboard key and not any mouse button or special button.");
                                        Logging.Write("If you still have this message, please try a \"Reset Keybindings\" before posting on the forum.");
                                        Logging.Write("A work arround have been used, it may let you actually farm or not. Because it's random, please fix your keybinding issue.");
                                        MountTask.Land(true);
                                    }
                                }
                            }

                            Thread.Sleep(Usefuls.Latency + 200);
                            if (ObjectManager.ObjectManager.Me.InInevitableCombat)
                            {
                                MountTask.DismountMount();
                                return;
                            }
                            _wasLooted    = false;
                            CountThisLoot = true;
                            NodeOrUnit    = true;
                            Interact.InteractWith(inode.GetBaseAddress);
                            Thread.Sleep(Usefuls.Latency + 500);
                            if (!ObjectManager.ObjectManager.Me.IsCast)
                            {
                                Interact.InteractWith(inode.GetBaseAddress);
                                Thread.Sleep(Usefuls.Latency + 500);
                            }
                            while (ObjectManager.ObjectManager.Me.IsCast)
                            {
                                Thread.Sleep(100);
                            }
                            if (ObjectManager.ObjectManager.Me.InInevitableCombat)
                            {
                                MountTask.DismountMount();
                                CountThisLoot = false;
                                return;
                            }
                            Thread.Sleep(Usefuls.Latency + 100);
                            if (ObjectManager.ObjectManager.Me.InInevitableCombat)
                            {
                                MountTask.DismountMount();
                                CountThisLoot = false;
                                return;
                            }
                            nManagerSetting.AddBlackList(inode.Guid, 1000 * 20);
                            return;
                        }
                        else if (!ObjectManager.ObjectManager.Me.GetMove)
                        {
                            Thread.Sleep(50);
                            if (!ObjectManager.ObjectManager.Me.IsMounted)
                            {
                                return;
                            }
                            MovementManager.MoveTo(inode.Position.X, inode.Position.Y, zT);
                        }
                        if (States.Farming.PlayerNearest(inode))
                        {
                            Logging.Write("Player near the inode, farm canceled");
                            nManagerSetting.AddBlackList(inode.Guid, 15 * 1000);
                            return;
                        }
                    }
                    if (timer.IsReady)
                    {
                        nManagerSetting.AddBlackList(inode.Guid, 60 * 1000);
                    }
                    MovementManager.StopMove();
                    if (!_wasLooted)
                    {
                        Logging.Write("Farm failed #1");
                    }
                }
            }
            catch (Exception ex)
            {
                Logging.WriteError("FarmingTask > Fly(IEnumerable<WoWGameObject> nodes): " + ex);
            }
        }