/// <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); }
/// <summary> /// Determine if the player should drink a dose of stamina potion /// </summary> protected void EvaluateStamina() { const int drinkBelow = 75; //Do not drink above 75 run energy. const int mostEarlyDrink = 100; //Never drink more than 80 seconds before a stamina potion runs out. double runEnergy = 100 * Minimap.RunEnergy(true); long timeSinceLastDose = StaminaTimer.ElapsedMilliseconds; if (DamagedPouches) { timeSinceLastDose += REPAIR_POUCHES_DURATION; } if (!StaminaTimer.IsRunning) //drink a stamina potion for the first time { timeSinceLastDose = STAMINA_DURATION; } int drinkEarly = (int)(mostEarlyDrink * ((drinkBelow - (int)runEnergy) / (double)drinkBelow)); LowStamina = timeSinceLastDose > (STAMINA_DURATION - UnitConversions.SecondsToMilliseconds(drinkEarly)); }