Esempio n. 1
0
 protected PBAction()
 {
     HasRunOnce = false;
     Pb = Professionbuddy.Instance;
     // ReSharper disable DoNotCallOverridableMethodsInConstructor
     Properties = new PropertyBag();
     // ReSharper restore DoNotCallOverridableMethodsInConstructor
     Expressions = new ListDictionary();
 }
Esempio n. 2
0
        // Indexes are {0}=ItemID, {1}=MinBuyout, {2}=LowestBuyoutFound

        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)
            {
                Professionbuddy.Log("Canceled {0} x{1}", ae.Name, numCanceled);
            }
            return(true);
        }
Esempio n. 3
0
 protected virtual bool CanRun(object context)
 {
     try
     {
         return(CanRunDelegate(context));
     }
     catch (Exception ex)
     {
         Professionbuddy.Err("If Condition: {0} ,Err:{1}", Condition, ex);
         return(false);
     }
 }
        bool ScanAh(ref AuctionEntry ae)
        {
            bool scanned = false;

            if (!queueTimer.IsRunning)
            {
                string lua = string.Format("QueryAuctionItems(\"{0}\" ,nil,nil,nil,nil,nil,{1}) return 1",
                                           ae.Name.ToFormatedUTF8(), page);
                Lua.GetReturnVal <int>(lua, 0);
                Professionbuddy.Debug("Searching AH for {0}", ae.Name);
                queueTimer.Start();
            }
            else if (queueTimer.ElapsedMilliseconds <= 10000)
            {
                using (new FrameLock())
                {
                    if (Lua.GetReturnVal <int>("if CanSendAuctionQuery('list') == 1 then return 1 else return 0 end ", 0) == 1)
                    {
                        queueTimer.Stop();
                        queueTimer.Reset();
                        totalAuctions = Lua.GetReturnVal <int>("return GetNumAuctionItems('list')", 1);
                        string lua = string.Format("local A,totalA= GetNumAuctionItems('list') local me = GetUnitName('player') local auctionInfo = {{{0},{1}}} for index=1, A do local name, _, count,_,_,_,minBid,_, buyoutPrice,_,_,owner,_ = GetAuctionItemInfo('list', index) if name == \"{2}\" and owner ~= me and buyoutPrice > 0 and buyoutPrice/count <  auctionInfo[1] then auctionInfo[1] = floor(buyoutPrice/count) end if owner == me then auctionInfo[2] = auctionInfo[2] + 1 end end return unpack(auctionInfo) ",
                                                   ae.LowestBo, ae.myAuctions, ae.Name.ToFormatedUTF8());
                        //Logging.Write("****Copy Below this line****");
                        //Logging.Write(lua);
                        //Logging.Write("****End of copy/paste****");
                        List <string> retVals = Lua.GetReturnValues(lua);
                        uint.TryParse(retVals[0], out ae.LowestBo);
                        uint.TryParse(retVals[1], out ae.myAuctions);
                        if (++page >= (int)Math.Ceiling((double)totalAuctions / 50))
                        {
                            scanned = true;
                        }
                    }
                }
            }
            else
            {
                scanned = true;
            }
            // reset to default values in preparations for next scan
            if (scanned)
            {
                Professionbuddy.Debug("lowest buyout {0}", ae.LowestBo);
                queueTimer.Stop();
                queueTimer.Reset();
                totalAuctions = 0;
                page          = 0;
            }
            return(scanned);
        }
        List <AuctionEntry> BuildScanItemList()
        {
            var tmpItemlist = new List <AuctionEntry>();
            Dictionary <uint, string> myAucs = GetMyAuctions();

            if (UseCategory)
            {
                using (new FrameLock())
                {
                    foreach (var aucKV in myAucs)
                    {
                        ItemInfo info = ItemInfo.FromId(aucKV.Key);
                        if (info != null)
                        {
                            if (info.ItemClass == Category && SubCategoryCheck(info.SubClassId))
                            {
                                tmpItemlist.Add(new AuctionEntry(aucKV.Value, aucKV.Key, 0, 0));
                            }
                        }
                        else
                        {
                            Professionbuddy.Err("item cache of {0} is null", aucKV.Value);
                        }
                    }
                }
            }
            else
            {
                if (ItemID == "0" || ItemID == "")
                {
                    tmpItemlist.AddRange(myAucs.Select(kv => new AuctionEntry(kv.Value, kv.Key, 0, 0)));
                }
                else
                {
                    string[] entries = ItemID.Split(',');
                    if (entries.Length > 0)
                    {
                        foreach (var entry in entries)
                        {
                            uint id;
                            uint.TryParse(entry.Trim(), out id);
                            if (myAucs.ContainsKey(id))
                            {
                                tmpItemlist.Add(new AuctionEntry(myAucs[id], id, 0, 0));
                            }
                        }
                    }
                }
            }
            return(tmpItemlist);
        }
Esempio n. 6
0
        //indexs are {0}=ItemsCounter,NumOfItemToBuy, {1}=ItemID, {2}=maxBuyout, {3}=BidOnItem ? 1 : 0

        private bool BuyFromAH(BuyItemEntry bie)
        {
            bool done = false;

            if (!_queueTimer.IsRunning)
            {
                string lua = string.Format("QueryAuctionItems(\"{0}\" ,nil,nil,nil,nil,nil,{1}) return 1",
                                           bie.Name.ToFormatedUTF8(), _page);
                Lua.GetReturnVal <int>(lua, 0);
                Professionbuddy.Debug("Searching AH for {0}", bie.Name);
                _queueTimer.Start();
            }
            else if (_queueTimer.ElapsedMilliseconds <= 10000)
            {
                if (Lua.GetReturnVal <int>("if CanSendAuctionQuery('list') == 1 then return 1 else return 0 end ", 0) ==
                    1)
                {
                    _totalAuctions = Lua.GetReturnVal <int>("return GetNumAuctionItems('list')", 1);
                    _queueTimer.Stop();
                    _queueTimer.Reset();
                    if (_totalAuctions > 0)
                    {
                        string lua = string.Format(BuyFromAHLuaFormat,
                                                   _counter, bie.BuyAmount, bie.Id, MaxBuyout.TotalCopper,
                                                   BidOnItem ? 1 : 0);
                        _counter = Lua.GetReturnVal <int>(lua, 0);
                        if (_counter == -1 || ++_page >= (int)Math.Ceiling((double)_totalAuctions / 50))
                        {
                            done = true;
                        }
                    }
                    else
                    {
                        done = true;
                    }
                }
            }
            else
            {
                done = true;
            }
            if (done)
            {
                _queueTimer    = new Stopwatch();
                _totalAuctions = 0;
                _counter       = 0;
                _page          = 0;
            }
            return(done);
        }
Esempio n. 7
0
        bool BuyFromAH(BuyItemEntry bie)
        {
            bool done = false;

            if (!queueTimer.IsRunning)
            {
                string lua = string.Format("QueryAuctionItems(\"{0}\" ,nil,nil,nil,nil,nil,{1}) return 1",
                                           bie.Name.ToFormatedUTF8(), page);
                Lua.GetReturnVal <int>(lua, 0);
                Professionbuddy.Debug("Searching AH for {0}", bie.Name);
                queueTimer.Start();
            }
            else if (queueTimer.ElapsedMilliseconds <= 10000)
            {
                if (Lua.GetReturnVal <int>("if CanSendAuctionQuery('list') == 1 then return 1 else return 0 end ", 0) == 1)
                {
                    totalAuctions = Lua.GetReturnVal <int>("return GetNumAuctionItems('list')", 1);
                    queueTimer.Stop();
                    queueTimer.Reset();
                    if (totalAuctions > 0)
                    {
                        string lua = string.Format("local A,totalA= GetNumAuctionItems('list') local amountBought={0} local want={1} local each={3} local useBid={4} local buyPrice=0 for index=1, A do local name, _, count,_,_,_,minBid,minInc, buyoutPrice,bidNum,isHighBidder,_,_ = GetAuctionItemInfo('list', index) if useBid == 1 and buyoutPrice > each*count and isHighBidder == nil then if bidNum == nil then buyPrice =minBid + minInc else buyPrice = bidNum + minInc end else buyPrice = buyoutPrice end if name == \"{2}\" and buyPrice > 0 and buyPrice <= each*count and amountBought < want then amountBought = amountBought + count PlaceAuctionBid('list', index,buyPrice) end if amountBought >=  want then return -1 end end return amountBought",
                                                   counter, bie.BuyAmount, bie.Name.ToFormatedUTF8(), MaxBuyout.TotalCopper, BidOnItem == true ? 1 : 0);
                        //string lua = string.Format("local A,totalA= GetNumAuctionItems('list') local amountBought={0} local want={1} local each={3} local useBid={4} for index=1, A do local name, _, count,_,_,_,minBid,minIncreament, buyoutPrice,_,_,_,_ = GetAuctionItemInfo('list', index) if name == \"{2}\" and ((buyoutPrice > 0 and buyoutPrice <= each*count) or (useBid==1 and (minBid+minIncreament) <= each*count)) and amountBought < want then amountBought = amountBought + count if useBid==1 and buyoutPrice > each*count then PlaceAuctionBid('list', index, minBid+minIncreament) else PlaceAuctionBid('list', index, buyoutPrice) end end if amountBought >=  want then return -1 end end return amountBought",
                        //    counter, bie.BuyAmount, bie.Name, MaxBuyout.TotalCopper, BidOnItem == true ? 1 : 0);
                        counter = Lua.GetReturnVal <int>(lua, 0);
                        if (counter == -1 || ++page >= (int)Math.Ceiling((double)totalAuctions / 50))
                        {
                            done = true;
                        }
                    }
                    else
                    {
                        done = true;
                    }
                }
            }
            else
            {
                done = true;
            }
            if (done)
            {
                queueTimer    = new Stopwatch();
                totalAuctions = 0;
                counter       = 0;
                page          = 0;
            }
            return(done);
        }
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                if (Lua.GetReturnVal <int>("if AuctionFrame and AuctionFrame:IsVisible() == 1 then return 1 else return 0 end ", 0) == 0)
                {
                    MoveToAh();
                }
                else if (Lua.GetReturnVal <int>("if CanSendAuctionQuery('owner') == 1 then return 1 else return 0 end ", 0) == 1)
                {
                    if (ToScanItemList == null)
                    {
                        ToScanItemList   = BuildScanItemList();
                        ToCancelItemList = new List <AuctionEntry>();
                    }

                    if (ToScanItemList.Count > 0)
                    {
                        AuctionEntry ae       = ToScanItemList[0];
                        bool         scanDone = ScanAh(ref ae);
                        ToScanItemList[0] = ae; // update
                        if (scanDone)
                        {
                            ToCancelItemList.Add(ae);
                            ToScanItemList.RemoveAt(0);
                        }
                        if (ToScanItemList.Count == 0)
                        {
                            Professionbuddy.Debug("Finished scanning for items");
                        }
                    }
                    else
                    {
                        if (ToCancelItemList.Count == 0)
                        {
                            ToScanItemList = null;
                            IsDone         = true;
                            return(RunStatus.Failure);
                        }
                        else if (CancelAuction(ToCancelItemList[0]))
                        {
                            ToCancelItemList.RemoveAt(0);
                        }
                    }
                }
                return(RunStatus.Running);
            }
            return(RunStatus.Failure);
        }
Esempio n. 9
0
        private bool ScanAh(ref AuctionEntry ae)
        {
            bool scanned = false;

            if (!_queueTimer.IsRunning)
            {
                string lua = string.Format("QueryAuctionItems(\"{0}\" ,nil,nil,nil,nil,nil,{1}) return 1",
                                           ae.Name.ToFormatedUTF8(), _page);
                Lua.GetReturnVal <int>(lua, 0);
                Professionbuddy.Debug("Searching AH for {0}", ae.Name);
                _queueTimer.Start();
            }
            else if (_queueTimer.ElapsedMilliseconds <= 10000)
            {
                using (new FrameLock())
                {
                    if (
                        Lua.GetReturnVal <int>("if CanSendAuctionQuery('list') == 1 then return 1 else return 0 end ", 0) ==
                        1)
                    {
                        _queueTimer.Reset();
                        _totalAuctions = Lua.GetReturnVal <int>("return GetNumAuctionItems('list')", 1);
                        string lua = string.Format(ScanAHFormatLua, ae.LowestBo, ae.MyAuctions, ae.Id,
                                                   IgnoreStackSizeBelow, StackSize);
                        List <string> retVals = Lua.GetReturnValues(lua);
                        uint.TryParse(retVals[0], out ae.LowestBo);
                        uint.TryParse(retVals[1], out ae.MyAuctions);
                        if (++_page >= (int)Math.Ceiling((double)_totalAuctions / 50))
                        {
                            scanned = true;
                        }
                    }
                }
            }
            else
            {
                scanned = true;
            }
            // reset to default values in preparations for next scan
            if (scanned)
            {
                Professionbuddy.Debug("lowest buyout {0}", ae.LowestBo);
                _queueTimer.Stop();
                _queueTimer.Reset();
                _totalAuctions = 0;
                _page          = 0;
            }
            return(scanned);
        }
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         try
         {
             Professionbuddy.ChangeSecondaryBot(BotName);
         }
         finally
         {
             IsDone = true;
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 11
0
 protected virtual bool CanRun(object context)
 {
     try
     {
         return(CanRunDelegate(context));
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             Professionbuddy.Err("If Condition: {0} ,Err:{1}", Condition, ex);
         }
         return(false);
     }
 }
Esempio n. 12
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (_sub == null)
         {
             if (!GetSubRoutine())
             {
                 Professionbuddy.Err("{0}: {1}.", Pb.Strings["Error_SubroutineNotFound"], SubRoutineName);
                 IsDone = true;
             }
         }
         if (!_ranonce)
         {
             // make sure all actions within the subroutine are reset before we start.
             if (_sub != null)
             {
                 _sub.Reset();
             }
             _ranonce = true;
         }
         if (_sub != null)
         {
             if (!_sub.IsRunning)
             {
                 _sub.Start(SubRoutineName);
             }
             try
             {
                 _sub.Tick(SubRoutineName);
             }
             catch (ThreadAbortException)
             {
                 return(RunStatus.Success);
             }
             catch
             {
             }
             IsDone = _sub.IsDone;
             // we need to reset so calls to the sub from other places can
             if (!IsDone)
             {
                 return(RunStatus.Success);
             }
         }
     }
     return(RunStatus.Failure);
 }
Esempio n. 13
0
 protected virtual bool CanRun(object context)
 {
     try
     {
         return(CanRunDelegate(context));
     }
     catch (Exception ex)
     {
         if (ex.GetType() != typeof(ThreadAbortException))
         {
             Professionbuddy.Err("{0}: {1}\nErr:{2}", Professionbuddy.Instance.Strings["FlowControl_If_LongName"],
                                 Condition, ex);
         }
         return(false);
     }
 }
Esempio n. 14
0
        private List <AuctionEntry> BuildScanItemList()
        {
            var            tmpItemlist = new List <AuctionEntry>();
            List <WoWItem> itemList;

            if (UseCategory)
            {
                itemList = ObjectManager.Me.BagItems.
                           Where(i => !i.IsSoulbound && !i.IsConjured && !i.IsDisabled &&
                                 !Pb.ProtectedItems.Contains(i.Entry) &&
                                 i.ItemInfo.ItemClass == Category && SubCategoryCheck(i)).ToList();
                foreach (WoWItem item in itemList)
                {
                    if (!_containsItem(item, tmpItemlist))
                    {
                        tmpItemlist.Add(new AuctionEntry(item.Name, item.Entry, 0, 0));
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries.Length > 0)
                {
                    foreach (string entry in entries)
                    {
                        uint id;
                        uint.TryParse(entry.Trim(), out id);
                        itemList =
                            ObjectManager.Me.BagItems.Where(i => !i.IsSoulbound && !i.IsConjured && i.Entry == id).
                            ToList();
                        if (itemList.Count > 0)
                        {
                            tmpItemlist.Add(new AuctionEntry(itemList[0].Name, itemList[0].Entry, 0, 0));
                        }
                    }
                }
                else
                {
                    Professionbuddy.Err(Pb.Strings["Error_NoItemEntries"]);
                    IsDone = true;
                }
            }
            return(tmpItemlist);
        }
        Dictionary <uint, int> BuildItemList()
        {
            Dictionary <uint, int> itemList    = new Dictionary <uint, int>();
            IEnumerable <WoWItem>  tmpItemlist = from item in me.BagItems
                                                 where !item.IsConjured && !item.IsSoulbound && !item.IsDisabled
                                                 select item;

            if (UseCategory)
            {
                foreach (WoWItem item in tmpItemlist)
                {
                    if (!Pb.ProtectedItems.Contains(item.Entry) && item.ItemInfo.ItemClass == Category &&
                        subCategoryCheck(item) && !itemList.ContainsKey(item.Entry))
                    {
                        itemList.Add(item.Entry, Amount);
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries != null && entries.Length > 0)
                {
                    foreach (var entry in entries)
                    {
                        uint temp = 0;
                        uint.TryParse(entry.Trim(), out temp);
                        itemList.Add(temp, Amount);
                    }
                }
                else
                {
                    Professionbuddy.Err("No ItemIDs are specified");
                    IsDone = true;
                }
            }
            Professionbuddy.Debug("List of items to deposit to bank");
            foreach (var item in itemList)
            {
                Professionbuddy.Debug("Item:{0} Amount:{1}", item.Key, item.Value);
            }
            Professionbuddy.Debug("End of list");
            return(itemList);
        }
Esempio n. 16
0
        public static bool CanDisenchant(this WoWItem item)
        {
            if (item.ItemInfo.StatsCount == 0 && item.ItemInfo.RandomPropertiesId == 0)
            {
                //Professionbuddy.Log("We cannot disenchant {0} found in bag {1} at slot {2} because it has no stats.",
                //    item.Name, item.BagIndex + 1, item.BagSlot + 1);
                return(false);
            }
            int enchantingLevel = ObjectManager.Me.GetSkill(SkillLine.Enchanting).CurrentValue;

            int[,] deList = null;
            if (item.Quality == WoWItemQuality.Uncommon)
            {
                deList = UncommonItemDeList;
            }
            else if (item.Quality == WoWItemQuality.Rare)
            {
                deList = RareItemDeList;
            }
            else if (item.Quality == WoWItemQuality.Epic)
            {
                deList = EpicItemDeList;
            }
            // returns true if item is found in the dictionary and player meets the level requirement
            if (deList != null)
            {
                int x      = 0;
                int iLevel = item.ItemInfo.Level;
                for (x = 0; x < deList.Length / 2; x++)
                {
                    int a = deList[x, 1];
                    if (iLevel <= deList[x, 1])
                    {
                        Professionbuddy.Log("We can disenchant {0} found in bag {1} at slot {2}",
                                            item.Name, item.BagIndex + 1, item.BagSlot + 1);
                        return(enchantingLevel >= deList[x, 0]);
                    }
                }
            }
            Professionbuddy.Log("We cannot disenchant {0} found in bag {1} at slot {2}",
                                item.Name, item.BagIndex + 1, item.BagSlot + 1);
            return(false);
        }
Esempio n. 17
0
        private Dictionary <uint, int> BuildItemList()
        {
            var itemList = new Dictionary <uint, int>();
            IEnumerable <WoWItem> tmpItemlist = from item in Me.BagItems
                                                where !item.IsConjured && !item.IsSoulbound && !item.IsDisabled
                                                select item;

            if (UseCategory)
            {
                foreach (WoWItem item in tmpItemlist)
                {
                    if (!Pb.ProtectedItems.Contains(item.Entry) && item.ItemInfo.ItemClass == Category &&
                        SubCategoryCheck(item) && !itemList.ContainsKey(item.Entry))
                    {
                        itemList.Add(item.Entry, Mail == DepositWithdrawAmount.Amount
                                                     ? Amount
                                                     : Util.GetCarriedItemCount(item.Entry));
                    }
                }
            }
            else
            {
                string[] entries = ItemID.Split(',');
                if (entries.Length > 0)
                {
                    foreach (string entry in entries)
                    {
                        uint itemID;
                        uint.TryParse(entry.Trim(), out itemID);
                        itemList.Add(itemID, Mail == DepositWithdrawAmount.Amount
                                                 ? Amount
                                                 : Util.GetCarriedItemCount(itemID));
                    }
                }
                else
                {
                    Professionbuddy.Err("No ItemIDs are specified");
                    IsDone = true;
                }
            }
            return(itemList);
        }
Esempio n. 18
0
        public static bool CanDisenchant(this WoWItem item, int skillLevel)
        {
            ItemInfo itemInfo = item.ItemInfo;

            if (itemInfo.StatsCount == 0 && itemInfo.RandomPropertiesId == 0 && itemInfo.RandomSuffixId == 0)
            {
                //Professionbuddy.Log("We cannot disenchant {0} found in bag {1} at slot {2} because it has no stats.",
                //    item.Name, item.BagIndex + 1, item.BagSlot + 1);
                return(false);
            }
            int[,] deList = null;
            if (item.Quality == WoWItemQuality.Uncommon)
            {
                deList = UncommonItemDeList;
            }
            else if (item.Quality == WoWItemQuality.Rare)
            {
                deList = RareItemDeList;
            }
            else if (item.Quality == WoWItemQuality.Epic)
            {
                deList = EpicItemDeList;
            }
            // returns true if item is found in the dictionary and player meets the level requirement
            if (deList != null)
            {
                int x;
                int iLevel = item.ItemInfo.Level;
                for (x = 0; x < deList.Length / 2; x++)
                {
                    if (iLevel <= deList[x, 1] && skillLevel >= deList[x, 0])
                    {
                        Professionbuddy.Log("We can disenchant {0} found in bag {1} at slot {2}",
                                            item.Name, item.BagIndex + 1, item.BagSlot + 1);
                        return(true);
                    }
                }
            }
            Professionbuddy.Log("We cannot disenchant {0} found in bag {1} at slot {2}. SkillLevel: {3}",
                                item.Name, item.BagIndex + 1, item.BagSlot + 1, skillLevel);
            return(false);
        }
        void MoveToBanker()
        {
            WoWPoint  movetoPoint = loc;
            WoWObject bank        = GetLocalBanker();

            if (bank != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(me.Location, bank.Location, 3);
            }
            // search the database
            else if (movetoPoint == WoWPoint.Zero)
            {
                if (Bank == BankType.Personal)
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestBanker, NpcEntry);
                }
                else
                {
                    movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestGB, NpcEntry);
                }
            }
            if (movetoPoint == WoWPoint.Zero)
            {
                IsDone = true;
                Professionbuddy.Err("Unable to find bank");
            }
            if (movetoPoint.Distance(ObjectManager.Me.Location) > 4)
            {
                Util.MoveTo(movetoPoint);
            }
            // since there are many personal bank replacement addons I can't just check if frame is open and be generic.. using events isn't reliable
            else if (bank != null)
            {
                bank.Interact();
            }
            else
            {
                IsDone = true;
                Logging.Write(System.Drawing.Color.Red, "Unable to find a banker at location. aborting");
            }
        }
Esempio n. 20
0
        private List <uint> BuildItemList()
        {
            var list = new List <uint>();

            string[] entries = ItemID.Split(',');
            if (entries.Length > 0)
            {
                foreach (string entry in entries)
                {
                    uint temp;
                    uint.TryParse(entry.Trim(), out temp);
                    list.Add(temp);
                }
            }
            else
            {
                Professionbuddy.Err(Pb.Strings["Error_NoItemEntries"]);
                IsDone = true;
            }
            return(list);
        }
        List <uint> BuildItemList()
        {
            List <uint> list = new List <uint>();

            string[] entries = ItemID.Split(',');
            if (entries != null && entries.Length > 0)
            {
                foreach (var entry in entries)
                {
                    uint temp = 0;
                    uint.TryParse(entry.Trim(), out temp);
                    list.Add(temp);
                }
            }
            else
            {
                Professionbuddy.Err("No ItemIDs are specified");
                IsDone = true;
            }
            return(list);
        }
Esempio n. 22
0
 protected override RunStatus Run(object context)
 {
     try
     {
         if (!IsDone)
         {
             try
             {
                 Action(this);
             }
             catch (Exception ex)
             {
                 Professionbuddy.Err("Custom:({0})\n{1}", Code, ex);
             }
             IsDone = true;
         }
         return(RunStatus.Failure);
     }
     catch (Exception ex) { Logging.Write(System.Drawing.Color.Red, "There was an exception while executing a CustomAction\n{0}", ex); }
     return(RunStatus.Failure);
 }
Esempio n. 23
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         if (_sub == null)
         {
             if (!GetSubRoutine())
             {
                 Professionbuddy.Err("Unable to find Subroutine with name: {0}.", SubRoutineName);
                 IsDone = true;
             }
         }
         if (!ranonce)
         {
             // make sure all actions within the subroutine are reset before we start.
             _sub.Reset();
             ranonce = true;
         }
         if (_sub != null)
         {
             if (!_sub.IsRunning)
             {
                 _sub.Start(SubRoutineName);
             }
             try
             {
                 _sub.Tick(SubRoutineName);
             }
             catch { IsDone = true; _sub.Reset(); return(RunStatus.Failure); }
             IsDone = _sub.IsDone;
             // we need to reset so calls to the sub from other places can
             if (!IsDone)
             {
                 return(RunStatus.Running);
             }
         }
     }
     return(RunStatus.Failure);
 }
        static public void ChangeBot(string name)
        {
            if (_botIsChanging)
            {
                Professionbuddy.Log("Must wait for previous ChangeBot to finish before calling ChangeBot again.");
                return;
            }
            BotBase bot = BotManager.Instance.Bots.FirstOrDefault(b => b.Key.Contains(name)).Value;

            if (BotManager.Current == bot)
            {
                return;
            }
            if (bot != null)
            {
                // execute from GUI thread since this thread will get aborted when switching bot
                _botIsChanging = true;
                Application.Current.Dispatcher.BeginInvoke(
                    new System.Action(() => {
                    bool isRunning = TreeRoot.IsRunning;
                    BotManager.Instance.SetCurrent(bot);
                    if (isRunning)
                    {
                        Professionbuddy.Log("Restarting HB in 3 seconds");
                        _timer = new Timer(new TimerCallback((o) => {
                            TreeRoot.Start();
                            Professionbuddy.Log("Restarting HB");
                            _botIsChanging = false;
                        }), null, 3000, Timeout.Infinite);
                    }
                }
                                      ));
                Professionbuddy.Log("Changing bot to {0}", name);
            }
            else
            {
                Professionbuddy.Err("Bot {0} does not exist", name);
            }
        }
Esempio n. 25
0
        private void MoveToBanker()
        {
            WoWPoint  movetoPoint = _loc;
            WoWObject bank        = GetLocalBanker();

            if (bank != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, bank.Location, 3);
            }
            // search the database
            else if (movetoPoint == WoWPoint.Zero)
            {
                movetoPoint =
                    MoveToAction.GetLocationFromDB(
                        Bank == BankType.Personal
                            ? MoveToAction.MoveToType.NearestBanker
                            : MoveToAction.MoveToType.NearestGB, NpcEntry);
            }
            if (movetoPoint == WoWPoint.Zero)
            {
                IsDone = true;
                Professionbuddy.Err(Pb.Strings["Error_UnableToFindBank"]);
            }
            if (movetoPoint.Distance(ObjectManager.Me.Location) > 4)
            {
                Util.MoveTo(movetoPoint);
            }
            // since there are many personal bank replacement addons I can't just check if frame is open and be generic.. using events isn't reliable
            else if (bank != null)
            {
                bank.Interact();
            }
            else
            {
                IsDone = true;
                Professionbuddy.Err(Pb.Strings["Error_UnableToFindBank"]);
            }
        }
        void MoveToAh()
        {
            WoWPoint movetoPoint = _loc;
            WoWUnit  auctioneer;

            if (AutoFindAh || movetoPoint == WoWPoint.Zero)
            {
                auctioneer = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.IsAuctioneer && o.IsAlive)
                             .OrderBy(o => o.Distance).FirstOrDefault();
            }
            else
            {
                auctioneer = ObjectManager.GetObjectsOfType <WoWUnit>().Where(o => o.IsAuctioneer &&
                                                                              o.Location.Distance(_loc) < 5)
                             .OrderBy(o => o.Distance).FirstOrDefault();
            }
            if (auctioneer != null)
            {
                movetoPoint = WoWMathHelper.CalculatePointFrom(Me.Location, auctioneer.Location, 3);
            }
            else if (movetoPoint == WoWPoint.Zero)
            {
                movetoPoint = MoveToAction.GetLocationFromDB(MoveToAction.MoveToType.NearestAH, 0);
            }
            if (movetoPoint == WoWPoint.Zero)
            {
                Professionbuddy.Err("Unable to location Auctioneer, Maybe he's dead?");
            }
            if (movetoPoint.Distance(ObjectManager.Me.Location) > 4.5)
            {
                Util.MoveTo(movetoPoint);
            }
            else if (auctioneer != null)
            {
                auctioneer.Interact();
            }
        }
        public void ReadXml(XmlReader reader)
        {
            reader.MoveToContent();
            reader.ReadStartElement("Professionbuddy");
            PrioritySelector ps = (PrioritySelector)DecoratedChild;

            while (reader.NodeType == XmlNodeType.Element || reader.NodeType == XmlNodeType.Comment)
            {
                if (reader.NodeType == XmlNodeType.Comment)
                {
                    ps.AddChild(new Comment(reader.Value));
                    reader.Skip();
                }
                else
                {
                    Type type = Type.GetType("HighVoltz.Composites." + reader.Name);
                    if (type != null)
                    {
                        IPBComposite comp = (IPBComposite)Activator.CreateInstance(type);
                        if (comp != null)
                        {
                            comp.ReadXml(reader);
                            ps.AddChild((Composite)comp);
                        }
                    }
                    else
                    {
                        Professionbuddy.Err("PB:Failed to load type {0}", type);
                    }
                }
            }
            if (reader.NodeType == XmlNodeType.Element)
            {
                reader.ReadEndElement();
            }
        }
Esempio n. 28
0
        // 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 ");
                Professionbuddy.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);

            // -1 means no item was found.
            if (retVal == -1)
            {
                Professionbuddy.Log("No items with entry {0} could be found in gbank", id);
            }
            return(retVal);
        }
 string GetLocalName(uint id)
 {
     Professionbuddy.Debug("Queueing server for Item: {0}", id);
     return(TradeSkillFrame.GetItemCacheName(id));
 }
Esempio n. 30
0
 protected PBAction()
 {
     HasRunOnce = false;
     Pb = Professionbuddy.Instance;
     Properties = new PropertyBag();
 }
        protected override RunStatus Run(object context)
        {
            if (!IsDone)
            {
                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(RunStatus.Failure);
                    }
                    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(((double)(lowestBo * UndercutPrecent) / 100d));
                            }
                            ae.Bid = (uint)((double)(ae.Buyout * BidPrecent) / 100d);
                            bool enoughItemsPosted = AmountType == AmountBasedType.Amount && ae.myAuctions >= Amount;
                            bool tooLowBuyout      = !PostIfBelowMinBuyout && lowestBo < MinBuyout.TotalCopper;

                            Professionbuddy.Debug("PB: PostIfBelowMinBuyout:{0} ", PostIfBelowMinBuyout, MinBuyout.TotalCopper);
                            Professionbuddy.Debug("PB: lowestBo:{0}  MinBuyout.TotalCopper: {1}", lowestBo, MinBuyout.TotalCopper);
                            Professionbuddy.Debug("PB: tooLowBuyout:{0} enoughItemsPosted: {1}", enoughItemsPosted, enoughItemsPosted);

                            if (!enoughItemsPosted && !tooLowBuyout)
                            {
                                ToSellItemList.Add(ae);
                            }
                            else
                            {
                                Professionbuddy.Log("Skipping {0} since {1}",
                                                    ae.Name, tooLowBuyout ? string.Format("lowest buyout:{0} is below 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)
                        {
                            Professionbuddy.Debug("Finished scanning for items");
                        }
                    }
                    if (ToSellItemList.Count > 0)
                    {
                        if (SellOnAh(ToSellItemList[0]))
                        {
                            Professionbuddy.Log("Selling {0}", ToSellItemList[0]);
                            ToSellItemList.RemoveAt(0);
                        }
                    }
                }
                return(RunStatus.Running);
            }
            return(RunStatus.Failure);
        }
Esempio n. 32
0
 protected override RunStatus Run(object context)
 {
     if (!IsDone)
     {
         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)
             {
                 Professionbuddy.Err("MoveToAction Failed.. Unable to find location from Database");
                 IsDone = true;
                 return(RunStatus.Failure);
             }
         }
         if (Entry > 0 && (!ObjectManager.Me.GotTarget || ObjectManager.Me.CurrentTarget.Entry != Entry))
         {
             WoWUnit unit = ObjectManager.GetObjectsOfType <WoWUnit>(true).FirstOrDefault(u => u.Entry == Entry);
             if (unit != null)
             {
                 unit.Target();
             }
         }
         float speed = ObjectManager.Me.MovementInfo.CurrentSpeed;
         Navigator.PathPrecision = speed > 7 ? (SpeedModifer * speed) / 7f : SpeedModifer;
         if (ObjectManager.Me.Location.Distance(_loc) > Navigator.PathPrecision)
         {
             if (Pathing == NavigationType.ClickToMove)
             {
                 WoWMovement.ClickToMove(_loc);
             }
             else
             {
                 Util.MoveTo(_loc);
             }
         }
         else
         {
             if (!_concludingSw.IsRunning)
             {
                 _concludingSw.Start();
             }
             else if (_concludingSw.ElapsedMilliseconds >= 2000)
             {
                 IsDone = true;
                 Professionbuddy.Log("MoveTo Action completed for type {0}", MoveType);
                 _concludingSw.Stop();
                 _concludingSw.Reset();
             }
         }
         if (!IsDone)
         {
             return(RunStatus.Success);
         }
     }
     return(RunStatus.Failure);
 }