From 5ad9787d7b5ed5994dea0f842c466201e7b175f2 Mon Sep 17 00:00:00 2001 From: redChrillz Date: Tue, 2 Aug 2016 13:18:09 +0200 Subject: [PATCH] Add new option 'AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs' which will use a lucky egg and evolve when criteria is met and KeepPokemonsThatCanEvolve is true --- PoGo.NecroBot.Logic/ILogicSettings.cs | 1 + PoGo.NecroBot.Logic/Settings.cs | 3 + .../Tasks/EvolvePokemonTask.cs | 134 ++++++++++-------- 3 files changed, 81 insertions(+), 57 deletions(-) diff --git a/PoGo.NecroBot.Logic/ILogicSettings.cs b/PoGo.NecroBot.Logic/ILogicSettings.cs index a2ead0f69..bf3a2be25 100644 --- a/PoGo.NecroBot.Logic/ILogicSettings.cs +++ b/PoGo.NecroBot.Logic/ILogicSettings.cs @@ -108,6 +108,7 @@ public interface ILogicSettings string GpxFile { get; } bool UseLuckyEggsWhileEvolving { get; } int UseLuckyEggsMinPokemonAmount { get; } + bool AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs { get; } bool EvolveAllPokemonAboveIv { get; } float EvolveAboveIvValue { get; } bool DumpPokemonStats { get; } diff --git a/PoGo.NecroBot.Logic/Settings.cs b/PoGo.NecroBot.Logic/Settings.cs index 6ba32539f..ae9ee41b0 100644 --- a/PoGo.NecroBot.Logic/Settings.cs +++ b/PoGo.NecroBot.Logic/Settings.cs @@ -194,6 +194,8 @@ public class GlobalSettings public bool UseLuckyEggConstantly; [DefaultValue(30)] public int UseLuckyEggsMinPokemonAmount; + [DefaultValue(true)] + public Boolean AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs; [DefaultValue(false)] public bool UseLuckyEggsWhileEvolving; [DefaultValue(false)] @@ -749,6 +751,7 @@ public LogicSettings(GlobalSettings settings) public bool UseGpxPathing => _settings.UseGpxPathing; public bool UseLuckyEggsWhileEvolving => _settings.UseLuckyEggsWhileEvolving; public int UseLuckyEggsMinPokemonAmount => _settings.UseLuckyEggsMinPokemonAmount; + public bool AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs => _settings.AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs; public bool EvolveAllPokemonAboveIv => _settings.EvolveAllPokemonAboveIv; public float EvolveAboveIvValue => _settings.EvolveAboveIvValue; public bool RenamePokemon => _settings.RenamePokemon; diff --git a/PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs index e483cf643..0bc9ca671 100644 --- a/PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs @@ -9,6 +9,8 @@ using PoGo.NecroBot.Logic.Utils; using POGOProtos.Inventory.Item; using PoGo.NecroBot.Logic.Common; +using System.Collections.Generic; +using POGOProtos.Data; #endregion @@ -32,15 +34,21 @@ public static async Task Execute(ISession session, CancellationToken cancellatio if (pokemonToEvolve.Any()) { - if (session.LogicSettings.KeepPokemonsThatCanEvolve) + if (session.LogicSettings.AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs && await shouldUseLuckyEgg(session, pokemonToEvolve)) + { + await UseLuckyEgg(session); + await evolve(session, pokemonToEvolve); + return; + } + else if (session.LogicSettings.KeepPokemonsThatCanEvolve) { var totalPokemon = await session.Inventory.GetPokemons(); - var pokemonNeededInInventory = session.Profile.PlayerData.MaxPokemonStorage * session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage/100.0f; + var pokemonNeededInInventory = session.Profile.PlayerData.MaxPokemonStorage * session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage / 100.0f; var needPokemonToStartEvolve = Math.Round( - Math.Max(0, + Math.Max(0, Math.Min(pokemonNeededInInventory, session.Profile.PlayerData.MaxPokemonStorage))); - + var deltaCount = needPokemonToStartEvolve - totalPokemon.Count(); if (deltaCount > 0) @@ -50,64 +58,15 @@ public static async Task Execute(ISession session, CancellationToken cancellatio Message = session.Translation.GetTranslation(TranslationString.WaitingForMorePokemonToEvolve, pokemonToEvolve.Count, deltaCount, totalPokemon.Count(), needPokemonToStartEvolve, session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage) }); - return; } - } - - var inventoryContent = await session.Inventory.GetItems(); + } - var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg); - var luckyEgg = luckyEggs.FirstOrDefault(); - - if (session.LogicSettings.UseLuckyEggsWhileEvolving && luckyEgg != null && luckyEgg.Count > 0) + if (await shouldUseLuckyEgg(session, pokemonToEvolve)) { - if (pokemonToEvolve.Count >= session.LogicSettings.UseLuckyEggsMinPokemonAmount) - { - await UseLuckyEgg(session); - } - else - { - var evolvablePokemon = await session.Inventory.GetPokemons(); - - var deltaPokemonToUseLuckyEgg = session.LogicSettings.UseLuckyEggsMinPokemonAmount - - pokemonToEvolve.Count; - - var availableSpace = session.Profile.PlayerData.MaxPokemonStorage - evolvablePokemon.Count(); - - if (deltaPokemonToUseLuckyEgg > availableSpace) - { - var possibleLimitInThisIteration = pokemonToEvolve.Count + availableSpace; - - session.EventDispatcher.Send(new NoticeEvent() - { - Message = session.Translation.GetTranslation(TranslationString.UseLuckyEggsMinPokemonAmountTooHigh, - session.LogicSettings.UseLuckyEggsMinPokemonAmount, possibleLimitInThisIteration) - }); - } - else - { - session.EventDispatcher.Send(new NoticeEvent() - { - Message = session.Translation.GetTranslation(TranslationString.CatchMorePokemonToUseLuckyEgg, - deltaPokemonToUseLuckyEgg) - }); - } - } - } - - foreach (var pokemon in pokemonToEvolve) - { - // no cancellationToken.ThrowIfCancellationRequested here, otherwise the lucky egg would be wasted. - var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id); - - session.EventDispatcher.Send(new PokemonEvolveEvent - { - Id = pokemon.PokemonId, - Exp = evolveResponse.ExperienceAwarded, - Result = evolveResponse.Result - }); + await UseLuckyEgg(session); } + await evolve(session, pokemonToEvolve); } } @@ -127,5 +86,66 @@ public static async Task UseLuckyEgg(ISession session) if (luckyEgg != null) session.EventDispatcher.Send(new UseLuckyEggEvent {Count = luckyEgg.Count}); DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 2000); } + + private static async Task evolve(ISession session, List pokemonToEvolve) + { + foreach (var pokemon in pokemonToEvolve) + { + // no cancellationToken.ThrowIfCancellationRequested here, otherwise the lucky egg would be wasted. + var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id); + + session.EventDispatcher.Send(new PokemonEvolveEvent + { + Id = pokemon.PokemonId, + Exp = evolveResponse.ExperienceAwarded, + Result = evolveResponse.Result + }); + } + } + + private static async Task shouldUseLuckyEgg(ISession session, List pokemonToEvolve) + { + var inventoryContent = await session.Inventory.GetItems(); + + var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg); + var luckyEgg = luckyEggs.FirstOrDefault(); + + if (session.LogicSettings.UseLuckyEggsWhileEvolving && luckyEgg != null && luckyEgg.Count > 0) + { + if (pokemonToEvolve.Count >= session.LogicSettings.UseLuckyEggsMinPokemonAmount) + { + return true; + } + else + { + var evolvablePokemon = await session.Inventory.GetPokemons(); + + var deltaPokemonToUseLuckyEgg = session.LogicSettings.UseLuckyEggsMinPokemonAmount - + pokemonToEvolve.Count; + + var availableSpace = session.Profile.PlayerData.MaxPokemonStorage - evolvablePokemon.Count(); + + if (deltaPokemonToUseLuckyEgg > availableSpace) + { + var possibleLimitInThisIteration = pokemonToEvolve.Count + availableSpace; + + session.EventDispatcher.Send(new NoticeEvent() + { + Message = session.Translation.GetTranslation(TranslationString.UseLuckyEggsMinPokemonAmountTooHigh, + session.LogicSettings.UseLuckyEggsMinPokemonAmount, possibleLimitInThisIteration) + }); + } + else + { + session.EventDispatcher.Send(new NoticeEvent() + { + Message = session.Translation.GetTranslation(TranslationString.CatchMorePokemonToUseLuckyEgg, + deltaPokemonToUseLuckyEgg) + }); + } + } + } + return false; + } } }