Beispiel #1
0
        private void AwakeningLoopThread(List <AwakeItem> preferredAwakeItemList)
        {
            Queue <List <Awake> > latestAwakes = new Queue <List <Awake> >();

            try
            {
                LogHelper.AppendLog(_ui, "Bot has started");

                Win32.SetForegroundWindow(_botConfig.Process.MainWindowHandle);

                AwakeningResolver awakeResolver = new AwakeningResolver(_serverConfig);

                while (_isRunning)
                {
                    if (latestAwakes.Count >= 3)
                    {
                        // Check if the 3 awakes in the queue are all the same
                        var firstAwakes = latestAwakes.ElementAt(0);

                        bool anyNotEqual = false;

                        for (int i = 1; i < latestAwakes.Count; ++i)
                        {
                            var awakes = latestAwakes.ElementAt(i);

                            bool sameSize = awakes.Count == firstAwakes.Count;

                            if (!sameSize)
                            {
                                anyNotEqual = true;
                                break;
                            }

                            for (int j = 0; j < awakes.Count; ++j)
                            {
                                bool equalText  = awakes[j].Text == firstAwakes[j].Text;
                                bool equalValue = awakes[j].Value == firstAwakes[j].Value;
                                if (!equalText || !equalValue)
                                {
                                    anyNotEqual = true;
                                    break;
                                }
                            }
                        }

                        if (!anyNotEqual)
                        {
                            LogHelper.AppendLog(_ui, "Same awake the last 3 times, stopping the bot.");
                            StopBot();
                            return;
                        }
                    }

                    var stopWatch = Stopwatch.StartNew();

                    MouseHelper.SetCursorPosition(new Point(_botConfig.ItemPosition.X + 3, _botConfig.ItemPosition.Y));

                    Thread.Sleep(50);

                    MouseHelper.SetCursorPosition(new Point(_botConfig.ItemPosition.X - 3, _botConfig.ItemPosition.Y));

                    Thread.Sleep(50);

                    // Hover over the item to check the awake
                    MouseHelper.SetCursorPosition(_botConfig.ItemPosition);

                    // Add specified delay to compensate for laggy server
                    int delayBeforeSnapshot = 0;

                    _ui.Invoke(new Action(() =>
                    {
                        delayBeforeSnapshot = _ui.TrackBarBeforeSnapshotMsDelay.Value;
                    }));

                    Thread.Sleep(delayBeforeSnapshot);

                    Bitmap bmp = awakeResolver.SnapshotRectangle(_botConfig.AwakeReadRectangle);

                    UpdateStepUi(_ui.PictureBoxDebug1, _ui.LabelStep1, bmp);

                    bmp = awakeResolver.DifferentiateAwakeText(bmp);

                    UpdateStepUi(_ui.PictureBoxDebug2, _ui.LabelStep2, bmp);

                    bmp = awakeResolver.CropBitmapSmart(bmp);

                    UpdateStepUi(_ui.PictureBoxDebug3, _ui.LabelStep3, bmp);

                    float newDPI = 300;

                    Size newSize = bmp.Size;

                    float inchesWidth  = (float)bmp.Width / bmp.HorizontalResolution;
                    float inchesHeight = (float)bmp.Height / bmp.VerticalResolution;

                    newSize.Width  = (int)(newDPI * inchesWidth);
                    newSize.Height = (int)(newDPI * inchesHeight);

                    bmp = awakeResolver.ResizeImage(bmp, newSize);
                    bmp.SetResolution(newDPI, newDPI);

                    string awakeText = awakeResolver.GetAwakening(bmp);

                    LogHelper.AppendLog(_ui, "Raw awake In-game text: \"" + awakeText + "\"");

                    List <Awake> itemAwakes = new AwakeningParser(_serverConfig, awakeText).GetCompletedAwakes();

                    if (latestAwakes.Count >= 3)
                    {
                        // Remove the object that was the first one in
                        latestAwakes.Dequeue();
                    }

                    latestAwakes.Enqueue(itemAwakes);

                    string awakeAchieved = "";

                    for (int i = 0; i < itemAwakes.Count; ++i)
                    {
                        awakeAchieved += itemAwakes[i].ToString() + (i == (itemAwakes.Count - 1) ? "" : " | ");
                    }

                    if (awakeAchieved.Length <= 0)
                    {
                        awakeAchieved = "No awake found\n";
                        LogHelper.AppendLog(_ui, awakeAchieved);
                    }

                    LogHelper.AppendLog(_ui, awakeAchieved);

                    bool shouldBreak = false;

                    if (_ui.CheckboxStopIfAwakeUnrecognized.Checked)
                    {
                        foreach (var awake in itemAwakes)
                        {
                            if (awake.TypeIndex == -1)
                            {
                                StopBot();

                                LogHelper.AppendLog(_ui, "An awake was not recognized, stopping the bot.");

                                shouldBreak = true;

                                break;
                            }
                        }
                    }

                    if (shouldBreak)
                    {
                        break;
                    }

                    var preferredAwakesList = ConvertAwakeItemListToAwakeList(preferredAwakeItemList);

                    // Go through each awake group and see if any of them meets the requirements
                    foreach (var preferredAwake in preferredAwakesList)
                    {
                        // Check if awake meets the requirements
                        if (AwakeMeetsRequirements(itemAwakes, preferredAwake))
                        {
                            LogHelper.AppendLog(_ui, "Preferred awake was successfully achieved");

                            stopWatch.Stop();

                            UpdateIterationTimeLabels(stopWatch.ElapsedMilliseconds);

                            shouldBreak = true;

                            break;
                        }
                    }

                    if (shouldBreak)
                    {
                        break;
                    }

                    LogHelper.AppendLog(_ui, "Preferred awake was not achieved");

                    // Doubleclick reversion scroll
                    MouseHelper.LeftClick(_botConfig.ReversionPosition);
                    MouseHelper.LeftClick(_botConfig.ReversionPosition);

                    const int ms = 200;

                    Thread.Sleep(ms);

                    // Click item with reversion
                    MouseHelper.LeftClick(_botConfig.ItemPosition);

                    // Wait until the reversion is done on the item
                    Thread.Sleep(_serverConfig.ScrollFinishDelay);

                    if (_ui.ComboBoxSupportAugmentation.Checked)
                    {
                        MouseHelper.LeftClick(_botConfig.AwakeScrollPosition);
                    }
                    else
                    {
                        // Doubleclick awake scroll
                        MouseHelper.LeftClick(_botConfig.AwakeScrollPosition);
                        MouseHelper.LeftClick(_botConfig.AwakeScrollPosition);
                    }

                    Thread.Sleep(ms);

                    // Click item with awake scroll
                    MouseHelper.LeftClick(_botConfig.ItemPosition);

                    Thread.Sleep(ms);

                    MouseHelper.SetCursorPosition(new Point(_botConfig.ItemPosition.X + 200, _botConfig.ItemPosition.Y + 200));

                    Thread.Sleep(ms);

                    MouseHelper.SetCursorPosition(_botConfig.ItemPosition);

                    // Wait until the awake is done on the item
                    Thread.Sleep(_serverConfig.ScrollFinishDelay);

                    bmp.Dispose();

                    stopWatch.Stop();

                    UpdateIterationTimeLabels(stopWatch.ElapsedMilliseconds);
                }

                StopBot();

                LogHelper.AppendLog(_ui, "Bot has finished");
            }
            catch (Exception ex)
            {
                StopBot();
                LogHelper.AppendLog(_ui, ex.ToString());
            }
        }
Beispiel #2
0
        private void AwakeningLoopThread(List <AwakeItem> preferredAwakeItemList)
        {
            try
            {
                LogHelper.AppendLog(_ui, "Bot has started");

                Win32.SetForegroundWindow(_botConfig.Process.MainWindowHandle);

                AwakeningResolver awakeResolver = new AwakeningResolver(_serverConfig);

                while (_isRunning)
                {
                    var stopWatch = Stopwatch.StartNew();

                    MouseHelper.SetCursorPosition(new Point(_botConfig.ItemPosition.X + 3, _botConfig.ItemPosition.Y));

                    Thread.Sleep(50);

                    MouseHelper.SetCursorPosition(new Point(_botConfig.ItemPosition.X - 3, _botConfig.ItemPosition.Y));

                    Thread.Sleep(50);

                    // Hover over the item to check the awake
                    MouseHelper.SetCursorPosition(_botConfig.ItemPosition);

                    // Add specified delay to compensate for laggy server
                    int delayBeforeSnapshot = 0;

                    _ui.Invoke(new Action(() =>
                    {
                        delayBeforeSnapshot = _ui.TrackBarBeforeSnapshotMsDelay.Value;
                    }));

                    Thread.Sleep(delayBeforeSnapshot);

                    Bitmap bmp = awakeResolver.SnapshotRectangle(_botConfig.AwakeReadRectangle);

                    UpdateStepUi(_ui.PictureBoxDebug1, _ui.LabelStep1, bmp);

                    bmp = awakeResolver.DifferentiateAwakeText(bmp);

                    UpdateStepUi(_ui.PictureBoxDebug2, _ui.LabelStep2, bmp);

                    bmp = awakeResolver.CropBitmapSmart(bmp);

                    UpdateStepUi(_ui.PictureBoxDebug3, _ui.LabelStep3, bmp);

                    string awakeText = awakeResolver.GetAwakening(bmp);

                    LogHelper.AppendLog(_ui, "Raw awake In-game text: \"" + awakeText + "\"");

                    List <Awake> itemAwakes = new AwakeningParser(_serverConfig, awakeText).GetCompletedAwakes();

                    string awakeAchieved = "";

                    for (int i = 0; i < itemAwakes.Count; ++i)
                    {
                        awakeAchieved += itemAwakes[i].ToString() + (i == (itemAwakes.Count - 1) ? "" : " | ");
                    }

                    if (awakeAchieved.Length <= 0)
                    {
                        awakeAchieved = "No awake found\n";
                        LogHelper.AppendLog(_ui, awakeAchieved);
                    }

                    LogHelper.AppendLog(_ui, awakeAchieved);

                    bool shouldBreak = false;

                    if (_ui.CheckboxStopIfAwakeUnrecognized.Checked)
                    {
                        foreach (var awake in itemAwakes)
                        {
                            if (awake.TypeIndex == -1)
                            {
                                StopBot();

                                LogHelper.AppendLog(_ui, "An awake was not recognized, stopping the bot.");

                                shouldBreak = true;

                                break;
                            }
                        }
                    }

                    if (shouldBreak)
                    {
                        break;
                    }

                    var preferredAwakesList = ConvertAwakeItemListToAwakeList(preferredAwakeItemList);

                    // Go through each awake group and see if any of them meets the requirements
                    foreach (var preferredAwake in preferredAwakesList)
                    {
                        // Check if awake meets the requirements
                        if (AwakeMeetsRequirements(itemAwakes, preferredAwake))
                        {
                            LogHelper.AppendLog(_ui, "Preferred awake was successfully achieved");

                            stopWatch.Stop();

                            UpdateIterationTimeLabels(stopWatch.ElapsedMilliseconds);

                            shouldBreak = true;

                            break;
                        }
                    }

                    if (shouldBreak)
                    {
                        break;
                    }

                    LogHelper.AppendLog(_ui, "Preferred awake was not achieved");

                    // Doubleclick reversion scroll
                    MouseHelper.LeftClick(_botConfig.ReversionPosition);
                    MouseHelper.LeftClick(_botConfig.ReversionPosition);

                    const int ms = 200;

                    Thread.Sleep(ms);

                    // Click item with reversion
                    MouseHelper.LeftClick(_botConfig.ItemPosition);

                    // Wait until the reversion is done on the item
                    Thread.Sleep(_serverConfig.ScrollFinishDelay);

                    if (_ui.ComboBoxSupportAugmentation.Checked)
                    {
                        MouseHelper.LeftClick(_botConfig.AwakeScrollPosition);
                    }
                    else
                    {
                        // Doubleclick awake scroll
                        MouseHelper.LeftClick(_botConfig.AwakeScrollPosition);
                        MouseHelper.LeftClick(_botConfig.AwakeScrollPosition);
                    }

                    Thread.Sleep(ms);

                    // Click item with awake scroll
                    MouseHelper.LeftClick(_botConfig.ItemPosition);

                    Thread.Sleep(ms);

                    MouseHelper.SetCursorPosition(new Point(_botConfig.ItemPosition.X + 200, _botConfig.ItemPosition.Y + 200));

                    Thread.Sleep(ms);

                    MouseHelper.SetCursorPosition(_botConfig.ItemPosition);

                    // Wait until the awake is done on the item
                    Thread.Sleep(_serverConfig.ScrollFinishDelay);

                    bmp.Dispose();

                    stopWatch.Stop();

                    UpdateIterationTimeLabels(stopWatch.ElapsedMilliseconds);
                }

                StopBot();

                LogHelper.AppendLog(_ui, "Bot has finished");
            }
            catch (Exception ex)
            {
                StopBot();
                LogHelper.AppendLog(_ui, ex.ToString());
            }
        }