Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed transfer functionality #1976

Merged
merged 2 commits into from
Aug 2, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public interface ILogicSettings
bool TransferConfigAndAuthOnUpdate { get; }
float KeepMinIvPercentage { get; }
int KeepMinCp { get; }
string KeepMinOperator { get; }
double WalkingSpeedInKilometerPerHour { get; }
bool EvolveAllPokemonWithEnoughCandy { get; }
bool KeepPokemonsThatCanEvolve { get; }
Expand Down
22 changes: 15 additions & 7 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,16 @@ public async Task<IEnumerable<PokemonData>> GetDuplicatePokemonToTransfer(
{
var myPokemon = await GetPokemons();

var pokemonList =
var pokemonList = (_logicSettings.KeepMinOperator.ToLower().Equals("and")) ?
myPokemon.Where(
p => p.DeployedFortId == string.Empty &&
p.Favorite == 0 && (p.Cp < GetPokemonTransferFilter(p.PokemonId).KeepMinCp ||
PokemonInfo.CalculatePokemonPerfection(p) <
GetPokemonTransferFilter(p.PokemonId).KeepMinIvPercentage))
.ToList();
p => p.DeployedFortId == string.Empty &&
p.Favorite == 0 && (p.Cp < GetPokemonTransferFilter(p.PokemonId).KeepMinCp ||
PokemonInfo.CalculatePokemonPerfection(p) < GetPokemonTransferFilter(p.PokemonId).KeepMinIvPercentage)).ToList() :
myPokemon.Where(
p => p.DeployedFortId == string.Empty &&
p.Favorite == 0 && (p.Cp < GetPokemonTransferFilter(p.PokemonId).KeepMinCp &&
PokemonInfo.CalculatePokemonPerfection(p) < GetPokemonTransferFilter(p.PokemonId).KeepMinIvPercentage)).ToList();

if (filter != null)
{
pokemonList = pokemonList.Where(p => !filter.Contains(p.PokemonId)).ToList();
Expand Down Expand Up @@ -138,6 +141,7 @@ public async Task<IEnumerable<PokemonData>> GetDuplicatePokemonToTransfer(
}
if (prioritizeIVoverCp)
{
var skipnum = GetPokemonTransferFilter(PokemonId.Arbok).KeepMinDuplicatePokemon;
return pokemonList
.GroupBy(p => p.PokemonId)
.Where(x => x.Any())
Expand Down Expand Up @@ -416,7 +420,11 @@ public async Task<List<PokemonData>> GetPokemonToUpgrade()
myPokemon.Where(
p => (p.Cp >= _logicSettings.UpgradePokemonCpMinimum ||
PokemonInfo.CalculatePokemonPerfection(p) >= _logicSettings.UpgradePokemonIvMinimum)).OrderByDescending(p => p.Cp).ToList();

/**
* @todo make sure theres enough candy (see line 109)
* @todo make sure max cp hasnt been reached
* @todo remove _logicSettings.AmountOfTimesToUpgradeLoop and use it as a count limitation in levelup loop for successes instead
* */
return upgradePokemon = (_logicSettings.LevelUpByCPorIv.ToLower().Equals("iv")) ?
highestPokemonForUpgrade.OrderByDescending(PokemonInfo.CalculatePokemonPerfection).Take(_logicSettings.AmountOfTimesToUpgradeLoop).ToList() :
highestPokemonForUpgrade.Take(_logicSettings.AmountOfTimesToUpgradeLoop).ToList();
Expand Down
27 changes: 15 additions & 12 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,21 @@ public class GlobalSettings
public bool EvolveAllPokemonAboveIv;
[DefaultValue(true)]
public bool EvolveAllPokemonWithEnoughCandy;
[DefaultValue(false)]
public bool KeepPokemonsThatCanEvolve;
[DefaultValue(0.90)]
public double EvolveKeptPokemonsAtStorageUsagePercentage;
[DefaultValue(false)]
public bool KeepPokemonsThatCanEvolve;
//keeping
[DefaultValue(1250)]
public int KeepMinCp;
[DefaultValue(90)]
public float KeepMinIvPercentage;
[DefaultValue("and")]
public string KeepMinOperator;
[DefaultValue(false)]
public bool PrioritizeIvOverCp;
[DefaultValue(1)]
public int KeepMinDuplicatePokemon;
//gpx
[DefaultValue(false)]
public bool UseGpxPathing;
Expand All @@ -177,15 +188,6 @@ public class GlobalSettings
public bool VerboseRecycling;
[DefaultValue(0.90)]
public double RecycleInventoryAtUsagePercentage;
//keeping
[DefaultValue(1250)]
public int KeepMinCp;
[DefaultValue(1)]
public int KeepMinDuplicatePokemon;
[DefaultValue(90)]
public float KeepMinIvPercentage;
[DefaultValue(false)]
public bool PrioritizeIvOverCp;
//lucky, incense and berries
[DefaultValue(true)]
public bool UseEggIncubators;
Expand Down Expand Up @@ -692,7 +694,8 @@ public LogicSettings(GlobalSettings settings)
public bool AutoUpdate => _settings.AutoUpdate;
public bool TransferConfigAndAuthOnUpdate => _settings.TransferConfigAndAuthOnUpdate;
public bool DisableHumanWalking => _settings.DisableHumanWalking;
public float KeepMinIvPercentage => _settings.KeepMinIvPercentage;
public float KeepMinIvPercentage => _settings.KeepMinIvPercentage;
public string KeepMinOperator => _settings.KeepMinOperator;
public int KeepMinCp => _settings.KeepMinCp;
public bool AutomaticallyLevelUpPokemon => _settings.AutomaticallyLevelUpPokemon;
public int AmountOfTimesToUpgradeLoop => _settings.AmountOfTimesToUpgradeLoop;
Expand Down
41 changes: 2 additions & 39 deletions PoGo.NecroBot.Logic/Tasks/DisplayPokemonStatsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,15 @@ public static async Task Execute(ISession session)

var highestsPokemonCp =
await session.Inventory.GetHighestsCp(session.LogicSettings.AmountOfPokemonToDisplayOnStart);
var highestsPokemonCpForUpgrade = await session.Inventory.GetHighestsCp(50);
var highestsPokemonIvForUpgrade = await session.Inventory.GetHighestsPerfect(50);

var pokemonPairedWithStatsCp =
highestsPokemonCp.Select(
pokemon =>
Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();
var pokemonPairedWithStatsCpForUpgrade =
highestsPokemonCpForUpgrade.Select(
pokemon =>
Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();

var highestsPokemonPerfect =
await session.Inventory.GetHighestsPerfect(session.LogicSettings.AmountOfPokemonToDisplayOnStart);

Expand All @@ -51,12 +45,6 @@ public static async Task Execute(ISession session)
PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon),
PokemonInfo.GetCandy(pokemon, myPokemonFamilies, myPokeSettings))).ToList();
var pokemonPairedWithStatsIvForUpgrade =
highestsPokemonIvForUpgrade.Select(
pokemon =>
Tuple.Create(pokemon, PokemonInfo.CalculateMaxCp(pokemon),
PokemonInfo.CalculatePokemonPerfection(pokemon), PokemonInfo.GetLevel(pokemon),
PokemonInfo.GetPokemonMove1(pokemon), PokemonInfo.GetPokemonMove2(pokemon))).ToList();

session.EventDispatcher.Send(
new DisplayHighestsPokemonEvent
Expand All @@ -74,31 +62,6 @@ public static async Task Execute(ISession session)
PokemonList = pokemonPairedWithStatsIv
});

foreach (var pokemon in pokemonPairedWithStatsIvForUpgrade)
{
var dgdfs = pokemon.ToString();

var tokens = dgdfs.Split(new[] {"id"}, StringSplitOptions.None);
var splitone = tokens[1].Split('"');
var iv = session.Inventory.GetPerfect(pokemon.Item1);
if (iv >= session.LogicSettings.UpgradePokemonIvMinimum)
{
PokemonId.Add(ulong.Parse(splitone[2]));
}
}
foreach (var t in pokemonPairedWithStatsCpForUpgrade)
{
var dgdfs = t.ToString();
var tokens = dgdfs.Split(new[] {"id"}, StringSplitOptions.None);
var splitone = tokens[1].Split('"');
var tokensSplit = tokens[1].Split(new[] {"cp"}, StringSplitOptions.None);
var tokenSplitAgain = tokensSplit[1].Split(' ');
var tokenSplitAgain2 = tokenSplitAgain[1].Split(',');
if (float.Parse(tokenSplitAgain2[0]) >= session.LogicSettings.UpgradePokemonCpMinimum)
{
PokemonIdcp.Add(ulong.Parse(splitone[2]));
}
}
var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
? await session.Inventory.GetHighestsPerfect(1000)
: await session.Inventory.GetHighestsCp(1000);
Expand Down
29 changes: 21 additions & 8 deletions PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,31 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
foreach (var duplicatePokemon in duplicatePokemons)
{
cancellationToken.ThrowIfCancellationRequested();

var pokemonTransferFilter = session.Inventory.GetPokemonTransferFilter(duplicatePokemon.PokemonId);

if (duplicatePokemon.Cp >=
pokemonTransferFilter.KeepMinCp ||
PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) >
pokemonTransferFilter.KeepMinIvPercentage ||
pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move1) ||
pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move2))
if (pokemonTransferFilter != null && session.LogicSettings.KeepMinOperator.ToLower().Equals("and"))
{
continue;
if ((duplicatePokemon.Cp >= pokemonTransferFilter.KeepMinCp &&
PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) >= pokemonTransferFilter.KeepMinIvPercentage) ||
pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move1) ||
pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move2))
{
continue;
}
}

else if(pokemonTransferFilter != null)
{
if (duplicatePokemon.Cp >= pokemonTransferFilter.KeepMinCp ||
PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) >
pokemonTransferFilter.KeepMinIvPercentage ||
pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move1) ||
pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move2))
{
continue;
}
}

await session.Client.Inventory.TransferPokemon(duplicatePokemon.Id);
await session.Inventory.DeletePokemonFromInvById(duplicatePokemon.Id);

Expand Down