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

Improved bottleneck when run out of pokeballs #1280

Merged
merged 1 commit into from
Jul 28, 2016
Merged
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
10 changes: 9 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/CatchNearbyPokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,14 @@ public static async Task Execute(ISession session)
var pokemons = await GetNearbyPokemons(session);
Copy link

@VitaminPSG VitaminPSG Jul 28, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall);
var greatBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall);
var ultraBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall);
var masterBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall);
if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
return;
Why do you check a condition that will not change in the loop?

foreach (var pokemon in pokemons)
{
var pokeBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemPokeBall);
var greatBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemGreatBall);
var ultraBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemUltraBall);
var masterBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall);

if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
return;

if (session.LogicSettings.UsePokemonToNotCatchFilter &&
session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
{
Expand Down Expand Up @@ -78,4 +86,4 @@ private static async Task<IOrderedEnumerable<MapPokemon>> GetNearbyPokemons(ISes
return pokemons;
}
}
}
}