Ejemplo n.º 1
0
        private async void Execute()
        {
            EnabledButton(false, "Reloading Pokemon list.");


            await check();

            try
            {
                client = Logic.Logic._client;
                if (client.readyToUse != false)
                {
                    profile = await client.Player.GetPlayer();

                    inventory = await client.Inventory.GetInventory();

                    pokemons =
                        inventory.InventoryDelta.InventoryItems
                        .Select(i => i.InventoryItemData?.PokemonData)
                        .Where(p => p != null && p?.PokemonId > 0)
                        .OrderByDescending(key => key.Cp);
                    var families = inventory.InventoryDelta.InventoryItems
                                   .Select(i => i.InventoryItemData?.Candy)
                                   .Where(p => p != null && (int)p?.FamilyId > 0)
                                   .OrderByDescending(p => (int)p.FamilyId);

                    var imageSize = 50;

                    var imageList = new ImageList {
                        ImageSize = new Size(imageSize, imageSize)
                    };
                    PokemonListView.ShowItemToolTips = true;
                    PokemonListView.SmallImageList   = imageList;

                    var templates = await client.Download.GetItemTemplates();

                    var myPokemonSettings = templates.ItemTemplates.Select(i => i.PokemonSettings).Where(p => p != null && p?.FamilyId != PokemonFamilyId.FamilyUnset);
                    var pokemonSettings   = myPokemonSettings.ToList();

                    var myPokemonFamilies = inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.Candy).Where(p => p != null && p?.FamilyId != PokemonFamilyId.FamilyUnset);
                    var pokemonFamilies   = myPokemonFamilies.ToArray();

                    PokemonListView.DoubleBuffered(true);
                    PokemonListView.View = View.Details;

                    ColumnHeader columnheader;
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "Name";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "CP";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "IV A-D-S";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "LVL";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "Evolvable?";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "Height";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "Weight";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "HP";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "Attack";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "SpecialAttack (DPS)";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "#";
                    PokemonListView.Columns.Add(columnheader);
                    columnheader      = new ColumnHeader();
                    columnheader.Text = "% CP";
                    PokemonListView.Columns.Add(columnheader);

                    PokemonListView.BeginUpdate();
                    foreach (var pokemon in pokemons)
                    {
                        Bitmap pokemonImage = null;
                        await Task.Run(() =>
                        {
                            pokemonImage = GetPokemonImage((int)pokemon.PokemonId);
                        });

                        imageList.Images.Add(pokemon.PokemonId.ToString(), pokemonImage);

                        PokemonListView.LargeImageList = imageList;
                        var listViewItem = new ListViewItem();
                        listViewItem.Tag = pokemon;



                        var currentCandy = families
                                           .Where(i => (int)i.FamilyId <= (int)pokemon.PokemonId)
                                           .Select(f => f.Candy_)
                                           .First();
                        listViewItem.SubItems.Add(string.Format("{0}", pokemon.Cp));
                        listViewItem.SubItems.Add(string.Format("{0}% {1}-{2}-{3}", PokemonInfo.CalculatePokemonPerfectionIV(pokemon).ToString("0.00"), pokemon.IndividualAttack, pokemon.IndividualDefense, pokemon.IndividualStamina));
                        listViewItem.SubItems.Add(string.Format("{0}", PokemonInfo.GetLevel(pokemon)));
                        listViewItem.ImageKey = pokemon.PokemonId.ToString();

                        listViewItem.Text = string.Format((pokemon.Favorite == 1) ? "{0} ★" : "{0}", StringUtils.getPokemonNameByLanguage(ClientSettings, (PokemonId)pokemon.PokemonId));

                        listViewItem.ToolTipText = new DateTime((long)pokemon.CreationTimeMs * 10000).AddYears(1769).ToString("dd/MM/yyyy HH:mm:ss");
                        if (pokemon.Nickname != "")
                        {
                            listViewItem.ToolTipText += "\nNickname: " + pokemon.Nickname;
                        }

                        var settings    = pokemonSettings.Single(x => x.PokemonId == pokemon.PokemonId);
                        var familyCandy = pokemonFamilies.Single(x => settings.FamilyId == x.FamilyId);

                        if (settings.EvolutionIds.Count > 0 && familyCandy.Candy_ >= settings.CandyToEvolve)
                        {
                            listViewItem.SubItems.Add("Y (" + familyCandy.Candy_ + "/" + settings.CandyToEvolve + ")");
                            listViewItem.Checked = true;
                        }
                        else
                        {
                            if (settings.EvolutionIds.Count > 0)
                            {
                                listViewItem.SubItems.Add("N (" + familyCandy.Candy_ + "/" + settings.CandyToEvolve + ")");
                            }
                            else
                            {
                                listViewItem.SubItems.Add("N (" + familyCandy.Candy_ + "/Max)");
                            }
                        }
                        listViewItem.SubItems.Add(string.Format("{0}", Math.Round(pokemon.HeightM, 2)));
                        listViewItem.SubItems.Add(string.Format("{0}", Math.Round(pokemon.WeightKg, 2)));
                        listViewItem.SubItems.Add(string.Format("{0}/{1}", pokemon.Stamina, pokemon.StaminaMax));
                        listViewItem.SubItems.Add(string.Format("{0}", pokemon.Move1));
                        listViewItem.SubItems.Add(string.Format("{0} ({1})", pokemon.Move2, PokemonInfo.GetAttack(pokemon.Move2)));
                        listViewItem.SubItems.Add(string.Format("{0}", (int)pokemon.PokemonId));
                        listViewItem.SubItems.Add(string.Format("{0}", PokemonInfo.CalculatePokemonPerfection(pokemon).ToString("0.00")));
                        PokemonListView.Items.Add(listViewItem);
                    }
                    PokemonListView.EndUpdate();
                    PokemonListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                    Text = "Pokemon List | User: "******" | Pokemons: " + pokemons.Count() + "/" + profile.PlayerData.MaxPokemonStorage;
                    EnabledButton(true);

                    statusTexbox.Text = string.Empty;
                }
            }
            catch (Exception e)
            {
                Logger.Error("[PokemonList-Error] " + e.StackTrace);
                await Task.Delay(1000); // Lets the API make a little pause, so we dont get blocked

                Execute();
            }
        }