Esempio n. 1
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;
            }
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        static void Fight()
        {
            AutomationDetector detector = new AutomationDetector();

            // 启用自动化
            detector.EnableAutomation();

            DateTime startBattleTime = DateTime.Now;

            Random rand = new Random();

            string[] keys = new string[] { "a", "s", "w", "d" };

            // wait for combat ending
            while (_stateWaiter.Detector.Detect() == GameState.Fighting)
            {
                // 判断 自动 是否被启用
                if (!detector.AutomationEnabled)
                {
                    // send some random keys before enable automation
                    for (int i = 0; i < 100; ++i)
                    {
                        AutoItX.Send(keys[rand.Next() % keys.Length]);
                    }

                    detector.EnableAutomation();
                }
                else
                {
                    detector.Detect();
                }

                AutoItX.Sleep(500);

                DateTime current    = DateTime.Now;
                TimeSpan battleTime = current - startBattleTime;

                if (battleTime.TotalMinutes > 10)
                {
                    // overtime, must be stuck
                    Console.WriteLine("Battle over 10 minutes, might be stuck");
                    MainWindowUtility.Close();
                    return;
                }
            }
        }
Esempio n. 4
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;
            }
        }
Esempio n. 5
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;
        }
Esempio n. 6
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;
            }
        }