Skip to content

Commit

Permalink
Merge pull request #1999 from simplyphp/master
Browse files Browse the repository at this point in the history
Fixed bug that always transfers pokemon that can evolve
  • Loading branch information
BornSupercharged authored Aug 2, 2016
2 parents 9a911d3 + 2cda5b7 commit 31a65c3
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 76 deletions.
120 changes: 46 additions & 74 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,88 +93,60 @@ public async Task<IEnumerable<PokemonData>> GetDuplicatePokemonToTransfer(

var pokemonList = pokemonFiltered.ToList();

if (keepPokemonsThatCanEvolve)
{
var results = new List<PokemonData>();
var pokemonsThatCanBeTransfered = pokemonList.GroupBy(p => p.PokemonId).ToList();
var results = new List<PokemonData>();
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<IEnumerable<EggIncubator>> GetEggIncubators()
Expand Down
4 changes: 2 additions & 2 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 31a65c3

Please sign in to comment.