private void OnFaceDetected(Rect obj)
        {
            var sw = (image.ActualWidth / orgWidth);
            var sh = (image.ActualHeight / orgHeight);


            loadingRect.Width  = (int)(obj.Width * sw);
            loadingRect.Height = (int)(obj.Height * sh);

            faceRect.Width  = startStepButton.Width = loadingRect.Width;
            faceRect.Height = startStepButton.Height = loadingRect.Height;

            var faceX = obj.Location.X * sw;
            var faceY = obj.Location.Y * sh;

            faceRect.SetValue(Canvas.TopProperty, faceY);
            faceRect.SetValue(Canvas.LeftProperty, faceX);

            loadingRect.SetValue(Canvas.TopProperty, faceY);
            loadingRect.SetValue(Canvas.LeftProperty, faceX);

            startStepButton.SetValue(Canvas.TopProperty, faceY);
            startStepButton.SetValue(Canvas.LeftProperty, faceX);

            percentageText.SetValue(Canvas.TopProperty, faceY - percentageText.DesiredSize.Height - 4);
            percentageText.SetValue(Canvas.LeftProperty, faceX + faceRect.Width / 2 - percentageText.DesiredSize.Width / 2);
        }
示例#2
0
        private void OnFaceDetected(Rect obj)
        {
            var sw = (image.ActualWidth / orgWidth);
            var sh = (image.ActualHeight / orgHeight);

            var faceX = obj.Location.X * sw;
            var faceY = obj.Location.Y * sh;

            faceRect.Visibility = Visibility.Visible;
            faceRect.Width      = (int)(obj.Width * sw);
            faceRect.Height     = (int)(obj.Height * sh);
            faceRect.SetValue(Canvas.TopProperty, faceY);
            faceRect.SetValue(Canvas.LeftProperty, faceX);
        }
        protected override void MakeActionSequenceTree()
        {
            ActionSequenceTree fromMain =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromMain]");
                AddSubJob(new JobMovePage(_form, Globals.MainPage, Globals.Menu, Globals.MenuPage));
            });

            ActionSequenceTree fromMenu =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromMenu]");
                AddSubJob(new JobMovePage(_form, Globals.MenuPage, Globals.MenuToItem, Globals.ItemPage));
            });

            ActionSequenceTree fromItem =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromItem]");

                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ItemSlot2, true));
                AddSubJob(new JobWaitTime(_form, 750));
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ItemSlot2, true));
                AddSubJob(new JobWaitTime(_form, 750));
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ItemSlot2, true));
                AddSubJob(new JobWaitTime(_form, 750));
            });

            ActionSequenceTree selectItem =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[selectItem]");
                if (_upgradeState != UpgradeState.Finished)
                {
                    var item = _upgradeItemOnState[_upgradeState];
                    AddSubJob(new JobMovePage(_form, Globals.ItemPage, item, Globals.ItemDetailPage));
                }
            });


            ActionSequenceTree fromItemDetail =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromItemDetail]");
                AddSubJob(new JobMovePage(_form, Globals.ItemDetailPage, Globals.ToUpgrade, Globals.ItemUpgradePage));
                AddSubJob(new JobWaitTime(_form, 750));
            });


            // upgrade
            ActionSequenceTree findItem =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[findItem]");
                AddSubJob(new JobTryFindOneOfSubImages(_form, _itemRanks));
            });

            ActionSequenceTree clickItem =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[clickItem]");
                OpenCvSharp.Rect rect = (OpenCvSharp.Rect)BlackBoard.Instance.Read(BlackBoard.UIRectBlackBoardID, this);

                int addX = 10;
                int addY = 20;

                var pos = Utils.RectToPos(rect.X + addX, rect.Y + addY, rect.Width, rect.Height);

                AddSubJob(new JobMoveAndClickMouse(_form, pos));
                AddSubJob(new JobWaitTime(_form, 500));
            });

            ActionSequenceTree upgrade =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[upgrade]");
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.StartUpgrade, true));
                AddSubJob(new JobWaitTime(_form, 500));
                AddSubJob(new JobCheckPage(_form, Globals.ItemUpgradeResultPage, 5000));
            });

            ActionSequenceTree checkLockPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkLockPage]");
                AddSubJob(new JobWaitTime(_form, 500));
                AddSubJob(new JobCheckPage(_form, Globals.ItemLockPage, 5000));
            });


            ActionSequenceTree exitResult =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitResult]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.ItemUpgradeResultPage,
                        Globals.OutFromUpgradeResult, Globals.ItemUpgradePage));
            });


            // exit
            ActionSequenceTree exitItemUpgrade =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitItemUpgrade]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.ItemUpgradePage,
                        Globals.BackInUpgradePage, Globals.ItemPage));
            });

            ActionSequenceTree checkUpgradeState =
                new ActionSequenceTree(() =>
            {
                AddSubJob(new JobCheckCondition(_form, () => { return(_upgradeState == UpgradeState.Finished); }));
            });

            ActionSequenceTree exitItemPage =
                new ActionSequenceTree(() =>
            {
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ItemSlot1, true));
                AddSubJob(new JobWaitTime(_form, 750));
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ItemSlot1, true));
                AddSubJob(new JobWaitTime(_form, 750));
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ItemSlot1, true));
                AddSubJob(new JobWaitTime(_form, 750));

                Console.WriteLine("[exitItemPage]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.ItemPage,
                        Globals.BackInItemPage, Globals.MenuPage));
            });

            ActionSequenceTree exitMenu =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitMenu]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.MenuPage,
                        Globals.BackInMenu, Globals.MainPage));
            });

            // if repair
            ActionSequenceTree exitLockPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitLockPage]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.ItemLockPage,
                        Globals.NoInItemLockPage, Globals.ItemUpgradePage));
            });

            ActionSequenceTree exitGetVisualPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitGetVisualPage]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.ItemGetVisualPage,
                        Globals.ExitItemGetVisual, Globals.ItemDetailPage));
            });


            fromMain.Completed       = fromMenu;
            fromMenu.Completed       = fromItem;
            fromItem.Completed       = selectItem;
            selectItem.Completed     = fromItemDetail;
            fromItemDetail.Completed = findItem;


            // upgrade
            findItem.Completed         = clickItem;
            findItem.ActionOnCompleted = () =>
            {
                _form.ItemUpgradeCnt = _form.ItemUpgradeCnt + 1;
                _nothingToUpgrade    = false;
            };

            clickItem.Completed     = upgrade;
            upgrade.Completed       = exitResult;
            upgrade.Failed          = checkLockPage;
            checkLockPage.Completed = exitLockPage;
            exitLockPage.Completed  = exitItemUpgrade;
            checkLockPage.Failed    = findItem;
            exitResult.Completed    = findItem;

            findItem.Failed = exitItemUpgrade;

            exitItemUpgrade.Completed         = checkUpgradeState;
            exitItemUpgrade.ActionOnCompleted = () =>
            {
                UpdateUpgradeState();
            };

            checkUpgradeState.Completed = exitItemPage;
            checkUpgradeState.Failed    = selectItem;

            exitItemPage.Completed     = exitMenu;
            exitMenu.ActionOnCompleted = () =>
            {
                if (_nothingToUpgrade)
                {
                    _returnState = State.Failed;
                }
                else
                {
                    _returnState = State.Completed;
                }
            };

            _currentAction = fromMain;

            // make repair map
            _repairMap[Globals.MenuPage]              = fromMenu;
            _repairMap[Globals.ItemPage]              = fromItem;
            _repairMap[Globals.ItemDetailPage]        = fromItemDetail;
            _repairMap[Globals.ItemUpgradePage]       = findItem;
            _repairMap[Globals.ItemLockPage]          = exitLockPage;
            _repairMap[Globals.ItemUpgradeResultPage] = exitResult;
            _repairMap[Globals.ItemGetVisualPage]     = exitGetVisualPage;
        }
示例#4
0
        protected override void MakeActionSequenceTree()
        {
            ActionSequenceTree fromTrial =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromTrial]");
                AddSubJob(new JobMovePage(_form, Globals.MainPage, Globals.Trial, Globals.TrialPage));
                AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.TrialPage }));
            });

            ActionSequenceTree findBeforeDrag =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[findBeforeDrag]");

                string what = "";
                if (_todo.TryGetValue(_currentState, out what))
                {
                    AddSubJob(new JobTryFindSubImage(_form, what));
                }
            });

            ActionSequenceTree click =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[click]");
                OpenCvSharp.Rect rect = (OpenCvSharp.Rect)BlackBoard.Instance.Read(BlackBoard.UIRectBlackBoardID, this);
                var pos = Utils.RectToPos(rect.X + 50, rect.Y + 100, rect.Width, rect.Height);
                AddSubJob(new JobMoveAndClickMouse(_form, pos));
            });


            ActionSequenceTree drag =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[drag]");
                AddSubJob(new JobWaitTime(_form, 1500));
                Drag(_form, this, new System.Drawing.Point(0, 0));
                AddSubJob(new JobWaitTime(_form, 1000));
                Drag(_form, this, new System.Drawing.Point(-100, 0));
                AddSubJob(new JobWaitTime(_form, 1000));
            });

            ActionSequenceTree findAfterDrag =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[findAfterDrag]");

                string what = "";
                if (_todo.TryGetValue(_currentState, out what))
                {
                    AddSubJob(new JobTryFindSubImage(_form, what));
                }
            });


            ActionSequenceTree fromTrialStage =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[fromTrialStage]");
                AddSubJob(new JobWaitTime(_form, 1500));
                Drag(_form, this, new System.Drawing.Point(0, 0));
                AddSubJob(new JobWaitTime(_form, 1000));
                Drag(_form, this, new System.Drawing.Point(-100, 0));
                AddSubJob(new JobWaitTime(_form, 1000));
            });

            ActionSequenceTree getCurrentPage =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[getCurrentPage]");
                AddSubJob(new JobWaitTime(_form, 3000));
                _currentPage = _form.CurrentPageName;
            });


            ActionSequenceTree start =
                new ActionSequenceTree(
                    () =>
            {
                Console.WriteLine("[start]  current page : " + _currentPage);

                string ui;
                if (_clickUI.TryGetValue(_currentPage, out ui))
                {
                    AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, ui, true));
                    AddSubJob(new JobWaitTime(_form, 1000));
                    AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, ui, true));
                    AddSubJob(new JobWaitTime(_form, 1000));
                }
            });

            ActionSequenceTree checkNoPageMove =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkCurrentPage]");
                AddSubJob(new JobCheckPage(_form, _currentPage, 5000));
            });


            ActionSequenceTree fromResult =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromResult]");

                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ToTrialFromTrialResult, true));
                AddSubJob(new JobWaitTime(_form, 1000));
                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.ToTrialFromTrialResult, true));
                AddSubJob(new JobWaitTime(_form, 1000));
            });

            ActionSequenceTree checkCurrentPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkCurrentPage]");
                AddSubJob(new JobCheckPage(_form, Globals.TrialPage, 8000));
            });

            ActionSequenceTree backToTrial =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[backToTrial]");

                AddSubJob(new JobMovePage(_form, _currentPage, Globals.BackInTrialLevelPages, Globals.TrialPage));
            });

            ActionSequenceTree checkCurrentState =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkCurrentState]");
                AddSubJob(new JobCheckCondition(_form, () => { return(_currentState == TrialState.Finished); }));
            });

            ActionSequenceTree exitTrial =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitTrial]");
                AddSubJob(new JobMovePage(_form, Globals.TrialPage, Globals.BackInTrial, Globals.MainPage));
            });

            fromTrial.Completed = checkCurrentState;

            checkCurrentState.Completed = exitTrial;
            checkCurrentState.Failed    = findBeforeDrag;

            findBeforeDrag.Completed     = click;
            findBeforeDrag.Failed        = drag;
            drag.Completed               = findAfterDrag;
            findAfterDrag.Completed      = click;
            findAfterDrag.Failed         = fromTrial;
            findAfterDrag.ActionOnFailed = () => { UpdateTrialState(); };

            click.Completed          = fromTrialStage;
            fromTrialStage.Completed = getCurrentPage;
            getCurrentPage.Completed = start;
            start.Completed          = checkNoPageMove;

            // not started
            checkNoPageMove.Completed = backToTrial;
            checkNoPageMove.Failed    = fromResult;

            fromResult.Completed = checkCurrentPage;

            checkCurrentPage.Completed    = fromTrial;
            checkCurrentPage.Failed       = backToTrial;
            backToTrial.Completed         = fromTrial;
            backToTrial.ActionOnCompleted = () => { UpdateTrialState(); };



            exitTrial.ActionOnCompleted = () =>
            {
                if (_currentState == TrialState.Finished)
                {
                    Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!");
                    _returnState = State.Completed;
                }
                else
                {
                    Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                    Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                    Console.WriteLine("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@");
                    _returnState = State.Failed;
                }
            };

            _currentAction = fromTrial;

            // make repair map
            _repairMap[Globals.TrialPage]            = fromTrial;
            _repairMap[Globals.TrialSweepAwayPage]   = fromTrialStage;
            _repairMap[Globals.TrialMansFightPage]   = fromTrialStage;
            _repairMap[Globals.TrialWomansFightPage] = fromTrialStage;
            _repairMap[Globals.TrialTwoDevilPage]    = fromTrialStage;
            //_repairMap[Globals.TrialBattleGodPage] = fromTrialStage;
            _repairMap[Globals.TrialStormEyePage] = fromTrialStage;
            _repairMap[Globals.TrialBloodyPage]   = fromTrialStage;
            _repairMap[Globals.TrialResultPage]   = fromResult;
        }
示例#5
0
 public static Rect ToRect(this OpenCvSharp.Rect r)
 {
     return(new Rect(r.X, r.Y, r.Width, r.Height));
 }
示例#6
0
        protected override void MakeActionSequenceTree()
        {
            ActionSequenceTree fromMain =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromMain]");
                AddSubJob(new JobMovePage(_form, Globals.MainPage, Globals.Cowork, Globals.CoworkPage));
                AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.CoworkPage }));
                AddSubJob(new JobMovePage(_form, Globals.CoworkPage, Globals.Party, Globals.PartyPage));
            });



            ActionSequenceTree dragForFindLevel =
                new ActionSequenceTree(
                    () =>
            {
                OpenCvSharp.Rect left;
                bool leftFlag =
                    _form.AllUIRects.TryGetValue(Globals.RaidDragLeftPos, out left);

                OpenCvSharp.Rect right;
                bool rightFlag =
                    _form.AllUIRects.TryGetValue(Globals.RaidDragRightPos, out right);

                if (leftFlag && rightFlag)
                {
                    if (_level == Globals.PLevel1 || _level == Globals.PLevel2)
                    {
                        var start = Utils.RectToPos(left.X, left.Y, left.Width, left.Height);
                        var end   = Utils.RectToPos(right.X, right.Y, right.Width, right.Height);
                        AddSubJob(new JobDrag(_form, start, end));
                    }
                    else
                    {
                        var start = Utils.RectToPos(right.X, right.Y, right.Width, right.Height);
                        var end   = Utils.RectToPos(left.X, left.Y, left.Width, left.Height);
                        AddSubJob(new JobDrag(_form, start, end));
                    }
                }
            });

            ActionSequenceTree findLevel =
                new ActionSequenceTree(
                    () =>
            {
                AddSubJob(new JobTryFindSubImage(_form, _level));
            });

            ActionSequenceTree clickLevel =
                new ActionSequenceTree(
                    () =>
            {
                OpenCvSharp.Rect rect = (OpenCvSharp.Rect)BlackBoard.Instance.Read(BlackBoard.UIRectBlackBoardID, this);
                var pos = Utils.RectToPos(rect.X, rect.Y, rect.Width, rect.Height);
                AddSubJob(new JobMoveAndClickMouse(_form, pos));
            });



            ActionSequenceTree fromParty =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromParty]");

                AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.PartyAward, true));
                AddSubJob(new JobWaitTime(_form, 1000));
            });

            ActionSequenceTree checkAwardPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkAwardPage]");

                AddSubJob(new JobCheckPage(_form, Globals.PartyRepeatAwardPage));
            });

            // if checkAwardPage completed
            ActionSequenceTree exitAwardPage =
                new ActionSequenceTree(() =>
            {
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.PartyRepeatAwardPage,
                        Globals.OutFromRepeatAward, Globals.PartyPage));
            });

            ActionSequenceTree clickStart =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[clickStart]");
                AddSubJob(new JobMovePage(_form, Globals.PartyPage, Globals.StartParty, new string[] { Globals.PartyRestrictedPage, Globals.UnknownPage }));
            });

            ActionSequenceTree checkPartyRestricted =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkPartyRestricted]");
                AddSubJob(new JobCheckPage(_form, Globals.PartyRestrictedPage));
            });

            // if checkPartyRestricted completed
            ActionSequenceTree exitPartyRestrictedPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitPartyRestrictedPage]");
                AddSubJob(
                    new JobMovePage(
                        _form,
                        Globals.PartyRestrictedPage,
                        Globals.NoInPartyRestrictedPage, Globals.PartyPage));
            });

            ActionSequenceTree exitPartyPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[exitPartyPage]");
                AddSubJob(new JobMovePage(_form, Globals.PartyPage, Globals.BackInParty, Globals.MainPage));
            });

            ActionSequenceTree fromStarted =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromStarted]");
                AddSubJob(
                    new JobCheckUntilMeetPage(
                        _form, new string[] { Globals.PartyResultPage }));
            });

            ActionSequenceTree fromResult =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromResult]");
                AddSubJob(new JobMovePage(_form, Globals.PartyResultPage, Globals.ToMainFromPartyResult, Globals.MainPage));
            });

            if (_form.SkipPartyLevelSelect)
            {
                fromMain.Completed = fromParty;
            }
            else
            {
                fromMain.Completed         = dragForFindLevel;
                dragForFindLevel.Completed = findLevel;
                findLevel.Completed        = clickLevel;
                clickLevel.Completed       = fromParty;
            }

            fromParty.Completed               = checkAwardPage;
            checkAwardPage.Completed          = exitAwardPage;
            checkAwardPage.Failed             = clickStart;
            exitAwardPage.Completed           = clickStart;
            clickStart.Completed              = checkPartyRestricted;
            checkPartyRestricted.Completed    = exitPartyRestrictedPage;
            checkPartyRestricted.Failed       = fromStarted;
            exitPartyRestrictedPage.Completed = exitPartyPage;
            fromStarted.Completed             = fromResult;
            fromResult.ActionOnCompleted      = () => { _returnState = State.Completed; };

            _currentAction = fromMain;

            // make repair map
            _repairMap[Globals.CoworkPage]           = fromMain;
            _repairMap[Globals.PartyPage]            = fromParty;
            _repairMap[Globals.PartyRepeatAwardPage] = exitAwardPage;
            _repairMap[Globals.PartyRestrictedPage]  = exitPartyRestrictedPage;
            _repairMap[Globals.PartyResultPage]      = fromResult;
        }
        protected override void MakeActionSequenceTree()
        {
            ActionSequenceTree checkEmulatorPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[checkEmulatorPage]");
                AddSubJob(new JobCheckPage(_form, Globals.EmulatorPage));
            });

            ActionSequenceTree killProcess =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[killProcess]");

                AddSubJob(new JobKillProcess(_form, MainForm.VirtualMachineProcess));
                AddSubJob(new JobWaitTime(_form, 1000));

                AddSubJob(new JobCheckCondition(
                              _form,
                              () => {
                    MainForm.HookStates hookState;
                    _form.HookProcessHandle(MainForm.VirtualMachineProcess, out hookState);
                    return(hookState == MainForm.HookStates.NoProcess);
                }));
            });


            ActionSequenceTree restartEmulator =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[restartEmulator]");
                AddSubJob(new JobExecuteProcess(_form, MainForm.VirtualMachineProcess));
            });

            ActionSequenceTree fromEmulator =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromEmulator]");

                AddSubJob(new JobWaitTime(_form, 3000));

                AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.EmulatorPage }));

                AddSubJob(new JobMovePage(_form, Globals.EmulatorPage, Globals.StartDarkAvenger3, Globals.StartGamePage));
            });

            // Login
            ActionSequenceTree fromLogin =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromLogin]");

                AddSubJob(new JobMovePage(_form, Globals.LoginPage, Globals.Facebook, Globals.FacebookPage));

                AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.FacebookPage }));
            });

            /*ActionSequenceTree fromFacebookLogin =
             *      new ActionSequenceTree(() =>
             *      {
             *              Console.WriteLine("[fromFacebookLogin]");
             *
             *              AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.EmailInFacebook, true));
             *              AddSubJob(new JobWaitTime(_form, 1000));
             *
             *              AddSubJob(new JobPressKeyboard(_form, _email));
             *              AddSubJob(new JobWaitTime(_form, 500));
             *
             *              AddSubJob(JobGenerator.CreateJobMoveAndClickMouse(_form, Globals.PasswordInFacebook, true));
             *              AddSubJob(new JobWaitTime(_form, 1000));
             *
             *              AddSubJob(new JobPressKeyboard(_form, _password));
             *              AddSubJob(new JobWaitTime(_form, 500));
             *
             *              AddSubJob(new JobMovePage(_form, Globals.FacebookPage, Globals.LoginInFacebook, Globals.FacebookConfirmPage, 2000, 2000));
             *
             *              AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.FacebookConfirmPage }));
             *      });*/


            ActionSequenceTree findLoginEmail =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[findLoginEmail]");
                AddSubJob(new JobTryFindSubImage(_form, Globals.LoginPhoneImg));
            });

            ActionSequenceTree clickLoginEmail =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[clickLoginEmail]");
                OpenCvSharp.Rect rect = (OpenCvSharp.Rect)BlackBoard.Instance.Read(BlackBoard.UIRectBlackBoardID, this);

                int addX = 0;
                int addY = 0;

                var pos = Utils.RectToPos(rect.X + addX, rect.Y + addY, rect.Width, rect.Height);

                AddSubJob(new JobMoveAndClickMouse(_form, pos));
                AddSubJob(new JobWaitTime(_form, 1000));

                AddSubJob(new JobMoveAndClickMouse(_form, pos));
                AddSubJob(new JobWaitTime(_form, 1000));

                AddSubJob(new JobPressKeyboard(_form, _email));
                AddSubJob(new JobWaitTime(_form, 500));
            });

            ActionSequenceTree findLoginPassword =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[findLoginPassword]");
                AddSubJob(new JobTryFindSubImage(_form, Globals.LoginPasswordImg));
            });

            ActionSequenceTree clickLoginPassword =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[clickLoginEmail]");
                OpenCvSharp.Rect rect = (OpenCvSharp.Rect)BlackBoard.Instance.Read(BlackBoard.UIRectBlackBoardID, this);

                int addX = 0;
                int addY = 0;

                var pos = Utils.RectToPos(rect.X + addX, rect.Y + addY, rect.Width, rect.Height);

                AddSubJob(new JobMoveAndClickMouse(_form, pos));
                AddSubJob(new JobWaitTime(_form, 1000));

                AddSubJob(new JobMoveAndClickMouse(_form, pos));
                AddSubJob(new JobWaitTime(_form, 1000));

                AddSubJob(new JobPressKeyboard(_form, _password));
                AddSubJob(new JobWaitTime(_form, 500));
            });

            ActionSequenceTree findLoginButton =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[findLoginButton]");
                AddSubJob(new JobTryFindSubImage(_form, Globals.LoginButtonImg));
            });

            ActionSequenceTree clickLoginButton =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[clickLoginButton]");
                OpenCvSharp.Rect rect = (OpenCvSharp.Rect)BlackBoard.Instance.Read(BlackBoard.UIRectBlackBoardID, this);

                int addX = 0;
                int addY = 0;

                var pos = Utils.RectToPos(rect.X + addX, rect.Y + addY, rect.Width, rect.Height);

                AddSubJob(new JobWaitTime(_form, 500));
                AddSubJob(new JobMoveAndClickMouse(_form, pos));
                AddSubJob(new JobWaitTime(_form, 3000));

                AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.FacebookConfirmPage }));
            });

            ActionSequenceTree fromFacebookConfirm =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromFacebookConfirm]");
                AddSubJob(new JobMovePage(_form, Globals.FacebookConfirmPage, Globals.YesInFacebook, Globals.StartGamePage));

                AddSubJob(new JobCheckUntilMeetPage(_form, new string[] { Globals.StartGamePage }));
            });


            // Login end



            ActionSequenceTree fromStartGame =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromStartGame]");
                AddSubJob(new JobMovePage(_form, Globals.StartGamePage, Globals.ClickOnStartGamePage, Globals.CharacterSelectPage));
            });

            ActionSequenceTree fromCharacterSelect =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[fromCharacterSelect]");
                AddSubJob(new JobMovePage(_form, Globals.CharacterSelectPage, Globals.StartGameInSelectPage, new string[] { Globals.NotifyPage, Globals.EventPage1, Globals.EventPage2, Globals.MainPage }));
            });

            ActionSequenceTree closeEventPage1 =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[closeEventPage1]");
                AddSubJob(new JobMovePage(_form, Globals.EventPage1, Globals.OutFromEventPage1, new string[] { Globals.EventPage2, Globals.EventPage3, Globals.NotifyPage, Globals.MainPage }));
            });

            ActionSequenceTree closeEventPage2 =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[closeEventPage2]");
                AddSubJob(new JobMovePage(_form, Globals.EventPage2, Globals.OutFromEventPage2, new string[] { Globals.EventPage3, Globals.NotifyPage, Globals.MainPage }));
            });

            ActionSequenceTree closeEventPage3 =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[closeEventPage3]");
                AddSubJob(new JobMovePage(_form, Globals.EventPage3, Globals.OutFromEventPage3, new string[] { Globals.NotifyPage, Globals.MainPage }));
            });

            ActionSequenceTree closeNotifyPage =
                new ActionSequenceTree(() =>
            {
                Console.WriteLine("[closeNotifyPage]");
                AddSubJob(new JobMovePage(_form, Globals.NotifyPage, Globals.CloseNotify, Globals.MainPage));
            });



            checkEmulatorPage.Completed = fromEmulator;
            checkEmulatorPage.Failed    = killProcess;

            killProcess.Completed = restartEmulator;
            killProcess.Failed    = killProcess;

            restartEmulator.Completed = fromEmulator;
            fromEmulator.Completed    = fromStartGame;

            fromStartGame.Completed       = fromCharacterSelect;
            fromCharacterSelect.Completed = closeEventPage1;
            closeEventPage1.Completed     = closeEventPage2;
            closeEventPage2.Completed     = closeEventPage3;
            closeEventPage3.Completed     = closeNotifyPage;

            closeNotifyPage.ActionOnCompleted = () => { _returnState = State.Completed; };

            // will be executed only after repair
            fromLogin.Completed      = findLoginEmail;
            findLoginEmail.Completed = clickLoginEmail;
            findLoginEmail.Failed    = null;

            clickLoginEmail.Completed   = findLoginPassword;
            findLoginPassword.Completed = clickLoginPassword;
            findLoginPassword.Failed    = null;

            clickLoginPassword.Completed = findLoginButton;
            findLoginButton.Completed    = clickLoginButton;
            findLoginButton.Failed       = null;

            clickLoginButton.Completed    = fromFacebookConfirm;
            fromFacebookConfirm.Completed = fromStartGame;

            _currentAction = checkEmulatorPage;

            // make repair map
            _repairMap[Globals.EmulatorPage] = fromEmulator;

            _repairMap[Globals.LoginPage]           = fromLogin;
            _repairMap[Globals.FacebookPage]        = findLoginEmail;
            _repairMap[Globals.FacebookConfirmPage] = fromFacebookConfirm;

            _repairMap[Globals.StartGamePage]       = fromStartGame;
            _repairMap[Globals.CharacterSelectPage] = fromCharacterSelect;

            _repairMap[Globals.EventPage1] = closeEventPage1;
            _repairMap[Globals.EventPage2] = closeEventPage2;
            _repairMap[Globals.EventPage3] = closeEventPage3;

            _repairMap[Globals.NotifyPage] = closeNotifyPage;
        }