Skip to content

Commit

Permalink
clean
Browse files Browse the repository at this point in the history
  • Loading branch information
Nicolas Schmitt committed Aug 1, 2016
1 parent fdec79f commit e85fd49
Showing 1 changed file with 30 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,44 +15,37 @@ class TransferPokemonTask
{
public static async Task Execute(ISession session, WebSocketSession webSocketSession, ulong pokemonId, string requestID)
{
try
{
var all = await session.Inventory.GetPokemons();
var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
var pokemon = pokemons.FirstOrDefault(p => p.Id == pokemonId);

if (pokemon == null) return;

var pokemonSettings = await session.Inventory.GetPokemonSettings();
var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

await session.Client.Inventory.TransferPokemon(pokemonId);
await session.Inventory.DeletePokemonFromInvById(pokemonId);

var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
? await session.Inventory.GetHighestPokemonOfTypeByIv(pokemon)
: await session.Inventory.GetHighestPokemonOfTypeByCp(pokemon)) ?? pokemon;

var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId);
var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);

family.Candy_++;

// Broadcast event as everyone would benefit
session.EventDispatcher.Send(new Logic.Event.TransferPokemonEvent
{
Id = pokemon.PokemonId,
Perfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(pokemon),
Cp = pokemon.Cp,
BestCp = bestPokemonOfType.Cp,
BestPerfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
FamilyCandies = family.Candy_
});
}
catch (Exception ex)
var all = await session.Inventory.GetPokemons();
var pokemons = all.OrderByDescending(x => x.Cp).ThenBy(n => n.StaminaMax);
var pokemon = pokemons.FirstOrDefault(p => p.Id == pokemonId);

if (pokemon == null) return;

var pokemonSettings = await session.Inventory.GetPokemonSettings();
var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

await session.Client.Inventory.TransferPokemon(pokemonId);
await session.Inventory.DeletePokemonFromInvById(pokemonId);

var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
? await session.Inventory.GetHighestPokemonOfTypeByIv(pokemon)
: await session.Inventory.GetHighestPokemonOfTypeByCp(pokemon)) ?? pokemon;

var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId);
var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);

family.Candy_++;

// Broadcast event as everyone would benefit
session.EventDispatcher.Send(new Logic.Event.TransferPokemonEvent
{
ex.ToString();
}
Id = pokemon.PokemonId,
Perfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(pokemon),
Cp = pokemon.Cp,
BestCp = bestPokemonOfType.Cp,
BestPerfection = Logic.PoGoUtils.PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
FamilyCandies = family.Candy_
});

await Task.Delay(500);
}
Expand Down

0 comments on commit e85fd49

Please sign in to comment.