Skip to content
This repository has been archived by the owner on Jul 30, 2020. It is now read-only.

Logic and CLI: added evolve features, fixed bugs #1982

Merged
merged 7 commits into from
Sep 29, 2017
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,11 @@
},
{
"Key": "waitingForMorePokemonToEvolve",
"Value": "Waiting to evolve {0} Pokemon once {1} more are caught! ({2}/{3} for {4,6:0.00}% inventory)"
"Value": "Waiting to evolve {0} Pokemons until {1} more are in storage! (In storage: {2} | Target: {3})"
},
{
"Key": "WaitingForMoreEvolutionsToEvolveWithEgg",
"Value": "Waiting for {0} more evolutions to evolve with lucky egg! (Possible: {1} | Needed: {2})"
},
{
"Key": "useLuckyEggsMinPokemonAmountTooHigh",
Expand Down
6 changes: 5 additions & 1 deletion PoGo.NecroBot.CLI/Config/Translations/translation.de.json
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,11 @@
},
{
"Key": "waitingForMorePokemonToEvolve",
"Value": "Warte mit Entwicklungen von {0} Pokemon bis {1} weitere gefangen wurden! ({2}/{3} bis {4}% Inventar Auslastung)"
"Value": "Warte mit Entwicklungen von {0} Pokemons bis {1} weitere im Speicher sind! (Im Speicher: {2} | Ziel: {3})"
},
{
"Key": "WaitingForMoreEvolutionsToEvolveWithEgg",
"Value": "Warte auf {0} weitere Entwicklungen um mit Gluecksei zu entwicklen! ({1} von {2} erreicht)"
},
{
"Key": "PokedexCatchedTelegram",
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.CLI/Forms/StarterConfigForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ private void WalkinSpeedPage_Commit(object sender, WizardPageConfirmEventArgs e)

settings.GoogleWalkConfig.UseGoogleWalk = chkEnableGoogle.Checked;
settings.GoogleWalkConfig.GoogleAPIKey = txtGoogleKey.Text;
settings.GoogleWalkConfig.UseGoogleWalk = chkAllowYourwalk.Checked;

settings.YoursWalkConfig.UseYoursWalk = chkAllowYourwalk.Checked;

settings.MapzenWalkConfig.UseMapzenWalk = chkMazen.Checked;
settings.MapzenWalkConfig.MapzenTurnByTurnApiKey = txtMapzenKey.Text;
Expand Down
7 changes: 5 additions & 2 deletions PoGo.NecroBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public enum TranslationString
EventPokemonCaptureFailed,
EventNoPokeballs,
WaitingForMorePokemonToEvolve,
WaitingForMoreEvolutionsToEvolveWithEgg,
UseLuckyEggsMinPokemonAmountTooHigh,
CatchMorePokemonToUseLuckyEgg,
EventUseBerry,
Expand Down Expand Up @@ -383,11 +384,13 @@ public class Translation : ITranslation
new KeyValuePair<TranslationString, string>(TranslationString.EventNoPokeballs,
"No Pokeballs - We missed a {0} with CP {1}"),
new KeyValuePair<TranslationString, string>(TranslationString.WaitingForMorePokemonToEvolve,
"Waiting to evolve {0} Pokemon once {1} more are caught! ({2}/{3} for {4,6:0.00}% inventory)"),
"Waiting to evolve {0} Pokemons until {1} more are in storage! (In storage: {2} | Target: {3})"),
new KeyValuePair<TranslationString, string>(TranslationString.WaitingForMoreEvolutionsToEvolveWithEgg,
"Waiting for {0} more evolutions to evolve with lucky egg! (Possible: {1} | Needed: {2})"),
new KeyValuePair<TranslationString, string>(TranslationString.UseLuckyEggsMinPokemonAmountTooHigh,
"Lucky eggs will never be used with UseLuckyEggsMinPokemonAmount set to {0}, use <= {1} instead"),
new KeyValuePair<TranslationString, string>(TranslationString.CatchMorePokemonToUseLuckyEgg,
"Catch {0} more Pokemon to use a Lucky Egg!"),
"Missing {0} more evolutions to use a Lucky Egg!"),
new KeyValuePair<TranslationString, string>(TranslationString.EventUseBerry,
"Used {0} | {1} remaining"),
new KeyValuePair<TranslationString, string>(TranslationString.ItemRazzBerry, "Razz Berry"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public interface ILogicSettings
int ByPassSpinCount { get; }
double AutoSnipeMaxDistance { get; }
bool EvolveAllPokemonWithEnoughCandy { get; }
bool EvolvePreserveMinCandiesFromFilter { get; }
bool KeepPokemonsThatCanEvolve { get; }

bool UseTransferFilterToCatch { get; }
Expand Down Expand Up @@ -147,6 +148,7 @@ public interface ILogicSettings
double RecycleInventoryAtUsagePercentage { get; }
double EvolveKeptPokemonsAtStorageUsagePercentage { get; }
int EvolveKeptPokemonIfBagHasOverThisManyPokemon { get; }
bool EvolveKeptPokemonsIfLuckyEggCanBeUsed { get; }
bool UseSnipeLimit { get; }
bool UsePokeStopLimit { get; }
bool UseCatchLimit { get; }
Expand Down
54 changes: 41 additions & 13 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,13 @@ public async Task<IEnumerable<InventoryItem>> GetCachedInventory()
return _client.Inventory.InventoryItems.Select(kvp => kvp.Value);
}

public async Task<IEnumerable<AppliedItems>> GetAppliedItems()
public async Task<IEnumerable<AppliedItem>> GetAppliedItems()
{
var inventory = await GetCachedInventory().ConfigureAwait(false);
return inventory
.Select(i => i.InventoryItemData?.AppliedItems)
.Where(p => p != null);
.Where(aItems => aItems?.Item != null)
.SelectMany(aItems => aItems.Item);
}

public async Task<IEnumerable<PokemonData>> GetSlashedPokemonToTransfer()
Expand Down Expand Up @@ -271,8 +272,9 @@ public async Task<IEnumerable<PokemonData>> GetDuplicatePokemonToTransfer(
var numToSaveForEvolve = pokemonGroupToTransfer.Count(p => pokemonToEvolveForThisGroup.Any(p2 => p2.Id == p.Id));
canBeRemoved -= numToSaveForEvolve;
var PokemonId = session.Translation.GetPokemonTranslation(pokemonGroupToTransfer.Key);
int candyCount = await GetCandyCount(pokemonGroupToTransfer.Key).ConfigureAwait(false);

Logger.Write($"Saving {numToSaveForEvolve,2:#0} {PokemonId,-12} for evolve. Number of {PokemonId,-12} to be transferred: {canBeRemoved,2:#0}", Logic.Logging.LogLevel.Info);
Logger.Write($"Saving {numToSaveForEvolve,2:#0} {PokemonId,-12} for evolve | Candies: {candyCount,4:#0} | Number to be transferred: {canBeRemoved,2:#0}", Logic.Logging.LogLevel.Info);

if (prioritizeIVoverCp)
{
Expand Down Expand Up @@ -561,6 +563,22 @@ public async Task<IEnumerable<PlayerStats>> GetPlayerStats()
.Where(p => p != null);
}

public async Task<TimeSpan> GetLuckyEggRemainingTime()
{
var appliedItems = await ownerSession.Inventory.GetAppliedItems().ConfigureAwait(false);
var luckyEgg = appliedItems.FirstOrDefault(i => i.ItemId == ItemId.ItemLuckyEgg);
if (luckyEgg != null)
{
// Could be old/cached
var expires = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc).AddMilliseconds(luckyEgg.ExpireMs);
TimeSpan duration = expires - DateTime.UtcNow;
if (duration.TotalSeconds > 0)
return duration;
}

return new TimeSpan(0);
}

public async Task UseLuckyEgg()
{
var inventoryContent = await ownerSession.Inventory.GetItems().ConfigureAwait(false);
Expand Down Expand Up @@ -786,8 +804,16 @@ public async Task<bool> CanEvolvePokemon(PokemonData pokemon, EvolveFilter appli
return false;
}

if (appliedFilter.MinCandiesBeforeEvolve > 0 && familyCandy < appliedFilter.MinCandiesBeforeEvolve)
return false;
int minCandiesBeforeEvolve = appliedFilter.MinCandiesBeforeEvolve;
if (minCandiesBeforeEvolve > 0)
{
if (ownerSession.LogicSettings.EvolvePreserveMinCandiesFromFilter)
{
minCandiesBeforeEvolve += GetCandyToEvolve(settings, appliedFilter);
}
if (familyCandy < minCandiesBeforeEvolve)
return false;
}
}

PokemonId evolveTo = PokemonId.Missingno;
Expand Down Expand Up @@ -862,22 +888,24 @@ public async Task<IEnumerable<PokemonData>> GetPokemonToEvolve(Dictionary<Pokemo
foreach (var g in groupedPokemons)
{
PokemonId pokemonId = g.Key;

var orderedGroup = g.OrderByDescending(p => p.Cp);

//if (!filters.ContainsKey(pokemon.PokemonId)) continue;
var filter = filters[pokemonId];

int candiesLeft = await GetCandyCount(pokemonId).ConfigureAwait(false);
int candiesAvailable = await GetCandyCount(pokemonId).ConfigureAwait(false);
if (ownerSession.LogicSettings.EvolvePreserveMinCandiesFromFilter)
{
// Do not use candies below filter defined MinCandiesBeforeEvolve
candiesAvailable -= filter.MinCandiesBeforeEvolve;
}

PokemonSettings settings = (await GetPokemonSettings().ConfigureAwait(false)).FirstOrDefault(x => x.PokemonId == pokemonId);
int pokemonLeft = orderedGroup.Count();
int candyNeed = GetCandyToEvolve(settings, filter);

if (candyNeed == -1)
continue; // If we were unable to determine which branch to use, then skip this pokemon.

var orderedGroup = g.OrderByDescending(p => p.Cp);
int pokemonLeft = orderedGroup.Count();
// Calculate the number of evolutions possible (taking into account +1 candy for evolve and +1 candy for transfer)
EvolutionCalculations evolutionInfo = CalculatePokemonEvolution(pokemonLeft, candiesLeft, candyNeed, 1);
EvolutionCalculations evolutionInfo = CalculatePokemonEvolution(pokemonLeft, candiesAvailable, candyNeed, 1);

if (evolutionInfo.Evolves > 0)
{
Expand Down
4 changes: 3 additions & 1 deletion PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public float GenRandom(float val)
public bool FastSoftBanBypass => _settings.SoftBanConfig.FastSoftBanBypass;
public int ByPassSpinCount => _settings.SoftBanConfig.ByPassSpinCount;
public bool EvolveAllPokemonWithEnoughCandy => _settings.PokemonConfig.EvolveAllPokemonWithEnoughCandy;
public bool EvolvePreserveMinCandiesFromFilter => _settings.PokemonConfig.EvolvePreserveMinCandiesFromFilter;
public bool EvolveFavoritedOnly => _settings.PokemonConfig.EvolveFavoritedOnly;
public string EvolveOperator => _settings.PokemonConfig.EvolveOperator;
public double EvolveMinIV => _settings.PokemonConfig.EvolveMinIV;
Expand Down Expand Up @@ -164,7 +165,7 @@ public float GenRandom(float val)
public string GpxFile => _settings.GPXConfig.GpxFile;
public bool UseGpxPathing => _settings.GPXConfig.UseGpxPathing;
public bool UseLuckyEggsWhileEvolving => _settings.PokemonConfig.UseLuckyEggsWhileEvolving;
public int UseLuckyEggsMinPokemonAmount => GenRandom(_settings.PokemonConfig.UseLuckyEggsMinPokemonAmount);
public int UseLuckyEggsMinPokemonAmount => _settings.PokemonConfig.UseLuckyEggsMinPokemonAmount;
public bool EvolveAllPokemonAboveIv => _settings.PokemonConfig.EvolveAllPokemonAboveIv;
public float EvolveAboveIvValue => _settings.PokemonConfig.EvolveAboveIvValue;
public bool RenamePokemon => _settings.PokemonConfig.RenamePokemon;
Expand All @@ -186,6 +187,7 @@ public float GenRandom(float val)
public double RecycleInventoryAtUsagePercentage => GenRandom(_settings.RecycleConfig.RecycleInventoryAtUsagePercentage);
public double EvolveKeptPokemonsAtStorageUsagePercentage => GenRandom(_settings.PokemonConfig.EvolveKeptPokemonsAtStorageUsagePercentage);
public int EvolveKeptPokemonIfBagHasOverThisManyPokemon => GenRandom(_settings.PokemonConfig.EvolveKeptPokemonIfBagHasOverThisManyPokemon);
public bool EvolveKeptPokemonsIfLuckyEggCanBeUsed => _settings.PokemonConfig.EvolveKeptPokemonsIfLuckyEggCanBeUsed;
public Dictionary<ItemId, ItemUseFilter> ItemUseFilters => _settings.ItemUseFilters;

public ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter => _settings.ItemRecycleFilter.Select(itemRecycleFilter => new KeyValuePair<ItemId, int>(itemRecycleFilter.Key, itemRecycleFilter.Value)).ToList();
Expand Down
Loading