/// <summary> /// Starts a new instance of the Runescape client /// </summary> /// <returns>true if successful</returns> public static bool StartClient(ref Process client, string clientFilePath, string arguments) { client = GetClient(); if (ProcessExists(client)) { return(true); //the Runescape client is already running } //start the Runescape client try { Process.Start(clientFilePath, arguments); //verify that the Runescape client has loaded Stopwatch watch = new Stopwatch(); watch.Start(); while (!ProcessExists(client) && (watch.ElapsedMilliseconds < UnitConversions.MinutesToMilliseconds(10)) && !BotProgram.StopFlag) { Thread.Sleep(500); client = GetClient(); } return(ProcessExists(client)); } catch { return(false); } }
/// <summary> /// Generates a random number of milliseconds for the bot to take a break /// </summary> /// <returns>the number of milliseconds for the bot to rest</returns> private int RandomBreakTime() { double breakType = RNG.NextDouble(); double mean, stdDev; //measured in minutes //average of 25.1 minutes if (breakType < 0.75) //75% { mean = 15; stdDev = 5.5; } else if (breakType < 0.90) //15% { mean = 33; stdDev = 8.7; } else //10% { mean = 89; stdDev = 41; } int minBreakTime = 2; int breakLength = (int)Probability.BoundedGaussian(mean, stdDev, minBreakTime, double.MaxValue); return(UnitConversions.MinutesToMilliseconds(breakLength)); }
/// <summary> /// Generates a number of milliseconds for the bot to run before logging out and resting /// </summary> /// <returns>the next work time in milliseconds</returns> public int RandomWorkTime() { double workType = RNG.NextDouble(); double mean, stdDev; //measured in minutes //average of 84.8 minutes if (workType < 0.3) //30% { mean = 45; stdDev = 18; } else if (workType < 0.7) //40% { mean = 83; stdDev = 35; } else //30% { mean = 127; stdDev = 21; } double workTime = Probability.BoundedGaussian(mean, stdDev, 1, 345); workTime = Math.Min(workTime, (RunParams.RunUntil - DateTime.Now).TotalMilliseconds); return(UnitConversions.MinutesToMilliseconds(workTime)); }
/// <summary> /// Generates a random number of milliseconds for the bot to sleep at night /// </summary> /// <returns>the number of milliseconds for the bot to sleep</returns> private int RandomSleepTime() { double avgSleepLength = UnitConversions.HoursToMilliseconds(14); double standardDeviation = UnitConversions.MinutesToMilliseconds(30); int breakLength = (int)Probability.RandomGaussian(avgSleepLength, standardDeviation); return(breakLength); }
/// <summary> /// Sets the normal default values for commonly used run parameters /// </summary> private void InitializeBaseParams() { BotName = "New Bot"; FrameTime = 3000; RandomizeFrames = true; BotState = BotProgram.BotState.Running; RunUntil = DateTime.Now; BotWorldCheckEnabled = false; BotWorldCheckInterval = UnitConversions.MinutesToMilliseconds(5); TaskComplete = new BotResponse(DoNothing); StartEatingBelow = 0.5; StopEatingAbove = 0.8; ClosedChatBox = false; RunLoggedIn = true; RunAbove = 0.2; Conversation = false; CustomSettingsData = new CustomSettingsData(); }
/// <summary> /// Makes sure that a client is running and starts it if it isn't /// </summary> /// <param name="forceRestart">Set to true to force a client restart even if the client is already running</param> /// <returns>true if client is successfully prepared</returns> public bool PrepareClient(bool forceRestart = false) { if (!forceRestart && ScreenScraper.ProcessExists(Value)) { return(true); } Process client = null; Stopwatch longWatch = new Stopwatch(); longWatch.Start(); while (longWatch.ElapsedMilliseconds < UnitConversions.HoursToMilliseconds(24) && !BotProgram.StopFlag) { if (!ScreenScraper.RestartClient(ref client, RunParams.RuneScapeClient, RunParams.ClientFlags)) { BotProgram.SafeWait(5000); continue; } //Successful restart Value = client; Stopwatch watch = new Stopwatch(); watch.Start(); //Wait for cient to be visually recognized. do { BotProgram.SafeWait(UnitConversions.SecondsToMilliseconds(5)); if (Screen.ReadWindow(false) && (Screen.IsLoggedOut(false) || Screen.IsLoggedIn(false))) { return(true); } }while ((watch.ElapsedMilliseconds < UnitConversions.MinutesToMilliseconds(5)) && !BotProgram.StopFlag); } if (!BotProgram.StopFlag) { const string errorMessage = "Client did not start correctly"; MessageBox.Show(errorMessage); } Value = null; return(false); }
public void MinutesToMillisecondsTest(double minutes, int expectedMS) { int actualMS = UnitConversions.MinutesToMilliseconds(minutes); Assert.AreEqual(actualMS, expectedMS); }