Exemplo n.º 1
0
        public PokemonDataViewModel(PokemonData pokemon, PokemonSettings setting = null, Candy candy = null)
        {
            this.PowerupText  = "Upgrade";
            this.AllowPowerup = true;

            this.PokemonData = pokemon;
            this.Id          = pokemon.Id;
            this.PokemonName = pokemon.PokemonId;
            this.HP          = pokemon.Stamina;
            this.MaxHP       = pokemon.StaminaMax;
            this.IV          = PokemonInfo.CalculatePokemonPerfection(pokemon);
            this.CP          = PokemonInfo.CalculateCp(pokemon);
            this.Level       = (int)PokemonInfo.GetLevel(pokemon);
            this.Favorited   = pokemon.Favorite > 0;
            this.IsSelected  = false;
            this.Move1       = pokemon.Move1.ToString();
            this.Move2       = pokemon.Move2.ToString();

            if (setting != null && candy != null)
            {
                this.PokemonSettings = setting;
                this.AllowEvolve     = candy.Candy_ >= setting.CandyToEvolve && setting.EvolutionIds.Count > 0;
                this.Candy           = candy.Candy_;
            }
        }
Exemplo n.º 2
0
        public static async Task SaveAsExcel(ISession session, string Filename = "")
        {
            await Task.Run(() =>
            {
                var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
                    ? session.Inventory.GetHighestsPerfect(1000).Result
                    : session.Inventory.GetHighestsCp(1000).Result;
                string file = !string.IsNullOrEmpty(Filename)
                    ? Filename
                    : $"config\\{session.Settings.GoogleUsername}{session.Settings.PtcUsername}\\allpokemon.xlsx";
                int rowNum = 1;
                using (Stream stream = File.OpenWrite(file))
                    using (var package = new ExcelPackage(stream))
                    {
                        var ws = package.Workbook.Worksheets.Add("Pokemons");
                        foreach (var item in allPokemonInBag)
                        {
                            if (rowNum == 1)
                            {
                                ws.Cells[1, 1].Value              = "#";
                                ws.Cells[1, 2].Value              = "Pokemon";
                                ws.Cells[1, 3].Value              = "Display Name";
                                ws.Cells[1, 4].Value              = "Nickname";
                                ws.Cells[1, 5].Value              = "IV";
                                ws.Cells[1, 6].Value              = "Attack";
                                ws.Cells[1, 7].Value              = "Defense";
                                ws.Cells[1, 8].Value              = "Stamina";
                                ws.Cells[1, 9].Value              = "HP";
                                ws.Cells[1, 10].Value             = "MaxHP";
                                ws.Cells[1, 11].Value             = "CP";
                                ws.Cells[1, 12].Value             = "Candy";
                                ws.Cells[1, 13].Value             = "Level";
                                ws.Cells[1, 14].Value             = "Move1";
                                ws.Cells[1, 15].Value             = "Move2";
                                ws.Cells["A1:O1"].AutoFilter      = true;
                                ws.Cells["A1:O1"].Style.Font.Bold = true;
                            }
                            ws.Cells[rowNum + 1, 1].Value = rowNum;
                            ws.Cells[rowNum + 1, 2].Value = item.PokemonId.ToString();
                            ws.Cells[rowNum + 1, 3].Value = item.Nickname;
                            ws.Cells[rowNum + 1, 4].Value = item.OwnerName;
                            ws.Cells[rowNum + 1, 5].Value = Math.Round(PokemonInfo.CalculatePokemonPerfection(item), 2);

                            ws.Cells[rowNum + 1, 6].Value  = item.IndividualAttack;
                            ws.Cells[rowNum + 1, 7].Value  = item.IndividualDefense;
                            ws.Cells[rowNum + 1, 8].Value  = item.IndividualStamina;
                            ws.Cells[rowNum + 1, 9].Value  = item.Stamina;
                            ws.Cells[rowNum + 1, 10].Value = item.StaminaMax;
                            ws.Cells[rowNum + 1, 11].Value = PokemonInfo.CalculateCp(item);
                            ws.Cells[rowNum + 1, 12].Value = session.Inventory.GetCandy(item.PokemonId);
                            ws.Cells[rowNum + 1, 13].Value = PokemonInfo.GetLevel(item);
                            ws.Cells[rowNum + 1, 14].Value = item.Move1.ToString();
                            ws.Cells[rowNum + 1, 15].Value = item.Move2.ToString();
                            rowNum++;
                        }
                        package.Save();
                    }
            });
        }
Exemplo n.º 3
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken, ulong pokemonId = 0)
        {
            PokemonData newBuddy = null;
            if (pokemonId == 0)
            {
                if (string.IsNullOrEmpty(session.LogicSettings.DefaultBuddyPokemon))
                    return;

                PokemonId buddyPokemonId;
                bool success = Enum.TryParse(session.LogicSettings.DefaultBuddyPokemon, out buddyPokemonId);
                if (!success)
                {
                    // Invalid buddy pokemon type
                    Logger.Write($"The DefaultBuddyPokemon ({session.LogicSettings.DefaultBuddyPokemon}) is not a valid pokemon.", LogLevel.Error);
                    return;
                }

                if (session.Profile.PlayerData.BuddyPokemon?.Id > 0)
                {
                    var currentBuddy = (await session.Inventory.GetPokemons().ConfigureAwait(false)).FirstOrDefault(x => x.Id == session.Profile.PlayerData.BuddyPokemon.Id);
                    if (currentBuddy.PokemonId == buddyPokemonId)
                    {
                        //dont change same buddy
                        return;
                    }
                }

                var buddy = (await session.Inventory.GetPokemons().ConfigureAwait(false)).Where(x => x.PokemonId == buddyPokemonId)
                .OrderByDescending(x => PokemonInfo.CalculateCp(x));

                if (session.LogicSettings.PrioritizeIvOverCp)
                {
                    buddy = buddy.OrderByDescending(x => PokemonInfo.CalculatePokemonPerfection(x));
                }
                newBuddy = buddy.FirstOrDefault();

                if (newBuddy == null)
                {
                    Logger.Write($"You don't have pokemon {session.LogicSettings.DefaultBuddyPokemon} to set as buddy");
                    return;
                }
            }
            if (newBuddy == null)
            {
                newBuddy = (await session.Inventory.GetPokemons().ConfigureAwait(false)).FirstOrDefault(x => x.Id == pokemonId);
            }
            if (newBuddy == null) return;

            var response = await session.Client.Player.SelectBuddy(newBuddy.Id).ConfigureAwait(false);

            if (response.Result == SetBuddyPokemonResponse.Types.Result.Success)
            {
                session.EventDispatcher.Send(new BuddyUpdateEvent(response.UpdatedBuddy, newBuddy));
            }
        }
Exemplo n.º 4
0
 public static double CP(this PokemonData pkm)
 {
     return(PokemonInfo.CalculateCp(pkm));
 }
Exemplo n.º 5
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            var pokemons = await session.Inventory.GetPokemons().ConfigureAwait(false);

            if (session.LogicSettings.TransferDuplicatePokemon && session.LogicSettings.RenamePokemonRespectTransferRule)
            {
                var duplicatePokemons = await
                                        session.Inventory.GetDuplicatePokemonToTransfer(
                    session.LogicSettings.PokemonsNotToTransfer,
                    session.LogicSettings.PokemonEvolveFilters,
                    session.LogicSettings.KeepPokemonsToBeEvolved,
                    session.LogicSettings.PrioritizeIvOverCp).ConfigureAwait(false);

                pokemons = pokemons.Where(x => !duplicatePokemons.Any(p => p.Id == x.Id));
            }

            if (session.LogicSettings.TransferWeakPokemon && session.LogicSettings.RenamePokemonRespectTransferRule)
            {
                var weakPokemons = await
                                   session.Inventory.GetWeakPokemonToTransfer(
                    session.LogicSettings.PokemonsNotToTransfer,
                    session.LogicSettings.PokemonEvolveFilters,
                    session.LogicSettings.KeepPokemonsToBeEvolved).ConfigureAwait(false);

                pokemons = pokemons.Where(x => !weakPokemons.Any(p => p.Id == x.Id));
            }
            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                var perfection  = Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon));
                var level       = PokemonInfo.GetLevel(pokemon);
                var pokemonName = session.Translation.GetPokemonTranslation(pokemon.PokemonId);
                var cp          = PokemonInfo.CalculateCp(pokemon);
                // iv number + templating part + pokemonName <= 12

                var newNickname = session.LogicSettings.RenameTemplate.ToUpper();
                newNickname = newNickname.Replace("{IV}", Math.Round(perfection, 0).ToString());
                newNickname = newNickname.Replace("{LEVEL}", Math.Round(level, 0).ToString());
                newNickname = newNickname.Replace("{CP}", cp.ToString());

                var nameLength = 18 - newNickname.Length;
                if (pokemonName.Length > nameLength && nameLength > 0)
                {
                    pokemonName = pokemonName.Substring(0, nameLength);
                }

                newNickname = newNickname.Replace("{NAME}", pokemonName);

                //verify
                if (nameLength <= 0)
                {
                    Logger.Write($"Your rename template : {session.LogicSettings.RenameTemplate} incorrect. : {pokemonName} / {newNickname}");
                    continue;
                }
                var oldNickname = pokemon.Nickname.Length != 0 ? pokemon.Nickname : pokemon.PokemonId.ToString();

                // If "RenameOnlyAboveIv" = true only rename pokemon with IV over "KeepMinIvPercentage"
                if ((!session.LogicSettings.RenameOnlyAboveIv ||
                     perfection >= session.LogicSettings.KeepMinIvPercentage) &&
                    newNickname != oldNickname)
                {
                    var result = await session.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname).ConfigureAwait(false);

                    if (result.Result == NicknamePokemonResponse.Types.Result.Success)
                    {
                        pokemon.Nickname = newNickname;

                        session.EventDispatcher.Send(new RenamePokemonEvent
                        {
                            Id          = pokemon.Id,
                            PokemonId   = pokemon.PokemonId,
                            OldNickname = oldNickname,
                            NewNickname = newNickname
                        });
                    }
                    //Delay only if the pokemon was really renamed!
                    await DelayingUtils.DelayAsync(session.LogicSettings.RenamePokemonActionDelay, 500, session.CancellationTokenSource.Token).ConfigureAwait(false);
                }
            }
        }
Exemplo n.º 6
0
 public static async Task SaveAsExcel(ISession session, string Filename = "")
 {
     await Task.Run(async() =>
     {
         var allPokemonInBag = session.LogicSettings.PrioritizeIvOverCp
             ? await session.Inventory.GetHighestsPerfect(1000).ConfigureAwait(false)
             : await session.Inventory.GetHighestsCp(1000).ConfigureAwait(false);
         string file = !string.IsNullOrEmpty(Filename)
             ? Filename
             : $"config\\{session.Settings.Username}\\allpokemon.xlsx";
         int rowNum = 1;
         using (Stream stream = File.OpenWrite(file))
             using (var package = new ExcelPackage(stream))
             {
                 var ws = package.Workbook.Worksheets.Add("Pokemons");
                 foreach (var item in allPokemonInBag)
                 {
                     var settings = await session.Inventory.GetPokemonSetting(item.PokemonId).ConfigureAwait(false);
                     if (rowNum == 1)
                     {
                         ws.Cells[1, 1].Value              = "#";
                         ws.Cells[1, 2].Value              = "Pokemon";
                         ws.Cells[1, 3].Value              = "Display Name";
                         ws.Cells[1, 4].Value              = "Nickname";
                         ws.Cells[1, 5].Value              = "IV";
                         ws.Cells[1, 6].Value              = "Attack";
                         ws.Cells[1, 7].Value              = "Defense";
                         ws.Cells[1, 8].Value              = "Stamina";
                         ws.Cells[1, 9].Value              = "HP";
                         ws.Cells[1, 10].Value             = "MaxHP";
                         ws.Cells[1, 11].Value             = "CP";
                         ws.Cells[1, 12].Value             = "Level";
                         ws.Cells[1, 13].Value             = "Candy";
                         ws.Cells[1, 14].Value             = "Move1";
                         ws.Cells[1, 15].Value             = "Move2";
                         ws.Cells[1, 16].Value             = "Type";
                         ws.Cells[1, 17].Value             = "Shiny";
                         ws.Cells[1, 18].Value             = "Form";
                         ws.Cells[1, 19].Value             = "Costume";
                         ws.Cells[1, 20].Value             = "Sex";
                         ws.Cells["A1:Q1"].AutoFilter      = true;
                         ws.Cells["A1:Q1"].Style.Font.Bold = true;
                     }
                     ws.Cells[rowNum + 1, 1].Value  = rowNum;
                     ws.Cells[rowNum + 1, 2].Value  = item.PokemonId.ToString();
                     ws.Cells[rowNum + 1, 3].Value  = item.Nickname;
                     ws.Cells[rowNum + 1, 4].Value  = item.OwnerName;
                     ws.Cells[rowNum + 1, 5].Value  = Math.Round(PokemonInfo.CalculatePokemonPerfection(item), 2);
                     ws.Cells[rowNum + 1, 6].Value  = item.IndividualAttack;
                     ws.Cells[rowNum + 1, 7].Value  = item.IndividualDefense;
                     ws.Cells[rowNum + 1, 8].Value  = item.IndividualStamina;
                     ws.Cells[rowNum + 1, 9].Value  = item.Stamina;
                     ws.Cells[rowNum + 1, 10].Value = item.StaminaMax;
                     ws.Cells[rowNum + 1, 11].Value = PokemonInfo.CalculateCp(item);
                     ws.Cells[rowNum + 1, 12].Value = PokemonInfo.GetLevel(item);
                     ws.Cells[rowNum + 1, 13].Value = session.Inventory.GetCandyCount(item.PokemonId);
                     ws.Cells[rowNum + 1, 14].Value = item.Move1.ToString();
                     ws.Cells[rowNum + 1, 15].Value = item.Move2.ToString();
                     ws.Cells[rowNum + 1, 16].Value = $"{settings.Type.ToString()},{settings.Type2.ToString()}";
                     ws.Cells[rowNum + 1, 17].Value = $"{(item.PokemonDisplay.Shiny ? "Yes" : "No")}";
                     ws.Cells[rowNum + 1, 18].Value = $"{(item.PokemonDisplay.Form.ToString().Replace("Unown", "").Replace("Unset", "Normal"))}";
                     ws.Cells[rowNum + 1, 19].Value = $"{(item.PokemonDisplay.Costume.ToString().Replace("Unset", "Regular"))}";
                     ws.Cells[rowNum + 1, 20].Value = $"{(item.PokemonDisplay.Gender.ToString().Replace("Less", "Genderless"))}";
                     rowNum++;
                 }
                 package.Save();
             }
     }).ConfigureAwait(false);
 }
Exemplo n.º 7
0
        public static async Task Execute(ISession session, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();
            TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
            var pokemons = session.Inventory.GetPokemons();

            if (session.LogicSettings.TransferDuplicatePokemon)
            {
                var duplicatePokemons =
                    await
                    session.Inventory.GetDuplicatePokemonToTransfer(
                        session.LogicSettings.PokemonsNotToTransfer,
                        session.LogicSettings.PokemonsToEvolve,
                        session.LogicSettings.KeepPokemonsThatCanEvolve,
                        session.LogicSettings.PrioritizeIvOverCp);

                pokemons = pokemons.Where(x => !duplicatePokemons.Any(p => p.Id == x.Id));
            }

            if (session.LogicSettings.TransferWeakPokemon)
            {
                var pokemonsFiltered =
                    pokemons.Where(pokemon => !session.LogicSettings.PokemonsNotToTransfer.Contains(pokemon.PokemonId) &&
                                   pokemon.Favorite == 0 &&
                                   pokemon.DeployedFortId == string.Empty)
                    .ToList().OrderBy(poke => poke.Cp);


                var weakPokemons = new List <PokemonData>();
                foreach (var pokemon in pokemonsFiltered)
                {
                    cancellationToken.ThrowIfCancellationRequested();
                    if ((pokemon.Cp >= session.LogicSettings.KeepMinCp) ||
                        (PokemonInfo.CalculatePokemonPerfection(pokemon) >= session.LogicSettings.KeepMinIvPercentage &&
                         session.LogicSettings.PrioritizeIvOverCp) ||
                        (PokemonInfo.GetLevel(pokemon) >= session.LogicSettings.KeepMinLvl && session.LogicSettings.UseKeepMinLvl) ||
                        pokemon.Favorite == 1)
                    {
                        continue;
                    }

                    weakPokemons.Add(pokemon);
                }
                pokemons = pokemons.Where(x => !weakPokemons.Any(p => p.Id == x.Id));
            }
            foreach (var pokemon in pokemons)
            {
                cancellationToken.ThrowIfCancellationRequested();
                TinyIoC.TinyIoCContainer.Current.Resolve <MultiAccountManager>().ThrowIfSwitchAccountRequested();
                var perfection  = Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon));
                var level       = PokemonInfo.GetLevel(pokemon);
                var pokemonName = session.Translation.GetPokemonTranslation(pokemon.PokemonId);
                var cp          = PokemonInfo.CalculateCp(pokemon);
                // iv number + templating part + pokemonName <= 12

                var newNickname = session.LogicSettings.RenameTemplate.ToUpper();
                newNickname = newNickname.Replace("{IV}", Math.Round(perfection, 0).ToString());
                newNickname = newNickname.Replace("{LEVEL}", Math.Round(level, 0).ToString());
                newNickname = newNickname.Replace("{CP}", cp.ToString());

                var nameLength = 18 - newNickname.Length;
                if (pokemonName.Length > nameLength && nameLength > 0)
                {
                    pokemonName = pokemonName.Substring(0, nameLength);
                }

                newNickname = newNickname.Replace("{NAME}", pokemonName);

                //verify
                if (Regex.IsMatch(newNickname, @"[^a-zA-Z0-9-_.%/\\]") || nameLength <= 0)
                {
                    Logger.Write($"Your rename template : {session.LogicSettings.RenameTemplate} incorrect. : {pokemonName} / {newNickname}");
                    continue;
                }
                var oldNickname = pokemon.Nickname.Length != 0 ? pokemon.Nickname : pokemon.PokemonId.ToString();

                // If "RenameOnlyAboveIv" = true only rename pokemon with IV over "KeepMinIvPercentage"
                if ((!session.LogicSettings.RenameOnlyAboveIv ||
                     perfection >= session.LogicSettings.KeepMinIvPercentage) &&
                    newNickname != oldNickname)
                {
                    var result = await session.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname);

                    if (result.Result == NicknamePokemonResponse.Types.Result.Success)
                    {
                        pokemon.Nickname = newNickname;

                        session.EventDispatcher.Send(new RenamePokemonEvent
                        {
                            Id          = pokemon.Id,
                            PokemonId   = pokemon.PokemonId,
                            OldNickname = oldNickname,
                            NewNickname = newNickname
                        });
                    }
                    //Delay only if the pokemon was really renamed!
                    DelayingUtils.Delay(session.LogicSettings.RenamePokemonActionDelay, 500);
                }
            }
        }