CampahApp.Interaction.BidOnItem C# (CSharp) Méthode

BidOnItem() private méthode

private BidOnItem ( CampahApp.ItemRequest item ) : void
item CampahApp.ItemRequest
Résultat void
        private void BidOnItem(ItemRequest item)
        {
            if (FFACEInstance.Instance.Item.InventoryMax == FFACEInstance.Instance.Item.InventoryCount)
                StopBuying("Inventory Full");
            if (item.BoughtCount >= item.Quantity)
                return;
            {
                string strstack = ".";
                if (item.Stack)
                    strstack = " stack.";
                CampahStatus.Instance.Status = "Finding item: " + item.ItemData.Name + strstack;
            }
            if (!GotoMenu(item.ItemData.Address))
            {
                GotoBidMenu();
                return;
            }
            Thread.Sleep((int)CampahStatus.Instance.GlobalDelay);
            int[] ids = ReadAHItems();
            if (ids.Length < 3 || ids[0] == ids[2])
            {
                //StopBuying("Error! AH item array could not be read. Try zoning or logging out");
                CampahStatus.SetStatus("Error! AH item array could not be read. Try zoning or logging out\r\n\t\tSkipping to the next item.");
                return;
            }
            int index = Array.IndexOf(ids, item.ItemData.ID) + 1;
            int stack = 0;
            if (item.Stack && item.ItemData.Stackable)
            {
                stack = 1;
            }
            AuctionHouse.MenuIndex = index + stack;
            Thread.Sleep((int)CampahStatus.Instance.GlobalDelay);
            int bid;
            {
                var parselowball = new Regex("[^0-9]*([0-9]+)(%)?.*");
                Match matches = parselowball.Match(CampahStatus.Instance.LowballBid);
                int lowballamount;
                if (matches.Groups.Count > 1 && !string.IsNullOrEmpty(matches.Groups[1].Value) && int.TryParse(matches.Groups[1].Value, out lowballamount))
                {
                    //int lowballamount = int.Parse(matches.Groups[1].Value);
                    if (matches.Groups[2].Value == "%" && lowballamount < 100)
                        bid = item.Minimum * lowballamount / 100;
                    else
                        bid = lowballamount;
                    if (bid > item.Minimum)
                        bid = item.Minimum;
                }
                else
                    bid = item.Minimum;
            }
            if (bid < 1)  //safety check on bid
                bid = 1;
            bool firstbid = true;
            bool hasitems = false;
            Chatlog.Instance.ClearChatAlerts();

            while (bid <= item.Maximum && item.BoughtCount < item.Quantity)
            {
                if (FFACEInstance.Instance.Item.InventoryMax == FFACEInstance.Instance.Item.InventoryCount)
                    StopBuying("Inventory Full");
                if (AuctionHouse.MenuIndex != index + stack)
                {
                    CampahStatus.Instance.Status = "Error: Mismatch IDs, Skipping...";
                    break;
                }

                FFACEInstance.Instance.Windower.SendKeyPress(KeyCode.EnterKey);
                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                AuctionHouse.MenuIndex = 2;
                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                FFACEInstance.Instance.Windower.SendKeyPress(KeyCode.EnterKey);
                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay*2);
                if (!hasitems)
                {
                    if (FFACEInstance.Instance.Menu.Selection != "Price Set")
                    {
                        CampahStatus.Instance.Status = item.ItemData.Name + " is unavailble on AH, Skipping...";
                        FFACEInstance.Instance.Windower.SendKeyPress(KeyCode.EscapeKey);
                        Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                        break;
                    }

                    hasitems = true;
                }
                while (FFACEInstance.Instance.Menu.Selection != "Price Set")
                {
                    Thread.Sleep(250);
                }

                AuctionHouse.BidValue = bid;
            CampahStatus.Instance.Status = string.Format("Bidding {0}g on {1}{2}", bid, item.ItemData.Name, item.Stack ? " stack." : ".");

                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                FFACEInstance.Instance.Windower.SendKeyPress(KeyCode.EnterKey);
                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                AuctionHouse.MenuIndex = 1;
                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                var alert = new ChatAlert(new Regex(@".*You(.*)buy the .* for ([0-9,]*) gil\."));
                Chatlog.Instance.AddAlert(alert);
                FFACEInstance.Instance.Windower.SendKeyPress(KeyCode.EnterKey);
                Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                FFACEInstance.Instance.Item.GetInventoryItemCount((ushort) item.ItemData.ID);
                var overrideAlert = false;
                int time = 0;
                while (!overrideAlert && !alert.Completed)
                {
                    Thread.Sleep((int) CampahStatus.Instance.GlobalDelay);
                    time += (int) CampahStatus.Instance.GlobalDelay;
                    if (time >= 20000)
                        overrideAlert = true;
                }
                if (overrideAlert)
                {
                    CampahStatus.SetStatus("An error occurred while parsing bid results\r\n\t\tRemoving item from bid list");
                    item.BoughtCount = item.Quantity;
                    break;
                }

                if (alert.Result.Groups[1].Value.Contains("unable"))
                {
                    if (bid < item.Minimum)
                        bid = item.Minimum;
                    else
                        bid += item.Increment;
                    if (bid > item.Maximum && bid < (item.Maximum + item.Increment))
                        bid = item.Maximum;
                    firstbid = false;
                    if (bid <= item.Maximum)
                    {
                        CampahStatus.Instance.Status = "Bid rejected, increasing bid to " + bid + "g.";
                    }
                    else
                    {
                        CampahStatus.Instance.Status = "Bid rejected, skipping to the next item...";
                    }
                }

                else
                {
                    var strstack = "";
                    if (item.Stack)
                    {
                        strstack = " stack";
                    }
                    CampahStatus.Instance.Status = string.Format("You bought the {0}{1} for {2}g.", item.ItemData.Name, strstack, bid);
                    item.BoughtCount++;
                    item.BoughtCost += bid;
                    RunningData.Instance.TotalSpent += bid;
                    if (item.Minimum >= bid && firstbid && CampahStatus.Instance.CheapO)
                    {
                        bid -= item.Increment;
                        if (bid < 1)
                        {
                            bid = 1;
                        }
                    }
                }
                Chatlog.Instance.ClearChatAlerts();
            }
        }