示例#1
0
        /// <summary>
        ///
        /// </summary>
        private void RunChatScanner()
        {
            while (_scanChat == true && !BotProgram.StopFlag)
            {
                if (Screen.LooksValid() && Screen.IsLoggedIn())
                {
                    ScanChat();
                }

                BotProgram.SafeWait(10000);
            }
        }
示例#2
0
        /// <summary>
        /// Begins iterating after Run is called. Called for the number of iterations specified by the user.
        /// Is only called if both Iterations and FrameRate are specified.
        /// </summary>
        /// <returns>true if execution is finished and the bot should stop. returns false if the bot should continue after a break.</returns>
        private bool Iterate()
        {
            if (StopFlag)
            {
                return(true);
            }
            int randomFrameOffset, randomFrameTime;

            //randomize the time between executions
            if (RunParams.RandomizeFrames)
            {
                randomFrameOffset = (int)(0.6 * RunParams.FrameTime);
            }
            else
            {
                randomFrameOffset = 0;
            }

            RunParams.BotState = BotState.Running;
            long workInterval = RunParams.SlaveDriver ? (long)(RunParams.RunUntil - DateTime.Now).TotalMilliseconds : RandomWorkTime();

            RunParams.SetNewState(workInterval);
            ScreenScraper.BringToForeGround();
            SafeWait(1000); //give the client time to show up on screen

            Stopwatch iterationWatch    = new Stopwatch();
            Stopwatch workIntervalWatch = new Stopwatch();

            workIntervalWatch.Start();

            while ((DateTime.Now < RunParams.RunUntil) && ((RunParams.Iterations > 0) || (RunParams.InfiniteIterations == true)))
            {
                if (StopFlag)
                {
                    return(true);
                }                                //quit immediately if the stop flag has been raised or we can't log back in
                iterationWatch.Restart();
                if (!Screen.ReadWindow() || BotWorldCheck(false))
                {
                    continue;
                }                                                                 //We had to switch out of a bot world

                //Only do the actual botting if we are logged in
                if (CheckLogIn(false))
                {
                    if (Screen.LooksValid()) //Make sure the read is successful before using the bitmap values
                    {
                        if (RunParams.AutoEat)
                        {
                            ManageHitpoints(false);
                        }

                        if (RunParams.Run)
                        {
                            Minimap.RunCharacter(RunParams.RunAbove, false); //Turn on run if the player has run energy
                        }

                        if (!Execute() && !StopFlag) //quit by a bot program
                        {
                            LogError.ScreenShot(Screen, "bot-quit");
                            return(true);
                        }
                        if (StopFlag)
                        {
                            return(true);
                        }
                    }
                }
                else
                {
                    if (StopFlag)
                    {
                        return(true);
                    }
                    if (!HandleFailedLogIn())
                    {
                        return(true);    //stop if we are unable to recover
                    }
                }

                randomFrameTime = RunParams.FrameTime + RNG.Next(-randomFrameOffset, randomFrameOffset + 1);
                randomFrameTime = Math.Max(0, randomFrameTime);
                if (iterationWatch.ElapsedMilliseconds < randomFrameTime)
                {
                    SafeWait(randomFrameTime - (int)iterationWatch.ElapsedMilliseconds);
                }
                if (StopFlag)
                {
                    return(true);
                }
                if (workIntervalWatch.ElapsedMilliseconds > workInterval)
                {
                    return(RunParams.SlaveDriver);
                }
            }

            return(true);
        }