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

Rewrote most of the upgrade code to actually work properly. #1957

Merged
merged 3 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 @@ -102,6 +102,7 @@ public interface ILogicSettings
float UseBerriesMinIv { get; }
double UseBerriesBelowCatchProbability { get; }
string UseBerriesOperator { get; }
string UpgradePokemonMinimumStatsOperator { get; }
int MaxTravelDistanceInMeters { get; }
bool UseGpxPathing { get; }
string GpxFile { get; }
Expand Down
37 changes: 30 additions & 7 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -349,25 +349,25 @@ public async Task<IEnumerable<PokemonSettings>> GetPokemonSettings()

public async Task<IEnumerable<PokemonData>> GetPokemonToEvolve(IEnumerable<PokemonId> filter = null)
{
var myPokemons = await GetPokemons();
myPokemons = myPokemons.Where(p => p.DeployedFortId == string.Empty).OrderByDescending(p => p.Cp);
var myPokemon = await GetPokemons();
myPokemon = myPokemon.Where(p => p.DeployedFortId == string.Empty).OrderByDescending(p => p.Cp);
//Don't evolve pokemon in gyms
IEnumerable<PokemonId> pokemonIds = filter as PokemonId[] ?? filter.ToArray();
if (pokemonIds.Any())
{
myPokemons =
myPokemons.Where(
myPokemon =
myPokemon.Where(
p => (_logicSettings.EvolveAllPokemonWithEnoughCandy && pokemonIds.Contains(p.PokemonId)) ||
(_logicSettings.EvolveAllPokemonAboveIv &&
(PokemonInfo.CalculatePokemonPerfection(p) >= _logicSettings.EvolveAboveIvValue)));
}
else if (_logicSettings.EvolveAllPokemonAboveIv)
{
myPokemons =
myPokemons.Where(
myPokemon =
myPokemon.Where(
p => PokemonInfo.CalculatePokemonPerfection(p) >= _logicSettings.EvolveAboveIvValue);
}
var pokemons = myPokemons.ToList();
var pokemons = myPokemon.ToList();

var myPokemonSettings = await GetPokemonSettings();
var pokemonSettings = myPokemonSettings.ToList();
Expand Down Expand Up @@ -399,6 +399,29 @@ public async Task<IEnumerable<PokemonData>> GetPokemonToEvolve(IEnumerable<Pokem
return pokemonToEvolve;
}

public async Task<List<PokemonData>> GetPokemonToUpgrade()
{
var upgradePokemon = new List<PokemonData>();

if (!_logicSettings.AutomaticallyLevelUpPokemon)
return upgradePokemon;

var myPokemon = await GetPokemons();
myPokemon = myPokemon.Where(p => p.DeployedFortId == string.Empty);

IEnumerable<PokemonData> highestPokemonForUpgrade = (_logicSettings.UpgradePokemonMinimumStatsOperator.ToLower().Equals("and")) ?
myPokemon.Where(
p => (p.Cp >= _logicSettings.UpgradePokemonCpMinimum &&
PokemonInfo.CalculatePokemonPerfection(p) >= _logicSettings.UpgradePokemonIvMinimum)).OrderByDescending(p => p.Cp).ToList() :
myPokemon.Where(
p => (p.Cp >= _logicSettings.UpgradePokemonCpMinimum ||
PokemonInfo.CalculatePokemonPerfection(p) >= _logicSettings.UpgradePokemonIvMinimum)).OrderByDescending(p => p.Cp).ToList();

return upgradePokemon = (_logicSettings.LevelUpByCPorIv.ToLower().Equals("iv")) ?
highestPokemonForUpgrade.OrderByDescending(PokemonInfo.CalculatePokemonPerfection).Take(_logicSettings.AmountOfTimesToUpgradeLoop).ToList() :
highestPokemonForUpgrade.Take(_logicSettings.AmountOfTimesToUpgradeLoop).ToList();
}

public TransferFilter GetPokemonTransferFilter(PokemonId pokemon)
{
if (_logicSettings.PokemonsTransferFilter != null &&
Expand Down
5 changes: 4 additions & 1 deletion PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@ public class GlobalSettings
public float UpgradePokemonCpMinimum;
[DefaultValue(95)]
public float UpgradePokemonIvMinimum;
[DefaultValue("and")]
public string UpgradePokemonMinimumStatsOperator;
//position
[DefaultValue(false)]
public bool DisableHumanWalking;
Expand Down Expand Up @@ -702,9 +704,10 @@ public LogicSettings(GlobalSettings settings)
public float UseBerriesMinIv => _settings.UseBerriesMinIv;
public double UseBerriesBelowCatchProbability => _settings.UseBerriesBelowCatchProbability;
public string UseBerriesOperator => _settings.UseBerriesOperator;

public float UpgradePokemonIvMinimum => _settings.UpgradePokemonIvMinimum;
public float UpgradePokemonCpMinimum => _settings.UpgradePokemonCpMinimum;
public string UpgradePokemonMinimumStatsOperator => _settings.UpgradePokemonMinimumStatsOperator;
public double WalkingSpeedInKilometerPerHour => _settings.WalkingSpeedInKilometerPerHour;
public bool EvolveAllPokemonWithEnoughCandy => _settings.EvolveAllPokemonWithEnoughCandy;
public bool KeepPokemonsThatCanEvolve => _settings.KeepPokemonsThatCanEvolve;
Expand Down
1 change: 0 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/DisplayPokemonStatsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ public class DisplayPokemonStatsTask
{
public static List<ulong> PokemonId = new List<ulong>();


public static List<ulong> PokemonIdcp = new List<ulong>();

public static async Task Execute(ISession session)
Expand Down
89 changes: 27 additions & 62 deletions PoGo.NecroBot.Logic/Tasks/LevelUpPokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Threading.Tasks;
using PoGo.NecroBot.Logic.Logging;
using PoGo.NecroBot.Logic.State;
using System.Collections.Generic;
using POGOProtos.Enums;

#endregion

Expand All @@ -15,74 +17,37 @@ internal class LevelUpPokemonTask
public static async Task Execute(ISession session, CancellationToken cancellationToken)
{
if (await session.Inventory.GetStarDust() <= session.LogicSettings.GetMinStarDustForLevelUp)
{
return;
}
if (session.LogicSettings.LevelUpByCPorIv.ToLower().Contains("iv") && DisplayPokemonStatsTask.PokemonId.Count != 0)
{
for (int i = 0; i < session.LogicSettings.AmountOfTimesToUpgradeLoop; i++)
{
var rand = new Random();
var randomNumber = rand.Next(0, DisplayPokemonStatsTask.PokemonId.Count - 1);

var upgradeResult =
await session.Inventory.UpgradePokemon(DisplayPokemonStatsTask.PokemonId[randomNumber]);
if (upgradeResult.Result.ToString().ToLower().Contains("success"))
{
Logger.Write("Pokemon Upgraded:" + upgradeResult.UpgradedPokemon.PokemonId + ":" +
upgradeResult.UpgradedPokemon.Cp);
}
else if (upgradeResult.Result.ToString().ToLower().Contains("insufficient"))
{
Logger.Write("Pokemon Upgrade Failed Not Enough Resources");
break;
}
else if (upgradeResult.Result.ToString().Contains("ErrorUpgradeNotAvailable"))
{
Logger.Write("Pokemon Is At Max Level For Your Level");
break;
}
else
{
Logger.Write(
"Pokemon Upgrade Failed Unknown Error");
break;
}
}
var upgradablePokemon = await session.Inventory.GetPokemonToUpgrade();
if (upgradablePokemon.Count == 0)
return;

}
else if (session.LogicSettings.LevelUpByCPorIv.ToLower().Contains("cp") && DisplayPokemonStatsTask.PokemonIdcp.Count != 0)
foreach (var pokemon in upgradablePokemon)
{
for (int i = 0; i < session.LogicSettings.AmountOfTimesToUpgradeLoop; i++)
var upgradeResult = await session.Inventory.UpgradePokemon(pokemon.Id);
if (upgradeResult.Result.ToString().ToLower().Contains("success"))
{
var rand = new Random();
var randomNumber = rand.Next(0, DisplayPokemonStatsTask.PokemonIdcp.Count - 1);
var upgradeResult =
await session.Inventory.UpgradePokemon(DisplayPokemonStatsTask.PokemonIdcp[randomNumber]);
if (upgradeResult.Result.ToString().ToLower().Contains("success"))
{
Logger.Write("Pokemon Upgraded:" + upgradeResult.UpgradedPokemon.PokemonId + ":" +
upgradeResult.UpgradedPokemon.Cp);
}
else if (upgradeResult.Result.ToString().ToLower().Contains("insufficient"))
{
Logger.Write("Pokemon Upgrade Failed Not Enough Resources");
break;
}
else if (upgradeResult.Result.ToString().Contains("ErrorUpgradeNotAvailable"))
{
Logger.Write("Pokemon Is At Max Level For Your Level");
break;
}
else
{
Logger.Write(
"Pokemon Upgrade Failed Unknown Error, Pokemon Could Be Max Level For Your Level The Pokemon That Caused Issue Was:" +
upgradeResult.UpgradedPokemon.PokemonId);
break;
}
Logger.Write("Pokemon Upgraded:" + upgradeResult.UpgradedPokemon.PokemonId + ":" +
upgradeResult.UpgradedPokemon.Cp);
}
else if (upgradeResult.Result.ToString().ToLower().Contains("insufficient"))
{
Logger.Write("Pokemon Upgrade Failed Not Enough Resources");
break;
}
else if (upgradeResult.Result.ToString().Contains("ErrorUpgradeNotAvailable"))
{
Logger.Write("Pokemon Is At Max Level For Your Level");
break;
}
else
{
Logger.Write(
"Pokemon Upgrade Failed Unknown Error, Pokemon Could Be Max Level For Your Level The Pokemon That Caused Issue Was:" +
upgradeResult.UpgradedPokemon.PokemonId);
break;
}

}
}
}
Expand Down