Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add new option 'AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs' w… #2031

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ public interface ILogicSettings
string GpxFile { get; }
bool UseLuckyEggsWhileEvolving { get; }
int UseLuckyEggsMinPokemonAmount { get; }
bool AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs { get; }
bool EvolveAllPokemonAboveIv { get; }
float EvolveAboveIvValue { get; }
bool DumpPokemonStats { get; }
Expand Down
3 changes: 3 additions & 0 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,8 @@ public class GlobalSettings
public bool UseLuckyEggConstantly;
[DefaultValue(30)]
public int UseLuckyEggsMinPokemonAmount;
[DefaultValue(true)]
public Boolean AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs;
[DefaultValue(false)]
public bool UseLuckyEggsWhileEvolving;
[DefaultValue(false)]
Expand Down Expand Up @@ -749,6 +751,7 @@ public LogicSettings(GlobalSettings settings)
public bool UseGpxPathing => _settings.UseGpxPathing;
public bool UseLuckyEggsWhileEvolving => _settings.UseLuckyEggsWhileEvolving;
public int UseLuckyEggsMinPokemonAmount => _settings.UseLuckyEggsMinPokemonAmount;
public bool AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs => _settings.AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs;
public bool EvolveAllPokemonAboveIv => _settings.EvolveAllPokemonAboveIv;
public float EvolveAboveIvValue => _settings.EvolveAboveIvValue;
public bool RenamePokemon => _settings.RenamePokemon;
Expand Down
134 changes: 77 additions & 57 deletions PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
using PoGo.NecroBot.Logic.Utils;
using POGOProtos.Inventory.Item;
using PoGo.NecroBot.Logic.Common;
using System.Collections.Generic;
using POGOProtos.Data;

#endregion

Expand All @@ -32,15 +34,21 @@ public static async Task Execute(ISession session, CancellationToken cancellatio

if (pokemonToEvolve.Any())
{
if (session.LogicSettings.KeepPokemonsThatCanEvolve)
if (session.LogicSettings.AlwaysEvolveWithLuckyEggWhenMinPokemonAmountOccurs && await shouldUseLuckyEgg(session, pokemonToEvolve))
{
await UseLuckyEgg(session);
await evolve(session, pokemonToEvolve);
return;
}
else if (session.LogicSettings.KeepPokemonsThatCanEvolve)
{
var totalPokemon = await session.Inventory.GetPokemons();

var pokemonNeededInInventory = session.Profile.PlayerData.MaxPokemonStorage * session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage/100.0f;
var pokemonNeededInInventory = session.Profile.PlayerData.MaxPokemonStorage * session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage / 100.0f;
var needPokemonToStartEvolve = Math.Round(
Math.Max(0,
Math.Max(0,
Math.Min(pokemonNeededInInventory, session.Profile.PlayerData.MaxPokemonStorage)));

var deltaCount = needPokemonToStartEvolve - totalPokemon.Count();

if (deltaCount > 0)
Expand All @@ -50,64 +58,15 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
Message = session.Translation.GetTranslation(TranslationString.WaitingForMorePokemonToEvolve,
pokemonToEvolve.Count, deltaCount, totalPokemon.Count(), needPokemonToStartEvolve, session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage)
});

return;
}
}

var inventoryContent = await session.Inventory.GetItems();
}

var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg);
var luckyEgg = luckyEggs.FirstOrDefault();

if (session.LogicSettings.UseLuckyEggsWhileEvolving && luckyEgg != null && luckyEgg.Count > 0)
if (await shouldUseLuckyEgg(session, pokemonToEvolve))
{
if (pokemonToEvolve.Count >= session.LogicSettings.UseLuckyEggsMinPokemonAmount)
{
await UseLuckyEgg(session);
}
else
{
var evolvablePokemon = await session.Inventory.GetPokemons();

var deltaPokemonToUseLuckyEgg = session.LogicSettings.UseLuckyEggsMinPokemonAmount -
pokemonToEvolve.Count;

var availableSpace = session.Profile.PlayerData.MaxPokemonStorage - evolvablePokemon.Count();

if (deltaPokemonToUseLuckyEgg > availableSpace)
{
var possibleLimitInThisIteration = pokemonToEvolve.Count + availableSpace;

session.EventDispatcher.Send(new NoticeEvent()
{
Message = session.Translation.GetTranslation(TranslationString.UseLuckyEggsMinPokemonAmountTooHigh,
session.LogicSettings.UseLuckyEggsMinPokemonAmount, possibleLimitInThisIteration)
});
}
else
{
session.EventDispatcher.Send(new NoticeEvent()
{
Message = session.Translation.GetTranslation(TranslationString.CatchMorePokemonToUseLuckyEgg,
deltaPokemonToUseLuckyEgg)
});
}
}
}

foreach (var pokemon in pokemonToEvolve)
{
// no cancellationToken.ThrowIfCancellationRequested here, otherwise the lucky egg would be wasted.
var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id);

session.EventDispatcher.Send(new PokemonEvolveEvent
{
Id = pokemon.PokemonId,
Exp = evolveResponse.ExperienceAwarded,
Result = evolveResponse.Result
});
await UseLuckyEgg(session);
}
await evolve(session, pokemonToEvolve);
}
}

Expand All @@ -127,5 +86,66 @@ public static async Task UseLuckyEgg(ISession session)
if (luckyEgg != null) session.EventDispatcher.Send(new UseLuckyEggEvent {Count = luckyEgg.Count});
DelayingUtils.Delay(session.LogicSettings.DelayBetweenPokemonCatch, 2000);
}

private static async Task evolve(ISession session, List<PokemonData> pokemonToEvolve)
{
foreach (var pokemon in pokemonToEvolve)
{
// no cancellationToken.ThrowIfCancellationRequested here, otherwise the lucky egg would be wasted.
var evolveResponse = await session.Client.Inventory.EvolvePokemon(pokemon.Id);

session.EventDispatcher.Send(new PokemonEvolveEvent
{
Id = pokemon.PokemonId,
Exp = evolveResponse.ExperienceAwarded,
Result = evolveResponse.Result
});
}
}

private static async Task<Boolean> shouldUseLuckyEgg(ISession session, List<PokemonData> pokemonToEvolve)
{
var inventoryContent = await session.Inventory.GetItems();

var luckyEggs = inventoryContent.Where(p => p.ItemId == ItemId.ItemLuckyEgg);
var luckyEgg = luckyEggs.FirstOrDefault();

if (session.LogicSettings.UseLuckyEggsWhileEvolving && luckyEgg != null && luckyEgg.Count > 0)
{
if (pokemonToEvolve.Count >= session.LogicSettings.UseLuckyEggsMinPokemonAmount)
{
return true;
}
else
{
var evolvablePokemon = await session.Inventory.GetPokemons();

var deltaPokemonToUseLuckyEgg = session.LogicSettings.UseLuckyEggsMinPokemonAmount -
pokemonToEvolve.Count;

var availableSpace = session.Profile.PlayerData.MaxPokemonStorage - evolvablePokemon.Count();

if (deltaPokemonToUseLuckyEgg > availableSpace)
{
var possibleLimitInThisIteration = pokemonToEvolve.Count + availableSpace;

session.EventDispatcher.Send(new NoticeEvent()
{
Message = session.Translation.GetTranslation(TranslationString.UseLuckyEggsMinPokemonAmountTooHigh,
session.LogicSettings.UseLuckyEggsMinPokemonAmount, possibleLimitInThisIteration)
});
}
else
{
session.EventDispatcher.Send(new NoticeEvent()
{
Message = session.Translation.GetTranslation(TranslationString.CatchMorePokemonToUseLuckyEgg,
deltaPokemonToUseLuckyEgg)
});
}
}
}
return false;
}
}
}