Ejemplo n.º 1
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);
                    }
                }
            }
        }