/// <summary> /// Click down and release a mouse button /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="clickTypeDown"></param> /// <param name="clickTypeUp"></param> private static Point Click(int x, int y, int clickTypeDown, int clickTypeUp, int hoverDelay, int randomize) { Random rng = new Random(); Point clickPoint = Probability.GaussianCircle(new Point(x, y), 0.35 * randomize, 0, 360, randomize); x = clickPoint.X; y = clickPoint.Y; ScreenScraper.BringToForeGround(); ScreenScraper.GameScreenToWindow(ref x, ref y); if (BotProgram.StopFlag) { return(new Point(0, 0)); } NaturalMove(x, y); BotProgram.SafeWaitPlus(hoverDelay, 0.25 * hoverDelay); //wait for RS client to recognize the cursor hover if (!BotProgram.StopFlag) { mouse_event(clickTypeDown, x, y, 0, 0); mouse_event(clickTypeUp, x, y, 0, 0); } return(clickPoint); }
/// <summary> /// Verifies that the client exists and that it is visible and maximized /// </summary> /// <returns></returns> private bool PrepareClientForInput() { if (BotProgram.StopFlag) { return(false); } if (ScreenScraper.ProcessExists(RSClient)) { ScreenScraper.BringToForeGround(); return(true); } else { return(false); } }
/// <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); }