From 8ffb13c81dca647df79ca58cf3d6e328b3b0c67f Mon Sep 17 00:00:00 2001 From: Andrew Waters Date: Tue, 26 Jul 2016 09:38:37 -0400 Subject: [PATCH] Setting to rename pokemon with their Name_IV for ease in manual evolving after capturing. Only renames those above the KeepMinIvPercentage. #587 #519 --- PoGo.NecroBot.CLI/Settings.cs | 4 +- PoGo.NecroBot.Logic/ILogicSettings.cs | 1 + .../PoGo.NecroBot.Logic.csproj | 1 + PoGo.NecroBot.Logic/State/FarmState.cs | 2 + .../Tasks/FarmPokestopsTask.cs | 1 + .../Tasks/RenamePokemonTask.cs | 50 +++++++++++++++++++ 6 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs diff --git a/PoGo.NecroBot.CLI/Settings.cs b/PoGo.NecroBot.CLI/Settings.cs index 64045e593..8a5c2d993 100644 --- a/PoGo.NecroBot.CLI/Settings.cs +++ b/PoGo.NecroBot.CLI/Settings.cs @@ -145,7 +145,8 @@ public void Save(string path) public bool UseLuckyEggsWhileEvolving = false; public bool UsePokemonToNotCatchFilter = false; public double WalkingSpeedInKilometerPerHour = 50; - + public bool RenameAboveIv = false; + public List> ItemRecycleFilter = new List> { new KeyValuePair(ItemId.ItemUnknown, 0), @@ -261,6 +262,7 @@ public LogicSettings(GlobalSettings settings) public bool UseLuckyEggsWhileEvolving => _settings.UseLuckyEggsWhileEvolving; public bool EvolveAllPokemonAboveIv => _settings.EvolveAllPokemonAboveIv; public float EvolveAboveIvValue => _settings.EvolveAboveIvValue; + public bool RenameAboveIv => _settings.RenameAboveIv; public ICollection> ItemRecycleFilter => _settings.ItemRecycleFilter; public ICollection PokemonsToEvolve => _settings.PokemonsToEvolve; public ICollection PokemonsNotToTransfer => _settings.PokemonsNotToTransfer; diff --git a/PoGo.NecroBot.Logic/ILogicSettings.cs b/PoGo.NecroBot.Logic/ILogicSettings.cs index 47b57010a..75fc75948 100644 --- a/PoGo.NecroBot.Logic/ILogicSettings.cs +++ b/PoGo.NecroBot.Logic/ILogicSettings.cs @@ -26,6 +26,7 @@ public interface ILogicSettings bool UseLuckyEggsWhileEvolving { get; } bool EvolveAllPokemonAboveIv { get; } float EvolveAboveIvValue { get; } + bool RenameAboveIv { get; } ICollection> ItemRecycleFilter { get; } diff --git a/PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj b/PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj index 5d0abeb6c..e38bc26ad 100644 --- a/PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj +++ b/PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj @@ -82,6 +82,7 @@ + diff --git a/PoGo.NecroBot.Logic/State/FarmState.cs b/PoGo.NecroBot.Logic/State/FarmState.cs index 8d389f0d9..9684a98ef 100644 --- a/PoGo.NecroBot.Logic/State/FarmState.cs +++ b/PoGo.NecroBot.Logic/State/FarmState.cs @@ -10,6 +10,8 @@ public class FarmState : IState { public IState Execute(Context ctx, StateMachine machine) { + RenamePokemonTask.Execute(ctx, machine); + if (ctx.LogicSettings.EvolveAllPokemonAboveIv || ctx.LogicSettings.EvolveAllPokemonWithEnoughCandy) { EvolvePokemonTask.Execute(ctx, machine); diff --git a/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs b/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs index f5b66e705..96e591d12 100644 --- a/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs @@ -88,6 +88,7 @@ public static void Execute(Context ctx, StateMachine machine) if (++stopsHit%5 == 0) //TODO: OR item/pokemon bag is full { stopsHit = 0; + RenamePokemonTask.Execute(ctx, machine); RecycleItemsTask.Execute(ctx, machine); if (ctx.LogicSettings.EvolveAllPokemonWithEnoughCandy || ctx.LogicSettings.EvolveAllPokemonAboveIv) { diff --git a/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs new file mode 100644 index 000000000..d70a06446 --- /dev/null +++ b/PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using PoGo.NecroBot.Logic.Event; +using PoGo.NecroBot.Logic.PoGoUtils; +using PoGo.NecroBot.Logic.State; + +namespace PoGo.NecroBot.Logic.Tasks +{ + public class RenamePokemonTask + { + public static void Execute(Context ctx, StateMachine machine) + { + var pokemons = ctx.Inventory.GetPokemons().Result; + + foreach (var pokemon in pokemons) + { + var perfection = Math.Round(PokemonInfo.CalculatePokemonPerfection(pokemon)); + var pokemonName = pokemon.PokemonId.ToString(); + if (pokemonName.Length > 10 - perfection.ToString().Length) + { + pokemonName = pokemonName.Substring(0, 10 - perfection.ToString().Length); + } + var newNickname = $"{pokemonName}_{perfection}"; + + if (perfection > ctx.LogicSettings.KeepMinIvPercentage && newNickname != pokemon.Nickname && ctx.LogicSettings.RenameAboveIv) + { + var result = ctx.Client.Inventory.NicknamePokemon(pokemon.Id, newNickname).Result; + + machine.Fire(new NoticeEvent + { + Message = $"Pokemon {pokemon.PokemonId} ({pokemon.Id}) renamed from {pokemon.Nickname} to {newNickname}." + }); + } + else if (newNickname == pokemon.Nickname && !ctx.LogicSettings.RenameAboveIv) + { + var result = ctx.Client.Inventory.NicknamePokemon(pokemon.Id, pokemon.PokemonId.ToString()); + + machine.Fire(new NoticeEvent + { + Message = $"Pokemon {pokemon.PokemonId} ({pokemon.Id}) renamed from {pokemon.Nickname} to {pokemon.PokemonId}." + }); + } + } + + } + } +}