/// <summary> /// Don't actually do anything /// </summary> /// <returns>returns false to stop the bot program</returns> protected override bool Run() { RunParams.ActiveBot.BotState = BotState.Running; int timeToRun = (int)(RunParams.RunUntil - DateTime.Now).TotalMilliseconds; RunParams.SetNewState(timeToRun); RunParams.BotIdle = true; SafeWait(timeToRun); RunParams.BotIdle = false; return(false); }
/// <summary> /// Pretends to sleep for the night /// </summary> /// <returns>true if execution should stop</returns> private bool Sleep() { RunParams.BotState = BotState.Sleep; long sleepLength = RandomSleepTime(); RunParams.SetNewState(sleepLength); RunParams.BotIdle = true; bool quit = SafeWait(sleepLength); RunParams.BotIdle = false; return(quit || (DateTime.Now >= RunParams.RunUntil)); }
/// <summary> /// Takes a break from executing the bot /// </summary> /// <returns>true if execution should stop</returns> private bool Break() { RunParams.BotState = BotState.Break; long breakLength = RandomBreakTime(); RunParams.SetNewState(breakLength); RunParams.BotIdle = true; bool quit = SafeWait(breakLength); RunParams.BotIdle = false; return(quit || (DateTime.Now >= RunParams.RunUntil)); }
/// <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); }