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

Added PokemonInfo to API for BaseStats,Level,MaxCP,Perfection. Fixed proto for cpMultipliers(int->float) #139

Merged
merged 4 commits into from
Jul 23, 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
4 changes: 2 additions & 2 deletions PokemonGo.RocketAPI.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task<IEnumerable<PokemonData>> GetHighestsPerfect(int limit)
{
var myPokemon = await GetPokemons();
var pokemons = myPokemon.ToList();
return pokemons.OrderByDescending(Logic.CalculatePokemonPerfection).Take(limit);
return pokemons.OrderByDescending(PokemonInfo.CalculatePokemonPerfection).Take(limit);
}

public async Task<PokemonData> GetHighestPokemonOfTypeByCP(PokemonData pokemon)
Expand All @@ -92,7 +92,7 @@ public async Task<PokemonData> GetHighestPokemonOfTypeByCP(PokemonData pokemon)
var pokemons = myPokemon.ToList();
return pokemons.Where(x => x.PokemonId == pokemon.PokemonId)
.OrderByDescending(x => x.Cp)
.First();
.FirstOrDefault();
}

public async Task<int> GetItemAmountByType(MiscEnums.Item type)
Expand Down
21 changes: 8 additions & 13 deletions PokemonGo.RocketAPI.Logic/Logic.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,14 @@ public Logic(ISettings clientSettings)
_navigation = new Navigation(_client);
}

public static float CalculatePokemonPerfection(PokemonData poke)
{
return (poke.IndividualAttack*2 + poke.IndividualDefense + poke.IndividualStamina)/(4.0f*15.0f)*100.0f;
}

private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemon)
{
CatchPokemonResponse caughtPokemonResponse;
do
{
var probability = encounter?.CaptureProbability?.CaptureProbability_?.FirstOrDefault();
if ((probability.HasValue && probability.Value < 0.35 && encounter.WildPokemon?.PokemonData?.Cp > 400) ||
CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData) >=
_clientSettings.KeepMinIVPercentage)
{
//Throw berry is we can
Expand All @@ -60,7 +55,7 @@ private async Task CatchEncounter(EncounterResponse encounter, MapPokemon pokemo
pokemon.Longitude, pokeball);
Logger.Write(
caughtPokemonResponse.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess
? $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) ({Math.Round(CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfection) | Chance: {encounter?.CaptureProbability.CaptureProbability_.First()} | {Math.Round(distance)}m distance | with {pokeball} "
? $"{pokemon.PokemonId} Lvl {PokemonInfo.GetLevel(encounter?.WildPokemon?.PokemonData)} ({encounter?.WildPokemon?.PokemonData?.Cp}/{PokemonInfo.CalculateMaxCP(encounter?.WildPokemon?.PokemonData)} CP) ({Math.Round(PokemonInfo.CalculatePokemonPerfection(encounter?.WildPokemon?.PokemonData)).ToString("0.00")}% perfection) | Chance: {encounter?.CaptureProbability.CaptureProbability_.First()} | {Math.Round(distance)}m distance | with {pokeball} "
: $"{pokemon.PokemonId} ({encounter?.WildPokemon?.PokemonData?.Cp} CP) Chance: {Math.Round(Convert.ToDouble(encounter?.CaptureProbability?.CaptureProbability_.First()))} | {Math.Round(distance)}m distance {caughtPokemonResponse.Status} | with {pokeball}",
LogLevel.Caught);
await DisplayPlayerLevelInTitle(true);
Expand Down Expand Up @@ -436,14 +431,14 @@ private async Task TransferDuplicatePokemon(bool keepPokemonsThatCanEvolve = fal

foreach (var duplicatePokemon in duplicatePokemons)
{
if (CalculatePokemonPerfection(duplicatePokemon) >= _clientSettings.KeepMinIVPercentage ||
if (PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) >= _clientSettings.KeepMinIVPercentage ||
duplicatePokemon.Cp > _clientSettings.KeepMinCP)
continue;

var transfer = await _client.TransferPokemon(duplicatePokemon.Id);
var bestPokemonOfType = await _inventory.GetHighestPokemonOfTypeByCP(duplicatePokemon);
Logger.Write(
$"{duplicatePokemon.PokemonId} with {duplicatePokemon.Cp} ({CalculatePokemonPerfection(duplicatePokemon).ToString("0.00")} % perfect) CP (Best: {bestPokemonOfType.Cp} | ({CalculatePokemonPerfection(bestPokemonOfType).ToString("0.00")} % perfect))",
$"{duplicatePokemon.PokemonId} with {duplicatePokemon.Cp} ({PokemonInfo.CalculatePokemonPerfection(duplicatePokemon).ToString("0.00")} % perfect) CP (Best: {bestPokemonOfType.Cp} | ({PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType).ToString("0.00")} % perfect))",
LogLevel.Transfer);
await Task.Delay(500);
}
Expand All @@ -465,18 +460,18 @@ public async Task UseBerry(ulong encounterId, string spawnPointId)

private async Task DisplayHighests()
{
Logger.Write("====== DisplayHighestsCP ======", LogLevel.Info, ConsoleColor.Yellow);
Logger.Write($"====== DisplayHighestsCP ======", LogLevel.Info, ConsoleColor.Yellow);
var highestsPokemonCP = await _inventory.GetHighestsCP(20);
foreach (var pokemon in highestsPokemonCP)
Logger.Write(
$"# CP {pokemon.Cp}\t| ({CalculatePokemonPerfection(pokemon).ToString("0.00")}\t% perfect) NAME: '{pokemon.PokemonId}'",
$"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCP(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect)\t| Lvl {PokemonInfo.GetLevel(pokemon)}\t NAME: '{pokemon.PokemonId}'",
LogLevel.Info, ConsoleColor.Yellow);
Logger.Write("====== DisplayHighestsPerfect ======", LogLevel.Info, ConsoleColor.Yellow);
Logger.Write($"====== DisplayHighestsPerfect ======", LogLevel.Info, ConsoleColor.Yellow);
var highestsPokemonPerfect = await _inventory.GetHighestsPerfect(10);
foreach (var pokemon in highestsPokemonPerfect)
{
Logger.Write(
$"# CP {pokemon.Cp}\t| ({CalculatePokemonPerfection(pokemon).ToString("0.00")}\t% perfect) NAME: '{pokemon.PokemonId}'",
$"# CP {pokemon.Cp.ToString().PadLeft(4, ' ')}/{PokemonInfo.CalculateMaxCP(pokemon).ToString().PadLeft(4, ' ')} | ({PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")}% perfect)\t| Lvl {PokemonInfo.GetLevel(pokemon)}\t NAME: '{pokemon.PokemonId}'",
LogLevel.Info, ConsoleColor.Yellow);
}
}
Expand Down
Loading