Beispiel #1
0
        private bool CheckCurrency()
        {
            // TODO create new check currency which check currencys with control + c and checks name and stack size
            List <Position> found_positions = null;

            List <Currency_ExRate> main_currs = new List <Currency_ExRate>();

            //set main currencies

            main_currs.Add(CurrentCustomer.Currency);

            if (CurrentCustomer.Currency.Name != "chaos orb")
            {
                main_currs.Add(_CurrenciesService.GetCurrencyByName("chaos"));
            }

            if (CurrentCustomer.Currency.Name != "divine orb")
            {
                main_currs.Add(_CurrenciesService.GetCurrencyByName("divine"));
            }

            if (CurrentCustomer.Currency.Name != "exalted orb")
            {
                main_currs.Add(_CurrenciesService.GetCurrencyByName("exalted"));
            }

            if (CurrentCustomer.Currency.Name != "orb of alchemy")
            {
                main_currs.Add(_CurrenciesService.GetCurrencyByName("alchemy"));
            }

            if (CurrentCustomer.Currency.Name == "exalted orb")
            {
                //Win32.ChatCommand($"@{CurrentCustomer.Nickname} exalted orb = {_CurrenciesService.GetCurrencyByName("exalted").ChaosEquivalent}");

                main_currs.Add(_CurrenciesService.GetCurrencyByName("exalted"));
            }

            Bitmap screen_shot = null;

            int x_trade = 220;
            int y_trade = 140;

            for (int i = 0; i < 30; i++)
            {
                double price = 0;

                foreach (Currency_ExRate cur in main_currs)
                {
                    if (!System.IO.File.Exists(cur.ImageName))
                    {
                        continue;
                    }
                    Win32.MoveTo(0, 0);

                    Thread.Sleep(100);

                    screen_shot = ScreenCapture.CaptureRectangle(x_trade, y_trade, 465, 200);

                    found_positions = OpenCV_Service.FindCurrencies(screen_shot, cur.ImageName, 0.6);

                    foreach (Position pos in found_positions)
                    {
                        Win32.MoveTo(x_trade + pos.Left + pos.Width / 2, y_trade + pos.Top + pos.Height / 2);

                        Thread.Sleep(100);

                        string ctrlc = CommandsService.CtrlC_PoE();
                        // TODO fix this currency stack count
                        var curbyname = _CurrenciesService.GetCurrencyByName(CommandsService.GetNameItem_PoE(ctrlc));

                        if (curbyname == null)
                        {
                            price += CommandsService.GetSizeInStack(ctrlc) * cur.ChaosEquivalent;
                        }

                        else
                        {
                            price += CommandsService.GetSizeInStack(ctrlc) * curbyname.ChaosEquivalent;
                        }


                        screen_shot.Dispose();
                    }

                    if (price >= CurrentCustomer.Chaos_Price && price != 0)
                    {
                        break;
                    }
                }

                _loggerService.Log("Bid price (in chaos) = " + price + " Necessary (in chaos) = " + CurrentCustomer.Chaos_Price);

                if (price >= CurrentCustomer.Chaos_Price)
                {
                    _loggerService.Log("I want accept trade");

                    screen_shot = ScreenCapture.CaptureRectangle(200, 575, 130, 40);

                    Position pos = OpenCV_Service.FindObject(screen_shot, $"Assets/{Properties.Settings.Default.UI_Fragments}/accept_tradewindow.png");

                    if (pos.IsVisible)
                    {
                        Win32.MoveTo(210 + pos.Left + pos.Width / 2, 580 + pos.Top + pos.Height / 2);

                        Thread.Sleep(100);

                        Win32.DoMouseClick();

                        screen_shot.Dispose();

                        var timer = DateTime.Now + new TimeSpan(0, 0, 5);

                        while (CurrentCustomer.TradeStatus != CustomerInfo.TradeStatuses.ACCEPTED)
                        {
                            if (CurrentCustomer.TradeStatus == CustomerInfo.TradeStatuses.CANCELED)
                            {
                                return(false);
                            }

                            if (DateTime.Now > timer)
                            {
                                break;
                            }
                        }

                        if (CurrentCustomer.TradeStatus == CustomerInfo.TradeStatuses.ACCEPTED)
                        {
                            return(true);
                        }

                        else
                        {
                            continue;
                        }
                    }
                }
                else
                {
                    screen_shot.Dispose();
                }

                Thread.Sleep(500);
            }

            Win32.SendKeyInPoE("{ESC}");

            return(false);
        }