-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #595 from kaeus/master
[Feature] Rename Pokemon above KeepIvPercent with Iv value in name
- Loading branch information
Showing
6 changed files
with
58 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}." | ||
}); | ||
} | ||
} | ||
|
||
} | ||
} | ||
} |