示例#1
0
        // Credits to Inrego
        // Index are {0}=ItemID, {1}=Amount
        // returns 1 if item is found, otherwise -1

        public static void BuyItem(uint id, uint count)
        {
            string lua   = string.Format(BuyItemFormat, id, count);
            bool   found = Lua.GetReturnVal <int>(lua, 0) == 1;

            PBLog.Log("item {0} {1}", id, found ? "bought " : "not found");
        }
示例#2
0
        protected override async Task Run()
        {
            if (MoveType != MoveToType.Location)
            {
                _loc = GetLocationFromType(MoveType, Entry);
                if (_loc == WoWPoint.Zero)
                {
                    if (_locationDb == WoWPoint.Zero)
                    {
                        _locationDb = GetLocationFromDB(MoveType, Entry);
                    }
                    _loc = _locationDb;
                }
                if (_loc == WoWPoint.Zero)
                {
                    PBLog.Warn(Strings["Error_UnableToFindLocationFromDB"]);
                    IsDone = true;
                    return;
                }
            }
            if (Entry > 0 && (!StyxWoW.Me.GotTarget || StyxWoW.Me.CurrentTarget.Entry != Entry))
            {
                WoWUnit unit = ObjectManager.GetObjectsOfType <WoWUnit>(true).FirstOrDefault(u => u.Entry == Entry);
                if (unit != null)
                {
                    unit.Target();
                }
            }
            float speed = StyxWoW.Me.MovementInfo.CurrentSpeed;

            Navigator.PathPrecision = speed > 7 ? (SpeedModifer * speed) / 7f : SpeedModifer;
            if (StyxWoW.Me.Location.Distance(_loc) > 4.5)
            {
                if (Pathing == NavigationType.ClickToMove)
                {
                    WoWMovement.ClickToMove(_loc);
                }
                else
                {
                    Util.MoveTo(_loc);
                }
            }
            else
            {
                if (!_concludingSw.IsRunning)
                {
                    _concludingSw.Start();
                }
                else if (_concludingSw.ElapsedMilliseconds >= 2000)
                {
                    IsDone = true;
                    PBLog.Log("MoveTo Action completed for type {0}", MoveType);
                    _concludingSw.Stop();
                    _concludingSw.Reset();
                }
            }
        }
示例#3
0
 protected async override Task Run()
 {
     if (!IsDone)
     {
         WoWObject obj = null;
         if (InteractType == InteractActionType.NPC)
         {
             if (Entry != 0)
             {
                 obj =
                     ObjectManager.GetObjectsOfType <WoWUnit>().Where(u => u.Entry == Entry).OrderBy(
                         u => u.Distance).FirstOrDefault();
             }
             else if (StyxWoW.Me.GotTarget)
             {
                 obj = StyxWoW.Me.CurrentTarget;
             }
         }
         else if (InteractType == InteractActionType.GameObject)
         {
             obj =
                 ObjectManager.GetObjectsOfType <WoWGameObject>().OrderBy(u => u.Distance).FirstOrDefault(
                     u => (Entry > 0 && u.Entry == Entry) || (u.SubType == GameObjectType &&
                                                              (GameObjectType != WoWGameObjectType.SpellFocus ||
                                                               (GameObjectType == WoWGameObjectType.SpellFocus &&
                                                                u.SpellFocus == SpellFocus))));
         }
         if (obj != null)
         {
             WoWPoint moveToLoc = WoWMathHelper.CalculatePointFrom(Me.Location, obj.Location, 3);
             if (moveToLoc.Distance(Me.Location) > 4)
             {
                 Util.MoveTo(moveToLoc);
             }
             else
             {
                 if (InteractDelay > 0 &&
                     (!_interactSw.IsRunning || _interactSw.ElapsedMilliseconds < InteractDelay))
                 {
                     _interactSw.Start();
                 }
                 else
                 {
                     _interactSw.Reset();
                     obj.Interact();
                     IsDone = true;
                 }
             }
         }
         if (IsDone)
         {
             PBLog.Log("InteractAction complete");
         }
     }
 }
示例#4
0
        private bool CancelAuction(AuctionEntry ae)
        {
            string lua         = String.Format(CancelAuctionLuaFormat, ae.Id, MinBuyout.TotalCopper, ae.LowestBo);
            var    numCanceled = Lua.GetReturnVal <int>(lua, 0);

            if (numCanceled > 0)
            {
                PBLog.Log("Canceled {0} x{1}", ae.Name, numCanceled);
            }
            return(true);
        }
        protected override async Task Run()
        {
            try
            {
                if (_changeBotTimer == null)
                {
                    _changeBotTimer = new WaitTimer(TimeSpan.FromSeconds(10));
                    _changeBotTimer.Reset();
                    _bot = Util.GetBotByName(BotName);
                    if (_bot != null)
                    {
                        if (ProfessionbuddyBot.Instance.SecondaryBot == _bot)
                        {
                            IsDone = true;
                            return;
                        }
                        ProfessionbuddyBot.ChangeSecondaryBot(BotName);
                    }
                }
            }
            finally
            {
                // Wait until bot change completes or fails
                if (_bot == null ||
                    _changeBotTimer != null && (_changeBotTimer.IsFinished || ProfessionbuddyBot.Instance.SecondaryBot == _bot))
                {
                    IsDone          = true;
                    _changeBotTimer = null;
                }
            }

            if (IsDone)
            {
                if (_bot == null)
                {
                    PBLog.Warn("No bot with name: {0} could be found", BotName);
                }
                else if (ProfessionbuddyBot.Instance.SecondaryBot == _bot)
                {
                    PBLog.Log("Successfuly changed secondary bot to: {0}", BotName);
                }
                else
                {
                    PBLog.Warn("Unable to switch secondary bot to: {0}", BotName);
                }
            }
        }
        // indexes are {0} = ItemID, {1} = amount to deposit

        /// <summary>
        /// Withdraws items from gbank
        /// </summary>
        /// <param name="id">item ID</param>
        /// <param name="amount">amount to withdraw.</param>
        /// <returns>the amount withdrawn.</returns>
        public int GetItemFromGBank(uint id, int amount)
        {
            if (_queueServerSW == null)
            {
                _queueServerSW = new Stopwatch();
                _queueServerSW.Start();
                Lua.DoString("for i=GetNumGuildBankTabs(), 1, -1 do QueryGuildBankTab(i) end ");
                PBLog.Log("Queuing server for gbank info");
                return(0);
            }
            if (_queueServerSW.ElapsedMilliseconds < 2000)
            {
                return(0);
            }
            string lua    = string.Format(WithdrawItemFromGBankLuaFormat, id, amount);
            var    retVal = Lua.GetReturnVal <int>(lua, 0);

            return(retVal);
        }
示例#7
0
        public int PutItemInGBank(uint id, int amount, uint tab)
        {
            using (StyxWoW.Memory.AcquireFrame())
            {
                if (_queryServerSW == null)
                {
                    _queryServerSW = new Stopwatch();
                    _queryServerSW.Start();
                    Lua.DoString(
                        "for i=GetNumGuildBankTabs(), 1, -1 do QueryGuildBankTab(i) end SetCurrentGuildBankTab({0}) ",
                        tab == 0 ? 1 : tab);
                    PBLog.Log("Querying server for gbank info");
                    return(0);
                }
                if (_queryServerSW.ElapsedMilliseconds < 2000)
                {
                    return(0);
                }
                if (_bankSlots == null)
                {
                    _bankSlots = GetBankSlotInfo();
                }
                var tabCnt     = Lua.GetReturnVal <int>("return GetNumGuildBankTabs()", 0);
                var currentTab = Lua.GetReturnVal <int>("return GetCurrentGuildBankTab()", 0);

                var slotsInCurrentTab = _bankSlots
                                        .Where(slotI => slotI.Bag == currentTab).ToList();

                WoWItem itemToDeposit = Me.CarriedItems.OrderBy(item => item.StackCount)
                                        .FirstOrDefault(item => item.Entry == id && !item.IsDisabled);
                if (itemToDeposit != null)
                {
                    int depositAmount = amount > 0 && amount < (int)itemToDeposit.StackCount
                                                ? amount
                                                : (int)itemToDeposit.StackCount;

                    BankSlotInfo emptySlot    = slotsInCurrentTab.FirstOrDefault(slotI => slotI.StackSize == 0);
                    BankSlotInfo partialStack = slotsInCurrentTab
                                                .FirstOrDefault(
                        slotI => slotI.ItemID == id && slotI.MaxStackSize - slotI.StackSize >= depositAmount);
                    if (partialStack != null || emptySlot != null)
                    {
                        bool slotIsEmpty = partialStack == null;
                        int  bSlotIndex  = slotIsEmpty ? _bankSlots.IndexOf(emptySlot) : _bankSlots.IndexOf(partialStack);
                        _bankSlots[bSlotIndex].StackSize += itemToDeposit.StackCount;
                        if (slotIsEmpty)
                        {
                            _bankSlots[bSlotIndex].ItemID       = itemToDeposit.Entry;
                            _bankSlots[bSlotIndex].MaxStackSize = itemToDeposit.ItemInfo.MaxStackSize;
                        }
                        if (depositAmount == itemToDeposit.StackCount)
                        {
                            itemToDeposit.UseContainerItem();
                        }
                        else
                        {
                            Lua.DoString(
                                "SplitContainerItem({0},{1},{2}) PickupGuildBankItem({3},{4})",
                                itemToDeposit.BagIndex + 1,
                                itemToDeposit.BagSlot + 1,
                                depositAmount,
                                _bankSlots[bSlotIndex].Bag,
                                _bankSlots[bSlotIndex].Slot);
                        }
                        return(depositAmount);
                    }
                    if (tab > 0 || currentTab == tabCnt)
                    {
                        PBLog.Log("Guild Tab: {0} is full", tab);
                        return(-1);
                    }
                    if (tab == 0 && currentTab < tabCnt)
                    {
                        Lua.DoString("SetCurrentGuildBankTab({0})", currentTab + 1);
                        return(0);
                    }
                }
                return(-1);
            }
        }
示例#8
0
 protected async override Task Run()
 {
     if ((Bank == BankType.Guild && !Util.IsGBankFrameOpen) ||
         (Bank == BankType.Personal && !Util.IsBankFrameOpen))
     {
         MoveToBanker();
     }
     else
     {
         if (_itemsSW == null)
         {
             _itemsSW = new Stopwatch();
             _itemsSW.Start();
         }
         else if (_itemsSW.ElapsedMilliseconds < Util.WowWorldLatency * 3)
         {
             return;
         }
         if (_itemList == null)
         {
             _itemList = BuildItemList();
         }
         // no bag space...
         if (_itemList.Count == 0)
         {
             IsDone = true;
         }
         else
         {
             uint itemID = _itemList.Keys.FirstOrDefault();
             bool done;
             if (Bank == BankType.Personal)
             {
                 done = PutItemInBank(itemID, _itemList[itemID]);
             }
             else
             {
                 // throttle the amount of items being withdrawn from gbank per sec
                 if (!_gbankItemThrottleSW.IsRunning)
                 {
                     _gbankItemThrottleSW.Start();
                 }
                 if (_gbankItemThrottleSW.ElapsedMilliseconds < GbankItemThrottle)
                 {
                     return;
                 }
                 _gbankItemThrottleSW.Reset();
                 _gbankItemThrottleSW.Start();
                 int ret = PutItemInGBank(itemID, _itemList[itemID], GuildTab);
                 _itemList[itemID] = ret < 0 ? 0 : _itemList[itemID] - ret;
                 done = _itemList[itemID] <= 0;
             }
             if (done)
             {
                 ProfessionbuddyBot.Debug("Done Depositing Item:{0} to bank", itemID);
                 _itemList.Remove(itemID);
             }
             _itemsSW.Reset();
             _itemsSW.Start();
         }
     }
     if (IsDone)
     {
         PBLog.Log("Deposited Items:[{0}] to {1} Bank", ItemID, Bank);
     }
 }
示例#9
0
        protected override async Task Run()
        {
            if (!MailFrame.Instance.IsVisible)
            {
                await OpenMailbox();

                return;
            }

            if (_itemList == null)
            {
                _itemList = BuildItemList();
            }

            if (string.IsNullOrEmpty(_mailSubject))
            {
                _mailSubject = " ";
            }

            if (!_itemList.Any())
            {
                if (NumberOfSlotsUsedInSendMail > 0)
                {
                    await MailItems(CharacterSettings.Instance.MailRecipient, _mailSubject);
                }

                IsDone = true;
                PBLog.Log(
                    "Done sending {0} via mail",
                    ItemSelection == ItemSelectionType.Category
                                                ? string.Format(
                        "Items that belong to category {0} and subcategory {1}",
                        Category,
                        SubCategory)
                                                : (ItemSelection == ItemSelectionType.IDs
                                                        ? string.Format("Items that match Id of {0}", ItemID)
                                                        : string.Format("Items of quality {0}", ItemQuality)));
                return;
            }

            MailFrame.Instance.SwitchToSendMailTab();
            uint    itemID = _itemList.Keys.FirstOrDefault();
            WoWItem item   = Me.BagItems.FirstOrDefault(i => i.Entry == itemID);

            _mailSubject = item != null ? item.Name : " ";

            PBLog.Debug("MailItem: placing {0} into a Send Mail slot", item != null ? item.Name:itemID.ToString());

            if (NumberOfSlotsUsedInSendMail >= 12)
            {
                await MailItems(CharacterSettings.Instance.MailRecipient, _mailSubject);
            }

            int amountPlaced = PlaceItemInMail(itemID, _itemList[itemID]);

            if (amountPlaced >= 0)
            {
                // we need to wait for item split to finish if ret >= 0
                await CommonCoroutines.SleepForLagDuration();
            }

            _itemList[itemID] = amountPlaced < 0 ? 0 : _itemList[itemID] - amountPlaced;

            bool doneWithItem = _itemList[itemID] <= 0;

            if (doneWithItem)
            {
                _itemList.Remove(itemID);
            }
        }
示例#10
0
        /// <summary>
        ///     Switches to a different character on same account
        /// </summary>
        /// <param name="character"></param>
        /// <param name="server"></param>
        /// <param name="botName">Name of bot to use on that character. The bot class type name will also work.</param>
        public static void SwitchCharacter(string character, string server, string botName)
        {
            if (_isSwitchingToons)
            {
                PBLog.Log("Already switching characters");
                return;
            }
            string loginLua = string.Format(LoginLua, character, server);

            _isSwitchingToons = true;
            // reset all actions
            ProfessionbuddyBot.Instance.IsRunning = false;
            ProfessionbuddyBot.Instance.Reset();

            Application.Current.Dispatcher.BeginInvoke(
                new Action(
                    () =>
            {
                Lua.DoString("Logout()");

                new Thread(
                    () =>
                {
                    while (StyxWoW.IsInGame)
                    {
                        Thread.Sleep(2000);
                    }
                    while (!StyxWoW.IsInGame)
                    {
                        Lua.DoString(loginLua);
                        Thread.Sleep(2000);
                    }
                    BotBase bot = Util.GetBotByName(botName);
                    if (bot != null)
                    {
                        if (ProfessionbuddyBot.Instance.SecondaryBot.Name != bot.Name)
                        {
                            ProfessionbuddyBot.Instance.SecondaryBot = bot;
                        }
                        if (!bot.Initialized)
                        {
                            bot.DoInitialize();
                        }
                        if (ProfessionBuddySettings.Instance.LastBotBase != bot.Name)
                        {
                            ProfessionBuddySettings.Instance.LastBotBase = bot.Name;
                            ProfessionBuddySettings.Instance.Save();
                        }
                    }
                    else
                    {
                        PBLog.Warn("Could not find bot with name {0}", botName);
                    }
                    TreeRoot.Start();
                    ProfessionbuddyBot.Instance.OnTradeSkillsLoaded += ProfessionbuddyBot.Instance.Professionbuddy_OnTradeSkillsLoaded;
                    ProfessionbuddyBot.Instance.LoadTradeSkills();
                    _isSwitchingToons = false;
                    ProfessionbuddyBot.Instance.IsRunning = true;
                })
                {
                    IsBackground = true
                }.Start();
            }));
            TreeRoot.Stop();
        }
示例#11
0
        protected override async Task Run()
        {
            if (!_timeoutSW.IsRunning)
            {
                _timeoutSW.Start();
            }

            if (_timeoutSW.ElapsedMilliseconds > 300000)
            {
                IsDone = true;
            }

            if (MailFrame.Instance == null || !MailFrame.Instance.IsVisible)
            {
                WoWPoint movetoPoint = _loc;
                if (AutoFindMailBox || movetoPoint == WoWPoint.Zero)
                {
                    _mailbox =
                        ObjectManager.GetObjectsOfType <WoWGameObject>().Where(
                            o => o.SubType == WoWGameObjectType.Mailbox && o.CanUse())
                        .OrderBy(o => o.DistanceSqr).FirstOrDefault();
                }
                else
                {
                    _mailbox =
                        ObjectManager.GetObjectsOfType <WoWGameObject>().Where(
                            o => o.SubType == WoWGameObjectType.Mailbox &&
                            o.Location.Distance(_loc) < 10 && o.CanUse())
                        .OrderBy(o => o.DistanceSqr).FirstOrDefault();
                }
                if (_mailbox != null)
                {
                    movetoPoint = _mailbox.Location;
                }
                if (movetoPoint == WoWPoint.Zero)
                {
                    PBLog.Warn(Strings["Error_UnableToFindMailbox"]);
                    return;
                }

                if (_mailbox == null || !_mailbox.WithinInteractRange)
                {
                    Util.MoveTo(movetoPoint);
                }
                else if (_mailbox != null)
                {
                    if (Me.IsMoving)
                    {
                        WoWMovement.MoveStop();
                    }
                    _mailbox.Interact();
                }
                return;
            }
            // mail frame is open.
            if (_idList == null)
            {
                _idList = BuildItemList();
            }
            if (!_refreshInboxSW.IsRunning)
            {
                _refreshInboxSW.Start();
            }
            if (!_waitForContentToShowSW.IsRunning)
            {
                _waitForContentToShowSW.Start();
            }
            if (_waitForContentToShowSW.ElapsedMilliseconds < 3000)
            {
                return;
            }

            if (!_concludingSW.IsRunning)
            {
                if (_refreshInboxSW.ElapsedMilliseconds < 64000)
                {
                    if (MinFreeBagSlots > 0 && Me.FreeNormalBagSlots - MinFreeBagSlots <= 4)
                    {
                        if (!_throttleSW.IsRunning)
                        {
                            _throttleSW.Start();
                        }
                        if (_throttleSW.ElapsedMilliseconds < 4000 - (Me.FreeNormalBagSlots - MinFreeBagSlots) * 1000)
                        {
                            return;
                        }
                        _throttleSW.Reset();
                        _throttleSW.Start();
                    }
                    if (GetMailType == GetMailActionType.AllItems)
                    {
                        string lua = string.Format(MailFormat, CheckNewMail ? 1 : 0, MaxCODAmount.TotalCopper);
                        if (Me.FreeNormalBagSlots <= MinFreeBagSlots || Lua.GetReturnValues(lua)[0] == "1")
                        {
                            _concludingSW.Start();
                        }
                    }
                    else
                    {
                        if (_idList.Count > 0 && Me.FreeNormalBagSlots > MinFreeBagSlots)
                        {
                            string lua = string.Format(MailByIdFormat, _idList[0], CheckNewMail ? 1 : 0, MaxCODAmount.TotalCopper);

                            if (Lua.GetReturnValues(lua)[0] == "1")
                            {
                                _idList.RemoveAt(0);
                            }
                        }
                        else
                        {
                            _concludingSW.Start();
                        }
                    }
                }
                else
                {
                    _refreshInboxSW.Reset();
                    MailFrame.Instance.Close();
                }
            }
            if (_concludingSW.ElapsedMilliseconds > 2000)
            {
                IsDone = true;
            }
            if (IsDone)
            {
                PBLog.Log("Mail retrieval of items:{0} finished", GetMailType);
            }
        }
        protected async override Task Run()
        {
            if ((Bank == BankType.Guild && !Util.IsGBankFrameOpen) ||
                (Bank == BankType.Personal && !Util.IsBankFrameOpen))
            {
                MoveToBanker();
            }
            else
            {
                if (_itemsSW == null)
                {
                    _itemsSW = new Stopwatch();
                    _itemsSW.Start();
                }
                else if (_itemsSW.ElapsedMilliseconds < Util.WowWorldLatency * 3)
                {
                    return;
                }
                if (_itemList == null)
                {
                    _itemList = BuildItemList();
                }
                // no bag space...
                if (Util.BagRoomLeft(_itemList.Keys.FirstOrDefault()) <= MinFreeBagSlots || !_itemList.Any())
                {
                    IsDone = true;
                }
                else
                {
                    uint itemID = _itemList.Keys.FirstOrDefault();
                    bool done;
                    if (Bank == BankType.Personal)
                    {
                        done = GetItemFromBank(itemID, _itemList[itemID]);
                    }
                    else
                    {
                        // throttle the amount of items being withdrawn from gbank per sec
                        if (!_gbankItemThrottleSW.IsRunning)
                        {
                            _gbankItemThrottleSW.Start();
                        }
                        if (_gbankItemThrottleSW.ElapsedMilliseconds < GbankItemThrottle)
                        {
                            return;
                        }

                        int ret = GetItemFromGBank(itemID, _itemList[itemID]);
                        if (ret >= 0)
                        {
                            _gbankItemThrottleSW.Restart();
                            _withdrawCnt += ret;
                        }
                        _itemList[itemID] = ret < 0 ? 0 : _itemList[itemID] - ret;
                        done = _itemList[itemID] <= 0;
                    }
                    if (done)
                    {
                        if (itemID == 0)
                        {
                            PBLog.Log("Done withdrawing all items from {0} Bank", Bank);
                        }
                        else
                        {
                            PBLog.Log("Done withdrawing {0} itemID:{1} from {2} Bank", _withdrawCnt, itemID, Bank);
                        }
                        _itemList.Remove(itemID);
                        _withdrawCnt = 0;
                    }
                }
                _itemsSW.Restart();
            }
        }
示例#13
0
        protected override async Task Run()
        {
            if (Me.IsFlying)
            {
                return;
            }
            if (_lootSw.IsRunning && _lootSw.ElapsedMilliseconds < WaitForLagTimeMs)
            {
                return;
            }
            if (LootFrame.Instance != null && LootFrame.Instance.IsVisible)
            {
                LootFrame.Instance.LootAll();
                _lootSw.Reset();
                _lootSw.Start();
                return;
            }
            uint timeToWait = GetCastTime();

            if (!Me.IsCasting && (!_castTimer.IsRunning || _castTimer.ElapsedMilliseconds >= timeToWait))
            {
                List <WoWItem> itemList = BuildItemList();
                if (itemList == null || !itemList.Any())
                {
                    IsDone = true;
                    PBLog.Log("Done {0}ing", ActionType);
                }
                else
                {
                    // skip 'locked' items
                    int index = 0;
                    for (; index <= itemList.Count; index++)
                    {
                        if (!itemList[index].IsDisabled)
                        {
                            break;
                        }
                    }
                    if (index < itemList.Count)
                    {
                        if (itemList[index].Guid == _lastItemGuid && _lastStackSize == itemList[index].StackCount)
                        {
                            if (++_tries >= 3)
                            {
                                PBLog.Log(
                                    "Unable to {0} {1}, BlackListing",
                                    ActionType,
                                    itemList[index].Name);
                                if (!_blacklistedItems.Contains(_lastItemGuid))
                                {
                                    _blacklistedItems.Add(_lastItemGuid);
                                }
                                return;
                            }
                        }
                        else
                        {
                            _tries = 0;
                        }
                        WoWSpell spell = WoWSpell.FromId(SpellId);
                        if (spell != null)
                        {
                            TreeRoot.GoalText = string.Format("{0}: {1}", ActionType, itemList[index].Name);
                            PBLog.Log(TreeRoot.GoalText);
                            //Lua.DoString("CastSpellByID({0}) UseContainerItem({1}, {2})",
                            //    spellId, ItemList[index].BagIndex + 1, ItemList[index].BagSlot + 1);
                            spell.CastOnItem(itemList[index]);
                            _lastItemGuid  = itemList[index].Guid;
                            _lastStackSize = itemList[index].StackCount;
                            _castTimer.Reset();
                            _castTimer.Start();
                        }
                        else
                        {
                            IsDone = true;
                        }
                    }
                }
            }
        }
示例#14
0
        protected async override Task Run()
        {
            if (Lua.GetReturnVal <int>("if AuctionFrame and AuctionFrame:IsVisible() then return 1 else return 0 end ", 0) == 0)
            {
                MoveToAh();
            }
            else
            {
                if (_toScanItemList == null)
                {
                    _toScanItemList = BuildScanItemList();
                    _toSellItemList = new List <AuctionEntry>();
                }
                if (_toScanItemList.Count == 0 && _toSellItemList.Count == 0)
                {
                    _toScanItemList = null;
                    IsDone          = true;
                    return;
                }
                if (_toScanItemList.Count > 0)
                {
                    AuctionEntry ae       = _toScanItemList[0];
                    bool         scanDone = ScanAh(ref ae);
                    _toScanItemList[0] = ae;                     // update
                    if (scanDone)
                    {
                        uint lowestBo = ae.LowestBo;
                        if (lowestBo > MaxBuyout.TotalCopper)
                        {
                            ae.Buyout = MaxBuyout.TotalCopper;
                        }
                        else if (lowestBo < MinBuyout.TotalCopper)
                        {
                            ae.Buyout = MinBuyout.TotalCopper;
                        }
                        else
                        {
                            ae.Buyout = lowestBo - (uint)Math.Ceiling((lowestBo * UndercutPrecent / 100d));
                        }
                        ae.Bid = (uint)(ae.Buyout * BidPrecent / 100d);
                        bool enoughItemsPosted = AmountType == AmountBasedType.Amount && ae.MyAuctions >= Amount;
                        bool tooLowBuyout      = !PostIfBelowMinBuyout && lowestBo < MinBuyout.TotalCopper;

                        ProfessionbuddyBot.Debug("Post If Below MinBuyout:{0} ", PostIfBelowMinBuyout, MinBuyout.TotalCopper);
                        ProfessionbuddyBot.Debug(
                            "Lowest Buyout on AH: {0}, My Minimum Bouyout: {1}",
                            AuctionEntry.GoldString(lowestBo),
                            AuctionEntry.GoldString(MinBuyout.TotalCopper));

                        if (!enoughItemsPosted && !tooLowBuyout)
                        {
                            _toSellItemList.Add(ae);
                        }
                        else
                        {
                            PBLog.Log(
                                "Skipping {0} since {1}",
                                ae.Name,
                                tooLowBuyout
                                                                        ? string.Format("lowest buyout:{0} is below my MinBuyout:{1}", AuctionEntry.GoldString(lowestBo), MinBuyout)
                                                                        : string.Format("{0} items from me are already posted. Max amount is {1}", ae.MyAuctions, Amount));
                        }
                        _toScanItemList.RemoveAt(0);
                    }
                    if (_toScanItemList.Count == 0)
                    {
                        ProfessionbuddyBot.Debug("Finished scanning for items");
                    }
                }
                if (_toSellItemList.Count > 0)
                {
                    if (SellOnAh(_toSellItemList[0]))
                    {
                        PBLog.Log(
                            "Selling {0} for {1}. {2}",
                            _toSellItemList[0].Name,
                            AuctionEntry.GoldString(_toSellItemList[0].Buyout),
                            _toSellItemList[0].LowestBo == uint.MaxValue
                                                                ? "There is no competition"
                                                                : string.Format("Competition is at {0}", AuctionEntry.GoldString(_toSellItemList[0].LowestBo)));
                        _toSellItemList.RemoveAt(0);
                    }
                }
            }
        }
示例#15
0
        protected override async Task Run()
        {
            if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
            {
                WoWPoint movetoPoint = _loc;
                WoWUnit  unit        = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.Entry == NpcEntry).
                                       OrderBy(o => o.Distance).FirstOrDefault();
                if (unit != null)
                {
                    movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, unit.Location, 3);
                }
                else if (movetoPoint == WoWPoint.Zero)
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NpcByID, NpcEntry);
                }
                if (movetoPoint != WoWPoint.Zero && StyxWoW.Me.Location.Distance(movetoPoint) > 4.5)
                {
                    Util.MoveTo(movetoPoint);
                }
                else if (unit != null)
                {
                    unit.Target();
                    unit.Interact();
                }
                if (GossipFrame.Instance != null && GossipFrame.Instance.IsVisible &&
                    GossipFrame.Instance.GossipOptionEntries != null)
                {
                    foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                    {
                        if (ge.Type == GossipEntry.GossipEntryType.Vendor)
                        {
                            GossipFrame.Instance.SelectGossipOption(ge.Index);
                            break;
                        }
                    }
                }
            }
            else
            {
                // check if we have merchant frame open at correct NPC
                if (NpcEntry > 0 && Me.GotTarget && Me.CurrentTarget.Entry != NpcEntry)
                {
                    MerchantFrame.Instance.Close();
                    return;
                }
                if (!_concludingSw.IsRunning)
                {
                    if (BuyItemType == BuyItemActionType.SpecificItem)
                    {
                        var      idList  = new List <uint>();
                        string[] entries = ItemID.Split(',');
                        if (entries.Length > 0)
                        {
                            foreach (string entry in entries)
                            {
                                uint itemID;
                                if (!uint.TryParse(entry.Trim(), out itemID))
                                {
                                    PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                                    continue;
                                }
                                idList.Add(itemID);
                            }
                        }
                        else
                        {
                            PBLog.Warn(Strings["Error_NoItemEntries"]);
                            IsDone = true;
                            return;
                        }
                        foreach (uint id in idList)
                        {
                            int count = !BuyAdditively?Math.Max(Count - Util.GetCarriedItemCount(id), 0) : Count;

                            if (count > 0)
                            {
                                BuyItem(id, (uint)count);
                            }
                        }
                    }
                    else if (BuyItemType == BuyItemActionType.Material)
                    {
                        foreach (var kv in ProfessionbuddyBot.Instance.MaterialList)
                        {
                            // only buy items if we don't have enough in bags...
                            int amount = kv.Value - (int)Ingredient.GetInBagItemCount(kv.Key);
                            if (amount > 0)
                            {
                                BuyItem(kv.Key, (uint)amount);
                            }
                        }
                    }
                    _concludingSw.Start();
                }
                if (_concludingSw.ElapsedMilliseconds >= 2000)
                {
                    PBLog.Log("BuyItemAction Completed");
                    IsDone = true;
                }
            }
        }
示例#16
0
        protected override async Task Run()
        {
            if (MerchantFrame.Instance == null || !MerchantFrame.Instance.IsVisible)
            {
                WoWPoint movetoPoint = _loc;
                if (_entry == 0)
                {
                    _entry = NpcEntry;
                }
                if (_entry == 0)
                {
                    MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestVendor, 0);
                    NpcResult npcResults = NpcQueries.GetNearestNpc(
                        StyxWoW.Me.MapId,
                        StyxWoW.Me.Location,
                        UnitNPCFlags.Vendor);
                    _entry      = (uint)npcResults.Entry;
                    movetoPoint = npcResults.Location;
                }
                WoWUnit unit = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.Entry == _entry).
                               OrderBy(o => o.Distance).FirstOrDefault();
                if (unit != null)
                {
                    movetoPoint = unit.Location;
                }
                else if (movetoPoint == WoWPoint.Zero)
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NpcByID, NpcEntry);
                }
                if (movetoPoint != WoWPoint.Zero && StyxWoW.Me.Location.Distance(movetoPoint) > 4.5)
                {
                    Util.MoveTo(movetoPoint);
                }
                else if (unit != null)
                {
                    unit.Target();
                    unit.Interact();
                }

                if (GossipFrame.Instance != null && GossipFrame.Instance.IsVisible &&
                    GossipFrame.Instance.GossipOptionEntries != null)
                {
                    foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                    {
                        if (ge.Type == GossipEntry.GossipEntryType.Vendor)
                        {
                            GossipFrame.Instance.SelectGossipOption(ge.Index);
                            return;
                        }
                    }
                }
            }
            else
            {
                if (SellItemType == SellItemActionType.Specific)
                {
                    var      idList  = new List <uint>();
                    string[] entries = ItemID.Split(',');
                    if (entries.Length > 0)
                    {
                        foreach (string entry in entries)
                        {
                            uint itemID;
                            if (!uint.TryParse(entry.Trim(), out itemID))
                            {
                                PBLog.Warn(Strings["Error_NotAValidItemEntry"], entry.Trim());
                                continue;
                            }
                            idList.Add(itemID);
                        }
                    }
                    else
                    {
                        PBLog.Warn(Strings["Error_NoItemEntries"]);
                        IsDone = true;
                        return;
                    }
                    List <WoWItem> itemList = StyxWoW.Me.BagItems.Where(u => idList.Contains(u.Entry)).
                                              Take(Sell == DepositWithdrawAmount.All ? int.MaxValue : Count).ToList();
                    using (StyxWoW.Memory.AcquireFrame())
                    {
                        foreach (WoWItem item in itemList)
                        {
                            item.UseContainerItem();
                        }
                    }
                }
                else
                {
                    List <WoWItem>        itemList  = null;
                    IEnumerable <WoWItem> itemQuery = from item in Me.BagItems
                                                      where !ProtectedItemsManager.Contains(item.Entry) &&
                                                      !ProfessionbuddyBot.Instance.TradeskillTools.Contains(item.Entry)
                                                      select item;
                    switch (SellItemType)
                    {
                    case SellItemActionType.Greys:
                        itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Poor).ToList();
                        break;

                    case SellItemActionType.Whites:
                        itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Common).ToList();
                        break;

                    case SellItemActionType.Greens:
                        itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Uncommon).ToList();
                        break;

                    case SellItemActionType.Blues:
                        itemList = itemQuery.Where(i => i.Quality == WoWItemQuality.Rare).ToList();
                        break;
                    }
                    if (itemList != null)
                    {
                        using (StyxWoW.Memory.AcquireFrame())
                        {
                            foreach (WoWItem item in itemList)
                            {
                                item.UseContainerItem();
                            }
                        }
                    }
                }
                PBLog.Log("SellItemAction Completed for {0}", ItemID);
                IsDone = true;
            }
        }
示例#17
0
        protected override async Task Run()
        {
            if (!_interactTimer.IsFinished)
            {
                return;
            }

            if (!TrainerFrame.Instance.IsVisible || !StyxWoW.Me.GotTarget || StyxWoW.Me.CurrentTarget.Entry != NpcEntry)
            {
                WoWPoint movetoPoint = _loc;
                WoWUnit  unit        = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.Entry == NpcEntry).
                                       OrderBy(o => o.Distance).FirstOrDefault();

                if (unit != null)
                {
                    movetoPoint = unit.Location;
                }
                else if (movetoPoint == WoWPoint.Zero)
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NpcByID, NpcEntry);
                }

                if (movetoPoint != WoWPoint.Zero && StyxWoW.Me.Location.Distance(movetoPoint) > 4.5)
                {
                    Util.MoveTo(movetoPoint);
                    return;
                }

                if (GossipFrame.Instance.IsVisible)
                {
                    foreach (GossipEntry ge in GossipFrame.Instance.GossipOptionEntries)
                    {
                        if (ge.Type == GossipEntry.GossipEntryType.Trainer)
                        {
                            GossipFrame.Instance.SelectGossipOption(ge.Index);
                            return;
                        }
                    }
                    PBLog.Warn("NPC does not provide a train gossip option");
                    // we should not continue at this point.
                    TreeRoot.Stop();
                    return;
                }

                if (Me.IsMoving)
                {
                    WoWMovement.MoveStop();
                    return;
                }

                if (unit != null)
                {
                    if (Me.CurrentTargetGuid != unit.Guid)
                    {
                        unit.Target();
                        return;
                    }
                    _interactTimer.Reset();
                    unit.Interact();
                }

                return;
            }

            if (_trainWaitTimer.IsFinished)
            {
                using (StyxWoW.Memory.AcquireFrame())
                {
                    Lua.DoString("SetTrainerServiceTypeFilter('available', 1)");
                    // check if there is any abilities to that need training.
                    var numOfAvailableAbilities =
                        Lua.GetReturnVal <int>(
                            "local a=0 for n=GetNumTrainerServices(),1,-1 do if select(3,GetTrainerServiceInfo(n)) == 'available' then a=a+1 end end return a ",
                            0);
                    if (numOfAvailableAbilities == 0)
                    {
                        IsDone = true;
                        PBLog.Log("Done training");
                        return;
                    }
                    Lua.DoString("BuyTrainerService(0) ");
                    _trainWaitTimer.Reset();
                }
            }
        }