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

            client = new Client(ClientSettings);
            client.setFailure(new PokemonGo.RocketAPI.Logic.ApiFailureStrat(client));

            try
            {
                await client.Login.DoLogin();

                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);

                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.CalculatePokemonPerfection(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)));

                    PokemonListView.Items.Add(listViewItem);
                }
                PokemonListView.AutoResizeColumns(ColumnHeaderAutoResizeStyle.ColumnContent);
                Text = "Pokemon List | User: "******" | Pokemons: " + pokemons.Count() + "/" + profile.PlayerData.MaxPokemonStorage;
                EnabledButton(true);

                statusTexbox.Text = string.Empty;
            }
            catch (Exception e)
            {
                Logger.ColoredConsoleWrite(ConsoleColor.Red, "Error reloading Pokemon list: " + e.Message);
                await Task.Delay(500); // Lets the API make a little pause, so we dont get blocked

                Execute();
            }
        }
Ejemplo n.º 2
0
        private void InitialzePokemonListView()
        {
            PokemonListView.Columns.Clear();
            ColumnHeader columnheader;

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

            PokemonListView.Columns.Add(CreateColumn(th.TS("Catch Date")));
            PokemonListView.Columns.Add(CreateColumn(th.TS("Pokeball")));
            PokemonListView.Columns.Add(CreateColumn(th.TS("Num Upgrades")));
            PokemonListView.Columns.Add(CreateColumn(th.TS("Battles Attacked")));
            PokemonListView.Columns.Add(CreateColumn(th.TS("Battles Defended")));
            PokemonListView.Columns.Add(CreateColumn(th.TS("In Gym")));
            PokemonListView.Columns.Add(CreateColumn(th.TS("Capture Place")));

            PokemonListView.Columns["#"].DisplayIndex = 0;

            PokemonListView.ColumnClick     += new ColumnClickEventHandler(PokemonListView_ColumnClick);
            PokemonListView.ShowItemToolTips = true;
            PokemonListView.DoubleBuffered(true);
            PokemonListView.View = View.Details;
            createImageList();
        }