Skip to content

Commit

Permalink
Merge pull request #595 from kaeus/master
Browse files Browse the repository at this point in the history
[Feature] Rename Pokemon above KeepIvPercent with Iv value in name
  • Loading branch information
Yamashi authored Jul 26, 2016
2 parents 4ad24b5 + f8303db commit 94a9eba
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 1 deletion.
4 changes: 3 additions & 1 deletion PoGo.NecroBot.CLI/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,8 @@ public void Save(string path)
public bool UseLuckyEggsWhileEvolving = false;
public bool UsePokemonToNotCatchFilter = false;
public double WalkingSpeedInKilometerPerHour = 50;

public bool RenameAboveIv = false;

[JsonIgnore]
internal AuthSettings Auth = new AuthSettings();

Expand Down Expand Up @@ -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<KeyValuePair<ItemId, int>> ItemRecycleFilter => _settings.ItemRecycleFilter;
public ICollection<PokemonId> PokemonsToEvolve => _settings.PokemonsToEvolve;
public ICollection<PokemonId> PokemonsNotToTransfer => _settings.PokemonsNotToTransfer;
Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public interface ILogicSettings
bool UseLuckyEggsWhileEvolving { get; }
bool EvolveAllPokemonAboveIv { get; }
float EvolveAboveIvValue { get; }
bool RenameAboveIv { get; }

ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter { get; }

Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/PoGo.NecroBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
<Compile Include="Tasks\FarmPokestopsGPXTask.cs" />
<Compile Include="Tasks\FarmPokestopsTask.cs" />
<Compile Include="Tasks\RecycleItemsTask.cs" />
<Compile Include="Tasks\RenamePokemonTask.cs" />
<Compile Include="Tasks\TransferDuplicatePokemonTask.cs" />
<Compile Include="Event\UseLuckyEggEvent.cs" />
<Compile Include="State\VersionCheckState.cs" />
Expand Down
2 changes: 2 additions & 0 deletions PoGo.NecroBot.Logic/State/FarmState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand Down
50 changes: 50 additions & 0 deletions PoGo.NecroBot.Logic/Tasks/RenamePokemonTask.cs
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}."
});
}
}

}
}
}

0 comments on commit 94a9eba

Please sign in to comment.