Beispiel #1
0
        static void EnterMatch()
        {
            int position = _position;

            if (position == 0)
            {
                Console.WriteLine("Invalid position 0");
                return;
            }

            while (position > 2)
            {
                ScreenUtility.Drag(1500, 914, 1500, 314);
                position--;
            }

            if (position == 1)
            {
                ScreenUtility.Click(1500, 314);
            }
            else if (position == 2)
            {
                ScreenUtility.Click(1500, 914);
            }
        }
Beispiel #2
0
        static void OpenChest(int runCount)
        {
            //bool existsMainWindow = MainWindowUtility.ExistsMainWindow();

            //if (!existsMainWindow && !ScreenUtility.IsForegroundFullScreen())
            //{
            //    Console.WriteLine("No main window exist");
            //    return;
            //}

            //if (existsMainWindow)
            //{
            //    MainWindowUtility.ActivateAndWait();
            //}

            // open chest
            for (int i = 0; i < runCount; ++i)
            {
                ScreenUtility.Click(177, 877);

                AutoItX.Sleep(1000);
            }

            return;
        }
Beispiel #3
0
        static void EnterSelectFightType()
        {
            ScreenUtility.Click(1562, 814);

            // wait for 2s to ensure all fights are populated.
            AutoItX.Sleep(2000);
        }
        public void EnableAutomation()
        {
            ScreenUtility.Click(xCord, yCord);

            recentColors.Clear();

            AutomationEnabled = true;
        }
Beispiel #5
0
        private static bool FuzzyMatch(int x, int y, uint color)
        {
            if (color == PixelColor.SpecialColorForPredicator)
            {
                return(DetectSpecialState(x, y));
            }

            Point newPos = ScreenUtility.Convert(new Point(x, y));

            Console.WriteLine("<{0}, {1}> -> <{2}, {3}>", x, y, newPos.X, newPos.Y);
            if (ScreenUtility.IsFullScreen)
            {
                Point[] points = new Point[]
                {
                    new Point(newPos.X - 1, newPos.Y),
                    new Point(newPos.X, newPos.Y),
                    new Point(newPos.X + 1, newPos.Y),
                    new Point(newPos.X, newPos.Y - 1),
                    new Point(newPos.X, newPos.Y + 1),
                };

                foreach (var point in points)
                {
                    if (color == PixelColor.SpecialColorForDetectingChange ||
                        color == PixelColor.SpecialColorForDetectingUnchange)
                    {
                        if (DetectChangeOrNotChange(point.X, point.Y, color))
                        {
                            return(true);
                        }
                    }
                    else
                    {
                        uint trueColor = GetPixelColor(point.X, point.Y);

                        if (trueColor == color)
                        {
                            return(true);
                        }
                    }
                }

                return(false);
            }
            else
            {
                if (color == PixelColor.SpecialColorForDetectingChange ||
                    color == PixelColor.SpecialColorForDetectingUnchange)
                {
                    return(DetectChangeOrNotChange(x, y, color));
                }
                else
                {
                    return(color == GetPixelColor(x, y));
                }
            }
        }
Beispiel #6
0
        static void SelectPartner()
        {
            // select first partner if possible
            ScreenUtility.Click(1120, 280);
            AutoItX.Sleep(1000);

            // click 开始
            ScreenUtility.Click(1478, 920);
        }
Beispiel #7
0
        static void RunDungeon()
        {
            var weekday = DateTime.Now.DayOfWeek;

            if (weekday == DayOfWeek.Saturday || weekday == DayOfWeek.Sunday)
            {
                return;
            }

            if (!ScreenUtility.IsForegroundFullScreen())
            {
                MainWindowUtility.ActivateAndWait();
            }

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.MainWindow, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.MainWindow, GameState.FightTypeSelection, EnterSelectFightType, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(
                    GameState.FightTypeSelection,
                    GameState.DailyDungeon,
                    EnterMatch,
                    MaxSingleTaskTime))
            {
                return;
            }

            SelectDungeonGrade(weekday);

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.SelectEquipment, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.SelectEquipment, GameState.SelectPartner, SelectedEquipment, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.SelectPartner, GameState.Fighting, SelectPartner, MaxSingleTaskTime, TouchToContinue))
            {
                return;
            }

            Fight();

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.MainWindow, null, MaxSingleTaskTime))
            {
                return;
            }
        }
Beispiel #8
0
        static void SelectWantedDifficulty()
        {
            // 选择 传奇
            ScreenUtility.Click(400, 900);
            AutoItX.Sleep(1000);

            // for rush
            // ScreenUtility.Click(1020, 920);
            // click 开始游戏
            ScreenUtility.Click(1460, 920);
        }
Beispiel #9
0
        public static void Handle(GameState state)
        {
            if (_dialogs.ContainsKey(state))
            {
                var tuple = _dialogs[state];

                Console.WriteLine("{0} handled, click on <{1}, {2}>", state, tuple.Item1, tuple.Item2);

                ScreenUtility.Click(tuple.Item1, tuple.Item2);
            }
        }
Beispiel #10
0
        public bool WaitForState(GameState currentState, GameState nextState, Action action, int waitTimeInMs, Action actionForUnknown = null)
        {
            DateTime startTime = DateTime.Now;

            Console.WriteLine("WaitForState: {0} -> {1}", currentState, nextState);

            do
            {
                if (!MainWindowUtility.ExistsMainWindow() && !ScreenUtility.IsForegroundFullScreen())
                {
                    Console.WriteLine("No main window and no full screen foreground window");
                    return(false);
                }

                var activeState = Detector.Detect();

                Console.WriteLine("{0} State: {1}", DateTime.Now, activeState);

                if (activeState == nextState)
                {
                    return(true);
                }

                if (DialogHandler.IsDialogState(activeState))
                {
                    DialogHandler.Handle(activeState);
                }

                if (activeState == currentState &&
                    currentState != GameState.Unknown &&
                    action != null)
                {
                    Console.WriteLine("Execute action {0}", action);
                    action();
                }

                if (activeState == GameState.Unknown && actionForUnknown != null)
                {
                    Console.WriteLine("Execute action for unknown {0}", actionForUnknown);
                    actionForUnknown();
                }

                var elapsedTime = DateTime.Now - startTime;
                if (elapsedTime.TotalMilliseconds > waitTimeInMs)
                {
                    return(false);
                }

                AutoIt.AutoItX.Sleep(1000);
            } while (true);
        }
Beispiel #11
0
 static void GoBackMainWindowFromWantedOrElementChallenge()
 {
     // 点击 返回主界面箭头
     ScreenUtility.Click(76, 94);
 }
Beispiel #12
0
        static void RunElementChallenge()
        {
            if (!ScreenUtility.IsForegroundFullScreen())
            {
                MainWindowUtility.ActivateAndWait();
            }

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.MainWindow, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.MainWindow, GameState.FightTypeSelection, EnterSelectFightType, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(
                    GameState.FightTypeSelection,
                    GameState.ElementChallenge,
                    EnterMatch,
                    MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.ElementChallenge, GameState.ElementChallengeLevel, SelectElementChallenge, MaxSingleTaskTime))
            {
                return;
            }

            SelectElementChallengeLevel();

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.SelectEquipment, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.SelectEquipment, GameState.SelectPartner, SelectedEquipment, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.SelectPartner, GameState.Fighting, SelectPartner, MaxSingleTaskTime, TouchToContinue))
            {
                return;
            }

            Fight();

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.ElementChallengeCompleted, null, MaxSingleTaskTime))
            {
                return;
            }

            AutoItX.Sleep(1000);
            AutoItX.Send("{ESC}");

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.ElementChallenge, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.ElementChallenge, GameState.MainWindow, GoBackMainWindowFromWantedOrElementChallenge, MaxSingleTaskTime))
            {
                return;
            }
        }
Beispiel #13
0
        static void RunWanted()
        {
            if (!ScreenUtility.IsForegroundFullScreen())
            {
                MainWindowUtility.ActivateAndWait();
            }

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.MainWindow, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.MainWindow, GameState.FightTypeSelection, EnterSelectFightType, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(
                    GameState.FightTypeSelection,
                    GameState.WantedChallenge,
                    EnterMatch,
                    MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.WantedChallenge, GameState.WantedDifficulty, SelectWanted, MaxSingleTaskTime))
            {
                return;
            }

            SelectWantedDifficulty();

            //for (; ; )
            //{
            //    // rush only
            //    SelectWantedDifficulty();
            //    AutoItX.Sleep(1000);
            //    _stateWaiter.WaitForState(GameState.Unknown, GameState.WantedDifficulty, null, MaxSingleTaskTime);
            //}

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.SelectEquipment, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.SelectEquipment, GameState.SelectPartner, SelectedEquipment, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.SelectPartner, GameState.Fighting, SelectPartner, MaxSingleTaskTime, TouchToContinue))
            {
                return;
            }

            Fight();

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.WantedChallenge, null, MaxSingleTaskTime))
            {
                return;
            }

            if (!_stateWaiter.WaitForState(GameState.WantedChallenge, GameState.MainWindow, GoBackMainWindowFromWantedOrElementChallenge, MaxSingleTaskTime))
            {
                return;
            }

            return;
        }
Beispiel #14
0
 static void TouchToContinue()
 {
     ScreenUtility.Click(1168, 985);
 }
Beispiel #15
0
 static void SelectedEquipment()
 {
     // click the 继续
     ScreenUtility.Click(1478, 920);
 }
Beispiel #16
0
 static void SelectElementChallengeLevel()
 {
     // click 开始游戏
     ScreenUtility.Click(1460, 920);
 }
Beispiel #17
0
 static void SelectElementChallenge()
 {
     // click 开始
     ScreenUtility.Click(1260, 928);
 }
Beispiel #18
0
 static void SelectWanted()
 {
     // click 开始
     ScreenUtility.Click(1260, 928);
 }
Beispiel #19
0
        static void SelectDungeonGrade(DayOfWeek weekday)
        {
            if (weekday == DayOfWeek.Sunday || weekday == DayOfWeek.Saturday)
            {
                throw new ArgumentOutOfRangeException();
            }

            int grade = _grade;

            switch (weekday)
            {
            case DayOfWeek.Monday:
            {
                int xCord = 1478;
                // 普通,困难,专家
                int[] yCords = new int[] { 310, 460, 610 };

                if (grade > yCords.Length)
                {
                    grade = yCords.Length;
                }

                ScreenUtility.Click(xCord, yCords[grade - 1]);
                AutoItX.Sleep(1000);
                break;
            }

            case DayOfWeek.Tuesday:
            {
                int xCord = 1478;
                // 普通,困难,专家,史诗
                int[] yCords = new int[] { 310, 460, 610, 760 };

                if (grade > yCords.Length)
                {
                    grade = yCords.Length;
                }

                ScreenUtility.Click(xCord, yCords[grade - 1]);
                AutoItX.Sleep(1000);
                break;
            }

            case DayOfWeek.Wednesday:
            {
                int xCord = 1478;
                // 普通,困难,专家,史诗
                int[] yCords = new int[] { 310, 460, 610, 760 };

                if (grade > yCords.Length)
                {
                    grade = yCords.Length;
                }

                ScreenUtility.Click(xCord, yCords[grade - 1]);
                AutoItX.Sleep(1000);
                break;
            }

            case DayOfWeek.Thursday:
            {
                //Thursday: 清流 320,烈焰440, 自然 560, 半影 680, 多彩810
                int   xCord  = 1478;
                int[] yCords = new int[5] {
                    320, 440, 560, 680, 810
                };

                if (grade > yCords.Length)
                {
                    grade = yCords.Length;
                }

                ScreenUtility.Click(xCord, yCords[grade - 1]);
                AutoItX.Sleep(1000);
                break;
            }

            case DayOfWeek.Friday:
            {
                int xCord = 1478;
                // 史诗, 传奇
                int[] yCords = new int[] { 320, 470 };

                if (grade > yCords.Length)
                {
                    grade = yCords.Length;
                }

                ScreenUtility.Click(xCord, yCords[grade - 1]);
                AutoItX.Sleep(1000);
                break;
            }

            default:
                throw new ArgumentOutOfRangeException();
            }

            // click 继续
            ScreenUtility.Click(1478, 920);
        }
Beispiel #20
0
        static void Run(string target, JobType job)
        {
            bool existsMainWindow = MainWindowUtility.ExistsMainWindow();

            if (!existsMainWindow && !ScreenUtility.IsForegroundFullScreen())
            {
                if (!Launch(target))
                {
                    return;
                }
            }
            else
            {
                Console.WriteLine("Main windows had been opened");
            }

            if (existsMainWindow)
            {
                MainWindowUtility.ActivateAndWait();
            }

            var screenBounds = ScreenUtility.GetScreenBounds(null);

            Console.WriteLine("Screen: <{0}, {1}, {2}, {3}>",
                              screenBounds.Top, screenBounds.Left, screenBounds.Height, screenBounds.Width);

            IntPtr hwnd = IntPtr.Zero;

            if (!ScreenUtility.IsForegroundFullScreen())
            {
                hwnd = MainWindowUtility.GetMainWindowHandle();

                var windowBounds = ScreenUtility.GetWindowBounds(hwnd);
                var clientRect   = ScreenUtility.GetClientRect(hwnd);

                Console.WriteLine("Window: <{0}, {1}, {2}, {3}>",
                                  windowBounds.Top, windowBounds.Left, windowBounds.Height, windowBounds.Width);

                Console.WriteLine("Client: <{0}, {1}, {2}, {3}>",
                                  clientRect.Top, clientRect.Left, clientRect.Height, clientRect.Width);

                ScreenUtility.SetScreenAttribute(screenBounds, false);
                //int left, width, top, height;
                //if (windowBounds.Left < 0)
                //{
                //    width = windowBounds.Width - 2 * Math.Abs(windowBounds.Left);
                //    left = 0;
                //}
                //else
                //{
                //    width = windowBounds.Width;
                //    left = windowBounds.Left;
                //}

                //if (windowBounds.Top < 0)
                //{
                //    height = windowBounds.Height - 2 * Math.Abs(windowBounds.Top);
                //    top = 0;
                //}
                //else
                //{
                //    height = windowBounds.Height;
                //    top = windowBounds.Top;
                //}
            }
            else
            {
                ScreenUtility.SetScreenAttribute(screenBounds, true);
            }

            if (!_stateWaiter.WaitForState(GameState.Unknown, GameState.MainWindow, null, MaxSingleTaskTime))
            {
                Console.WriteLine("Failed to show main window although main window was opened");
                MainWindowUtility.Close();

                return;
            }

            if (job == JobType.ElementChallenge)
            {
                //if (!CheatEngineUtility.EnableCheating())
                //{
                //    Console.WriteLine("Cheating is not enabled, can't run element challenging job");
                //    return;
                //}
            }

            if (!ScreenUtility.IsForegroundFullScreen())
            {
                MainWindowUtility.ActivateAndWait();
            }

            Run(job);

            if (_stateWaiter.Detector.Detect() != GameState.MainWindow)
            {
                Console.WriteLine("Failed to go back main window after run");
                MainWindowUtility.Close();

                return;
            }
        }