public async void CheckForMaxCatch() { try { if (!GlobalSettings.CatchSettings.PauseBotOnMaxHourlyRates || RealWorkH < 1 || //DEBUG Session?.Stats == null) { return; } var countXp = GlobalSettings.CatchSettings.MaxXPPerHour > 0; var countSd = GlobalSettings.CatchSettings.MaxStarDustPerHour > 0; var countPokemons = GlobalSettings.CatchSettings.MaxCatchPerHour > 0; var countPokestops = GlobalSettings.CatchSettings.MaxPokestopsPerHour > 0; var tooMuchPokemons = countPokemons && PokemonsRate > GlobalSettings.CatchSettings.MaxCatchPerHour; var tooMuchPokestops = countPokestops && PokestopsRate > GlobalSettings.CatchSettings.MaxPokestopsPerHour; var tooMuchXp = countXp && Xpph > GlobalSettings.CatchSettings.MaxXPPerHour; var tooMuchStarDust = countSd && StardustRate > GlobalSettings.CatchSettings.MaxStarDustPerHour; if (!tooMuchPokemons && !tooMuchPokestops && !tooMuchXp && !tooMuchStarDust) { return; } var pokemonSec = tooMuchPokemons ? (PokemonsRate - GlobalSettings.CatchSettings.MaxCatchPerHour) / GlobalSettings.CatchSettings.MaxCatchPerHour * 60 * 60 : 0; var pokestopSec = tooMuchPokestops ? (PokestopsRate - GlobalSettings.CatchSettings.MaxPokestopsPerHour) / GlobalSettings.CatchSettings.MaxPokestopsPerHour * 60 * 60 : 0; var xpSec = tooMuchXp ? (Xpph - GlobalSettings.CatchSettings.MaxXPPerHour) / GlobalSettings.CatchSettings.MaxXPPerHour * 60 * 60 : 0; var stardustSec = tooMuchStarDust ? (StardustRate - GlobalSettings.CatchSettings.MaxStarDustPerHour) / GlobalSettings.CatchSettings.MaxStarDustPerHour * 60 * 60 : 0; var stopSec = 10 * 60 + _rnd.Next(60 * 5) + (int)(new [] { pokestopSec, pokemonSec, xpSec, stardustSec }).Max(); var stopMs = stopSec * 1000; //#if DEBUG // stopMs /= 100; //#endif Session.EventDispatcher.Send(new WarnEvent { Message = $"Max amount of Pokemon ({PokemonsRate.ToN1()})/Pokestops ({PokestopsRate.ToN1()})/XP ({Xpph.ToN1()})/Star Dust ({StardustRate.ToN1()}) per hour reached, bot will be stopped for {(stopMs/60000).ToString("N1")} minutes" }); _realWorkSec += stopSec; Stop(true); _pauseCts.Dispose(); _pauseCts = new CancellationTokenSource(); RandomizePosition(); await SetPause(stopMs); Start(); } catch (OperationCanceledException) { Session.EventDispatcher.Send(new WarnEvent { Message = "Bot pause routine canceled" }); } catch (Exception ex) { Session.EventDispatcher.Send(new WarnEvent { Message = "Bot pause routine failed badly" }); Logger.Write($"[PAUSE FAIL] Error: {ex.Message}", LogLevel.Error); } }
public async void CheckForMaxCatch() { try { if (!GlobalSettings.CatchSettings.PauseBotOnMaxHourlyRates || RealWorkH < 1 || //DEBUG Session?.Stats == null || Session.State == BotState.LuckyEgg || !Started || UsedItemsList.Any(x => x.InUse)) { return; } var countXp = GlobalSettings.CatchSettings.MaxXPPerHour > 0; var countSd = GlobalSettings.CatchSettings.MaxStarDustPerHour > 0; var countPokemons = GlobalSettings.CatchSettings.MaxCatchPerHour > 0; var countPokestops = GlobalSettings.CatchSettings.MaxPokestopsPerHour > 0; var tooMuchPokemons = countPokemons && PokemonsRate > GlobalSettings.CatchSettings.MaxCatchPerHour; var tooMuchPokestops = countPokestops && PokestopsRate > GlobalSettings.CatchSettings.MaxPokestopsPerHour; var tooMuchXp = countXp && Xpph > GlobalSettings.CatchSettings.MaxXPPerHour; var tooMuchStarDust = countSd && StardustRate > GlobalSettings.CatchSettings.MaxStarDustPerHour; if (!tooMuchPokemons && !tooMuchPokestops && !tooMuchXp && !tooMuchStarDust) { return; } var pokemonSec = tooMuchPokemons ? (PokemonsRate - GlobalSettings.CatchSettings.MaxCatchPerHour) / GlobalSettings.CatchSettings.MaxCatchPerHour * 60 * 60 : 0; var pokestopSec = tooMuchPokestops ? (PokestopsRate - GlobalSettings.CatchSettings.MaxPokestopsPerHour) / GlobalSettings.CatchSettings.MaxPokestopsPerHour * 60 * 60 : 0; var xpSec = tooMuchXp ? (Xpph - GlobalSettings.CatchSettings.MaxXPPerHour) / GlobalSettings.CatchSettings.MaxXPPerHour * 60 * 60 : 0; var stardustSec = tooMuchStarDust ? (StardustRate - GlobalSettings.CatchSettings.MaxStarDustPerHour) / GlobalSettings.CatchSettings.MaxStarDustPerHour * 60 * 60 : 0; var stopSec = 10 * 60 + _rnd.Next(60 * 5) + (int)(new [] { pokestopSec, pokemonSec, xpSec, stardustSec }).Max(); var stopMs = stopSec * 1000; //#if DEBUG // stopMs /= 100; //#endif _realWorkSec += stopSec; Stop(true); _pauseCts.Dispose(); _pauseCts = new CancellationTokenSource(); Session.EventDispatcher.Send(new WarnEvent { Message = Session.Translation.GetTranslation(TranslationString.HourRateReached, PokemonsRate.ToN1(), PokestopsRate.ToN1(), Xpph.ToN1(), StardustRate.ToN1(), (stopMs / 60000).ToString("N1")) }); RandomizePosition(); await SetPause(stopMs); Start(); } catch (OperationCanceledException) { Session.EventDispatcher.Send(new WarnEvent { Message = Session.Translation.GetTranslation(TranslationString.BotPauseCancel) }); } catch (Exception ex) { Session.EventDispatcher.Send(new WarnEvent { Message = Session.Translation.GetTranslation(TranslationString.BotPauseFail) }); Logger.Write($"[PAUSE FAIL] Error: {ex.Message}", LogLevel.Error); } }