diff --git a/PoGo.NecroBot.Logic/Inventory.cs b/PoGo.NecroBot.Logic/Inventory.cs index 5505f39cb..c07645cb3 100644 --- a/PoGo.NecroBot.Logic/Inventory.cs +++ b/PoGo.NecroBot.Logic/Inventory.cs @@ -93,88 +93,60 @@ public async Task> GetDuplicatePokemonToTransfer( var pokemonList = pokemonFiltered.ToList(); - if (keepPokemonsThatCanEvolve) - { - var results = new List(); - var pokemonsThatCanBeTransfered = pokemonList.GroupBy(p => p.PokemonId).ToList(); + var results = new List(); + var pokemonsThatCanBeTransfered = pokemonList.GroupBy(p => p.PokemonId).ToList(); - var myPokemonSettings = await GetPokemonSettings(); - var pokemonSettings = myPokemonSettings.ToList(); + var myPokemonSettings = await GetPokemonSettings(); + var pokemonSettings = myPokemonSettings.ToList(); - var myPokemonFamilies = await GetPokemonFamilies(); - var pokemonFamilies = myPokemonFamilies.ToArray(); + var myPokemonFamilies = await GetPokemonFamilies(); + var pokemonFamilies = myPokemonFamilies.ToArray(); - foreach (var pokemon in pokemonsThatCanBeTransfered) + foreach (var pokemon in pokemonsThatCanBeTransfered) + { + var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.Key); + var amountToSkip = GetPokemonTransferFilter(pokemon.Key).KeepMinDuplicatePokemon; + + var transferrablePokemonTypeCount = pokemonFiltered.Where(p => p.PokemonId == pokemon.Key).Count(); + var currentPokemonTypeCount = myPokemon.Where(p => p.PokemonId == pokemon.Key).Count(); + var currentlyKeepingPokemonType = currentPokemonTypeCount - transferrablePokemonTypeCount; + + if (currentlyKeepingPokemonType > GetPokemonTransferFilter(pokemon.Key).KeepMinDuplicatePokemon) + { + amountToSkip = 0; + } + else if (transferrablePokemonTypeCount > amountToSkip || currentlyKeepingPokemonType > 1) { - var settings = pokemonSettings.Single(x => x.PokemonId == pokemon.Key); - var familyCandy = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId); - var amountToSkip = GetPokemonTransferFilter(pokemon.Key).KeepMinDuplicatePokemon; - - var transferrablePokemonTypeCount = pokemonFiltered.Where(p => p.PokemonId == pokemon.Key).Count(); - var currentPokemonTypeCount = myPokemon.Where(p => p.PokemonId == pokemon.Key).Count(); - var currentlyKeepingPokemonType = currentPokemonTypeCount - transferrablePokemonTypeCount; - - if (currentlyKeepingPokemonType > GetPokemonTransferFilter(pokemon.Key).KeepMinDuplicatePokemon) - { - amountToSkip = 0; - } - else if (transferrablePokemonTypeCount > amountToSkip || currentlyKeepingPokemonType > 1) - { - amountToSkip = (amountToSkip - currentlyKeepingPokemonType + 1); - } - - // Fail safe - if (amountToSkip < 0) amountToSkip = 0; - - if (settings.CandyToEvolve > 0 && _logicSettings.PokemonsToEvolve.Contains(pokemon.Key)) - { - var amountPossible = (familyCandy.Candy_ - 1) / (settings.CandyToEvolve - 1); - if (amountPossible > amountToSkip) - amountToSkip += amountPossible; - } - - if (prioritizeIVoverCp) - { - results.AddRange(pokemonList.Where(x => x.PokemonId == pokemon.Key) - .OrderByDescending(PokemonInfo.CalculatePokemonPerfection) - .ThenByDescending(n => n.Cp) - .Skip(amountToSkip) - .ToList()); - } - else - { - results.AddRange(pokemonList.Where(x => x.PokemonId == pokemon.Key) - .OrderByDescending(x => x.Cp) - .ThenByDescending(PokemonInfo.CalculatePokemonPerfection) - .Skip(amountToSkip) - .ToList()); - } + amountToSkip = (amountToSkip - currentlyKeepingPokemonType + 1); } - return results; - } + // Fail safe + if (amountToSkip < 0) amountToSkip = 0; + + // Don't get rid of it if we can evolve it + if (keepPokemonsThatCanEvolve && settings.EvolutionIds.Count != 0) + continue; - if (prioritizeIVoverCp) - { - return pokemonList - .GroupBy(p => p.PokemonId) - .Where(x => x.Any()) - .SelectMany( - p => - p.OrderByDescending(PokemonInfo.CalculatePokemonPerfection) - .ThenBy(n => n.StaminaMax) - .Skip(GetPokemonTransferFilter(p.Key).KeepMinDuplicatePokemon) - .ToList()); + if (prioritizeIVoverCp) + { + results.AddRange(pokemonList.Where(x => x.PokemonId == pokemon.Key) + .OrderByDescending(PokemonInfo.CalculatePokemonPerfection) + .ThenByDescending(n => n.Cp) + .Skip(amountToSkip) + .ToList()); + } + else + { + results.AddRange(pokemonList.Where(x => x.PokemonId == pokemon.Key) + .OrderByDescending(x => x.Cp) + .ThenByDescending(PokemonInfo.CalculatePokemonPerfection) + .Skip(amountToSkip) + .ToList()); + } } - return pokemonList - .GroupBy(p => p.PokemonId) - .Where(x => x.Any()) - .SelectMany( - p => - p.OrderByDescending(x => x.Cp) - .ThenBy(n => n.StaminaMax) - .Skip(GetPokemonTransferFilter(p.Key).KeepMinDuplicatePokemon) - .ToList()); + + return results; + } public async Task> GetEggIncubators() diff --git a/PoGo.NecroBot.Logic/Settings.cs b/PoGo.NecroBot.Logic/Settings.cs index 1dbbc9e7a..6ba32539f 100644 --- a/PoGo.NecroBot.Logic/Settings.cs +++ b/PoGo.NecroBot.Logic/Settings.cs @@ -139,9 +139,9 @@ public class GlobalSettings public bool DisableHumanWalking; [DefaultValue(10)] public double DefaultAltitude; - [DefaultValue(40.785091)] + [DefaultValue(40.778915)] public double DefaultLatitude; - [DefaultValue(-73.968285)] + [DefaultValue(-73.962277)] public double DefaultLongitude; [DefaultValue(31.0)] public double WalkingSpeedInKilometerPerHour;