Exemple #1
0
        public override void Run()
        {
            if (!Products.IsStarted || ObjectManager.Me.IsDeadMe || ObjectManager.Me.InCombatBlizzard)
            {
                return;
            }
            if (!FisherbotSetting.CurrentSetting.FishSchool)
            {
                if (_firstRun && FishingTask.IsLaunched)
                {
                    _firstRun = false;
                }
                // If we have a saved position and we don't fish, then go to position
                if (FisherbotSetting.CurrentSetting.FisherbotPosition.IsValid && (!FishingTask.IsLaunched || _beenFighting) && !_firstRun)
                {
                    _beenFighting = false;
                    if (ObjectManager.Me.Position.DistanceTo(FisherbotSetting.CurrentSetting.FisherbotPosition) > 5)
                    {
                        LongMove.LongMoveGo(FisherbotSetting.CurrentSetting.FisherbotPosition);
                    }
                    else if (ObjectManager.Me.Position.DistanceTo(FisherbotSetting.CurrentSetting.FisherbotPosition) > 1.5f)
                    {
                        MovementManager.MoveTo(FisherbotSetting.CurrentSetting.FisherbotPosition);
                    }
                    MovementManager.Face(FisherbotSetting.CurrentSetting.FisherbotRotation);
                }
                // If we don't fish or the timer is null, then start a new timer, save position and fish
                if (timer == null || !FishingTask.IsLaunched)
                {
                    timer = new nManager.Helpful.Timer(10 * 60 * 1000 + 10 * 1000);
                    FisherbotSetting.CurrentSetting.FisherbotPosition = ObjectManager.Me.Position;
                    FisherbotSetting.CurrentSetting.FisherbotRotation = ObjectManager.Me.Rotation;
                    Fishing.EquipFishingPoles(FisherbotSetting.CurrentSetting.FishingPoleName);
                    FishingTask.LoopFish(0, FisherbotSetting.CurrentSetting.UseLure, FisherbotSetting.CurrentSetting.LureName, FisherbotSetting.CurrentSetting.FishingPoleName, false,
                                         FisherbotSetting.AutomaticallyUseDraenorSecondaryBait);
                }
                // If the timer ended, stop fishing, equip weapon, null the timer
                else if (timer.IsReady)
                {
                    FishingTask.StopLoopFish();
                    ItemsManager.EquipItemByName(FisherbotSetting.CurrentSetting.WeaponName);
                    if (!string.IsNullOrEmpty(FisherbotSetting.CurrentSetting.ShieldName))
                    {
                        ItemsManager.EquipItemByName(FisherbotSetting.CurrentSetting.ShieldName);
                    }

                    timer = null;
                }
                // We are in timer, we fish, then save the position
                else
                {
                    if (FishingTask._lastSuccessfullFishing > Environment.TickCount - 5000)
                    {
                        FisherbotSetting.CurrentSetting.FisherbotPosition = ObjectManager.Me.Position;
                        FisherbotSetting.CurrentSetting.FisherbotRotation = ObjectManager.Me.Rotation;
                        // We successfully fished in the last 5 seconds, let's record our position again.
                    }
                    if (FishingTask._lastSuccessfullFishing != 0 && FishingTask._lastSuccessfullFishing < Environment.TickCount - 25000)
                    {
                        // We did not catch a single thing in the last 25 seconds...
                        FishingTask.StopLoopFish();
                        return;
                    }
                    // _lastSuccessfullFishing is fine or we never fished yet, let it load :)
                    Thread.Sleep(500);
                }
                // No more while, we test what we need and return
                return;
            }

            // Nodes fishing code
            if (_node.IsValid)
            {
                FisherbotSetting.CurrentSetting.FisherbotPosition =
                    Bot.Profile.Points[Math.NearestPointOfListPoints(Bot.Profile.Points, _node.Position)];
                Logging.Write("Fish " + _node.Name + " > " + _node.Position);
            }

            if (FisherbotSetting.CurrentSetting.FishSchool)
            {
                Point whereToGo = Fishing.FindTheUltimatePoint(_node.Position);
                if (whereToGo.Type == "invalid")
                {
                    Logging.Write("No valid point found");
                    nManagerSetting.AddBlackList(_node.Guid);
                    return;
                }
                bool         r;
                List <Point> points = PathFinder.FindPath(whereToGo, out r);
                if (points.Count <= 1 || points.Count >= 20)
                {
                    points.Clear();
                    points.Add(ObjectManager.Me.Position);
                    points.Add(whereToGo);
                }
                else
                {
                    for (int i = 0; i < points.Count; i++)
                    {
                        if (points[i].Z < whereToGo.Z)
                        {
                            points[i].Z = whereToGo.Z;
                        }
                    }
                }
                Logging.Write("Going to point > " + whereToGo.X + " ; " + whereToGo.Y + " ; " + whereToGo.Z + " ; " +
                              points[0].Type);
                MovementManager.Go(points);

                timer = new nManager.Helpful.Timer(((int)Math.DistanceListPoint(points) / 3 * 1000) + 4000);
                while ((_node.IsValid || !FisherbotSetting.CurrentSetting.FishSchool) && Products.IsStarted &&
                       !ObjectManager.Me.IsDeadMe &&
                       !ObjectManager.Me.InInevitableCombat &&
                       !timer.IsReady && MovementManager.InMovement)
                {
                    if (ObjectManager.Me.Position.DistanceTo2D(whereToGo) <= 0.2f)
                    {
                        MovementManager.StopMove();
                        break;
                    }
                    Thread.Sleep(50);
                }

                if (timer.IsReady && _node.GetDistance2D > DistanceMax)
                {
                    Logging.Write("Fishing failed - No nearby point found (distance near position = " +
                                  ObjectManager.Me.Position.DistanceTo2D(
                                      FisherbotSetting.CurrentSetting.FisherbotPosition).ToString(CultureInfo.InvariantCulture) + ")");
                    MovementManager.StopMove();
                    nManagerSetting.AddBlackList(_node.Guid);
                    return;
                }
            }

            // Stop move
            MovementManager.StopMove();
            MountTask.DismountMount();

            // Face
            if (_node.IsValid)
            {
                MovementManager.Face(_node);
            }
            else
            {
                MovementManager.Face(FisherbotSetting.CurrentSetting.FisherbotRotation);
            }

            // Ce met a la bonne distance du banc de poisson
            if (_node.IsValid)
            {
                int nbIsSwimming = 0;
                timer = new nManager.Helpful.Timer(1000 * 8);
                while ((Usefuls.IsSwimming || _node.GetDistance > DistanceMax || _node.GetDistance < DistanceMin) &&
                       Products.IsStarted && !ObjectManager.Me.IsDeadMe && !ObjectManager.Me.InCombat && !timer.IsReady)
                {
                    if (nbIsSwimming * 100 > TimeTryFindGoodPos)
                    {
                        FishingTask.StopLoopFish();
                        MovementsAction.MoveBackward(false);
                        MovementsAction.MoveForward(false);
                        Logging.Write("BlackList " + _node.Name);
                        nManagerSetting.AddBlackList(_node.Guid);
                        return;
                    }
                    FishingTask.StopLoopFish();
                    MovementManager.Face(_node);

                    if (Usefuls.IsSwimming || _node.GetDistance < DistanceMin)
                    {
                        MovementsAction.MoveForward(false);
                        MovementsAction.MoveBackward(true);
                    }
                    if (_node.GetDistance > DistanceMax)
                    {
                        MovementsAction.MoveBackward(false);
                        MovementsAction.MoveForward(true);
                    }

                    nbIsSwimming++;
                    Thread.Sleep(100);
                }
                MovementsAction.MoveBackward(false);
                MovementsAction.MoveForward(false);
                if (timer.IsReady)
                {
                    Logging.Write("Fishing failed - Out of range" + timer.IsReady.ToString());
                    MovementManager.StopMove();
                    nManagerSetting.AddBlackList(_node.Guid);
                    return;
                }
            }

            // Fish
            Fishing.EquipFishingPoles(FisherbotSetting.CurrentSetting.FishingPoleName);
            FishingTask.LoopFish(_node.Guid, FisherbotSetting.CurrentSetting.UseLure, FisherbotSetting.CurrentSetting.LureName, FisherbotSetting.CurrentSetting.FishingPoleName,
                                 FisherbotSetting.CurrentSetting.PrecisionMode, FisherbotSetting.AutomaticallyUseDraenorSecondaryBait);

            timer = new nManager.Helpful.Timer(2 * 60 * 1000);
            while ((_node.IsValid || !FisherbotSetting.CurrentSetting.FishSchool) && Products.IsStarted &&
                   !ObjectManager.Me.IsDeadMe &&
                   !ObjectManager.Me.InCombat && !timer.IsReady &&
                   FishingTask.IsLaunched)
            {
                if (ObjectManager.Me.Position.DistanceTo2D(FisherbotSetting.CurrentSetting.FisherbotPosition) > 3.5f &&
                    !FisherbotSetting.CurrentSetting.FishSchool)
                {
                    break;
                }
                Thread.Sleep(300);
            }
            FishingTask.StopLoopFish();
            ItemsManager.EquipItemByName(FisherbotSetting.CurrentSetting.WeaponName);
            if (!string.IsNullOrEmpty(FisherbotSetting.CurrentSetting.ShieldName))
            {
                ItemsManager.EquipItemByName(FisherbotSetting.CurrentSetting.ShieldName);
            }
        }
Exemple #2
0
        public override void Run()
        {
            if (MovementManager.InMovement)
            {
                return;
            }
            // Now configure if not already done
            if (tList == null)
            {
                // Fill the task list
                tList = new Stack <Task>();
                tList.Push(Task.CheckGarrisonRessourceCache);
                if (Garrison.GetGarrisonLevel() > 1)
                {
                    tList.Push(Task.MineWorkOrder);
                    tList.Push(Task.GatherMinerals);
                    tList.Push(Task.GardenWorkOrder);
                    tList.Push(Task.GatherHerbs);
                }
                tList.Push(Task.GoToGarrison);
                // And fill the variables
                _cacheGarrison = new List <int> {
                    237722, 236916, 237191, 237724, 237720, 237723
                };
                if (ObjMgr.Me.PlayerFaction == "Alliance")
                {
                    _npcGarden   = 85514;
                    _cacheGarden = 235885;
                    _npcMine     = 77730;
                    _cacheMine   = 235886;
                    _garden      = new Point {
                        X = 1833.85f, Y = 154.7408f, Z = 76.66339f
                    };
                    _mineEntrance = new Point {
                        X = 1886.021f, Y = 83.23455f, Z = 84.31888f
                    };
                    _cacheGarrisonPoint = new Point {
                        X = 1914.361f, Y = 290.3863f, Z = 88.96407f
                    };
                }
                else
                {
                    _npcGarden   = 85783;
                    _cacheGarden = 239238;
                    _npcMine     = 81688;
                    _cacheMine   = 239237;
                    _garden      = new Point {
                        X = 5413.795f, Y = 4548.928f, Z = 139.1232f
                    };
                    _mineEntrance = new Point {
                        X = 5465.796f, Y = 4430.045f, Z = 145.4595f
                    };
                    _cacheGarrisonPoint = new Point {
                        X = 5592.229f, Y = 4569.476f, Z = 136.1069f
                    };
                }
                _cacheGardenGathered = false;
                _cacheMineGathered   = false;
            }
            bool  success, display = false;
            Point me          = ObjMgr.Me.Position;
            Task  currentTask = tList.Peek();

            if (currentTask != previousTask)
            {
                previousTask = currentTask;
                display      = true;
            }
            switch (currentTask)
            {
            case Task.GoToGarrison:
                if (display)
                {
                    Logging.Write("Task: go to garrison");
                }

                /*var pathToGarrison2 = PathFinder.FindPath(new Point() { X = 2727.872f, Y = 6451.539f, Z = 191.9229f }, out success);
                 * if (success)
                 * {
                 *  //this code allow me to test a path easily.
                 *  MovementManager.Go(pathToGarrison2);
                 *  return;
                 * }*/
                if (!Garrison.GarrisonMapIdList.Contains(Usefuls.RealContinentId))
                {
                    // We are in Draenor
                    if (Usefuls.ContinentId == Usefuls.ContinentIdByContinentName("Draenor"))
                    {
                        // We can fly, then fly
                        if (MountTask.GetMountCapacity() == MountCapacity.Fly)
                        {
                            LongMove.LongMoveGo(_cacheGarrisonPoint);
                            return;
                        }
                        // else if not too far go by foot
                        else if (_cacheGarrisonPoint.DistanceTo(me) < 100)
                        {
                            List <Point> pathToGarrison = PathFinder.FindPath(_cacheGarrisonPoint, out success);
                            if (success)
                            {
                                MovementManager.Go(pathToGarrison);
                                return;
                            }
                        }
                    }
                    // We have to use the garrison hearthstone
                    if (ItemsManager.GetItemCount(GarrisonHearthstone) > 0 && !ItemsManager.IsItemOnCooldown(GarrisonHearthstone))
                    {
                        Logging.Write("Using garrison Hearthstone");
                        ItemsManager.UseItem(GarrisonHearthstone);
                    }
                    else
                    {
                        Logging.Write("Run aborted, you are not in Draenor or too far away and don't known how to fly and don't have a Garrison Hearthstone or it's on Cooldown.");
                        tList.Clear();
                        break;     // prevent poping an empty stack, break to the end
                    }
                }
                tList.Pop();
                break;

            case Task.CheckGarrisonRessourceCache:
                if (display)
                {
                    Logging.Write("Task: gather garrison cache");
                }
                if (_cacheGarrisonPoint.DistanceTo(me) > 75.0f)
                {
                    List <Point> pathToGCache = PathFinder.FindPath(_cacheGarrisonPoint);
                    MovementManager.Go(pathToGCache);
                    return;
                }
                WoWGameObject cache = ObjMgr.GetNearestWoWGameObject(ObjMgr.GetWoWGameObjectById(_cacheGarrison));
                if (cache.GetBaseAddress != 0)
                {
                    if (cache.Position.DistanceTo(me) > 5.0f)
                    {
                        _targetNpc = new Npc {
                            Entry = cache.Entry, Position = cache.Position
                        };
                        MovementManager.FindTarget(ref _targetNpc, 5f);
                        return;
                    }
                    Interact.InteractWith(cache.GetBaseAddress, true);
                }
                tList.Pop();
                break;

            case Task.GatherHerbs:
                if (display)
                {
                    Logging.Write("Task: gather plants in garrison garden");
                }
                if (_garden.DistanceTo(me) > 15.0f)
                {
                    List <Point> pathToGarden = PathFinder.FindPath(_garden, out success);    // assume success
                    MovementManager.Go(pathToGarden);
                    return;
                }
                nManagerSetting.CurrentSetting.ActivateHerbsHarvesting = true;
                nManagerSetting.CurrentSetting.GatheringSearchRadius   = 30f;
                if (!FarmingState.NeedToRun)     // Nothing anymore to farm, then next task
                {
                    Logging.Write("Finished to farm garrison garden");
                    nManagerSetting.CurrentSetting.ActivateHerbsHarvesting = false;
                    tList.Pop();
                }
                break;

            case Task.GatherMinerals:
                if (display)
                {
                    Logging.Write("Task: gather ores and carts in garrison mine");
                }
                if (_mineEntrance.DistanceTo(me) > 15.0f)
                {
                    List <Point> pathToMine = PathFinder.FindPath(_mineEntrance, out success);    // assume success
                    MovementManager.Go(pathToMine);
                    return;
                }
                nManagerSetting.CurrentSetting.GatheringSearchRadius   = 120f;
                nManagerSetting.CurrentSetting.ActivateVeinsHarvesting = true;
                if (FarmingState.NeedToRun)
                {
                    Logging.Write("Take coffee and Mining Pick buffs");
                    if (ItemsManager.GetItemCount(PreservedMiningPick) > 0 && !ItemsManager.IsItemOnCooldown(PreservedMiningPick) &&
                        ItemsManager.IsItemUsable(PreservedMiningPick) && !ObjMgr.Me.HaveBuff(PreservedMiningPickBuff))
                    {
                        ItemsManager.UseItem(PreservedMiningPick);
                        Thread.Sleep(150 + Usefuls.Latency);
                        while (ObjMgr.Me.IsCast)
                        {
                            Thread.Sleep(150);
                        }
                        Thread.Sleep(1000);
                    }
                    if (ItemsManager.GetItemCount(MinerCoffee) > 0 && !ItemsManager.IsItemOnCooldown(MinerCoffee) &&
                        ItemsManager.IsItemUsable(MinerCoffee) && ObjMgr.Me.BuffStack(MinerCoffeeBuff) < 2)
                    {
                        ItemsManager.UseItem(MinerCoffee);
                        Thread.Sleep(150 + Usefuls.Latency);
                        while (ObjMgr.Me.IsCast)
                        {
                            Thread.Sleep(150);
                        }
                    }
                }
                else     // Nothing anymore to farm, then next task
                {
                    Logging.Write("Finished to farm garrison mine");
                    nManagerSetting.CurrentSetting.ActivateVeinsHarvesting = false;
                    tList.Pop();
                }
                break;

            case Task.GardenWorkOrder:
                if (display)
                {
                    Logging.Write("Task: collect garden cache and send work order");
                }
                if (!_cacheGardenGathered)
                {
                    WoWGameObject gardenCache = ObjMgr.GetNearestWoWGameObject(ObjMgr.GetWoWGameObjectById(_cacheGarden));
                    if (gardenCache.GetBaseAddress != 0)
                    {
                        if (gardenCache.Position.DistanceTo(me) > 5.0f)
                        {
                            _targetNpc = new Npc {
                                Entry = gardenCache.Entry, Position = gardenCache.Position
                            };
                            MovementManager.FindTarget(ref _targetNpc, 5f);
                            return;
                        }
                        else
                        {
                            Thread.Sleep(Usefuls.Latency + 250);
                            Interact.InteractWith(gardenCache.GetBaseAddress, true);
                            _cacheGardenGathered = true;
                            Thread.Sleep(Usefuls.Latency + 1750);
                        }
                    }
                }
                WoWUnit gardenNpc = ObjMgr.GetNearestWoWUnit(ObjMgr.GetWoWUnitByEntry(_npcGarden));
                if (gardenNpc.GetBaseAddress != 0)
                {
                    if (gardenNpc.Position.DistanceTo(me) > 5.0f)
                    {
                        _targetNpc = new Npc {
                            Entry = gardenNpc.Entry, Position = gardenNpc.Position
                        };
                        MovementManager.FindTarget(ref _targetNpc, 5f);
                        return;
                    }
                    else
                    {
                        Interact.InteractWith(gardenNpc.GetBaseAddress, true);
                        Thread.Sleep(Usefuls.Latency + 1000);
                        Interact.InteractWith(gardenNpc.GetBaseAddress, true);
                        Thread.Sleep(Usefuls.Latency + 500);
                        Lua.LuaDoString("GarrisonCapacitiveDisplayFrame.CreateAllWorkOrdersButton:Click()");
                        Thread.Sleep(Usefuls.Latency + 1000);
                    }
                }
                tList.Pop();
                break;

            case Task.MineWorkOrder:
                if (display)
                {
                    Logging.Write("Task: collect mine cache and send work order");
                }
                if (!_cacheMineGathered)
                {
                    WoWGameObject mineCache = ObjMgr.GetNearestWoWGameObject(ObjMgr.GetWoWGameObjectById(_cacheMine));
                    if (mineCache.GetBaseAddress != 0)
                    {
                        if (mineCache.Position.DistanceTo(me) > 5.0f)
                        {
                            _targetNpc = new Npc {
                                Entry = mineCache.Entry, Position = mineCache.Position
                            };
                            MovementManager.FindTarget(ref _targetNpc, 5f);
                            return;
                        }
                        else
                        {
                            Thread.Sleep(Usefuls.Latency + 250);
                            Interact.InteractWith(mineCache.GetBaseAddress, true);
                            _cacheMineGathered = true;
                            Thread.Sleep(Usefuls.Latency + 1750);
                        }
                    }
                }
                WoWUnit mineNpc = ObjMgr.GetNearestWoWUnit(ObjMgr.GetWoWUnitByEntry(_npcMine));
                if (mineNpc.GetBaseAddress != 0)
                {
                    if (mineNpc.Position.DistanceTo(me) > 5.0f)
                    {
                        _targetNpc = new Npc {
                            Entry = mineNpc.Entry, Position = mineNpc.Position
                        };
                        MovementManager.FindTarget(ref _targetNpc, 5f);
                        return;
                    }
                    else
                    {
                        Interact.InteractWith(mineNpc.GetBaseAddress, true);
                        Thread.Sleep(Usefuls.Latency + 1000);
                        Interact.InteractWith(mineNpc.GetBaseAddress, true);
                        Thread.Sleep(Usefuls.Latency + 500);
                        Lua.LuaDoString("GarrisonCapacitiveDisplayFrame.CreateAllWorkOrdersButton:Click()");
                        Thread.Sleep(Usefuls.Latency + 1000);
                    }
                }
                tList.Pop();
                break;
            }
            if (tList.Count == 0)
            {
                Logging.Write("Garrison Farming completed");
                CloseProduct();
            }
        }