Skip to content

Commit

Permalink
EVOLVE CHECKING METHOD FIXED!
Browse files Browse the repository at this point in the history
now using lucky eggs works with KeepPokemonThatCanEvolve!
  • Loading branch information
ChemiHatake committed Aug 8, 2016
1 parent 4c53a8e commit 1fc1353
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 21 deletions.
10 changes: 5 additions & 5 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,7 @@ public async Task<IEnumerable<PokemonData>> GetPokemonToEvolve(IEnumerable<Pokem
{
myPokemon =
myPokemon.Where(
p => (_logicSettings.EvolveAllPokemonWithEnoughCandy && pokemonIds.Contains(p.PokemonId)) ||
p => (pokemonIds.Contains(p.PokemonId)) ||
(_logicSettings.EvolveAllPokemonAboveIv &&
(PokemonInfo.CalculatePokemonPerfection(p) >= _logicSettings.EvolveAboveIvValue)));
}
Expand All @@ -427,13 +427,13 @@ public async Task<IEnumerable<PokemonData>> GetPokemonToEvolve(IEnumerable<Pokem
//Don't evolve if we can't evolve it
if (settings.EvolutionIds.Count == 0)
continue;

//DO NOT CHANGE! TESTED AND WORKS
var pokemonCandyNeededAlready =
pokemonToEvolve.Count(
p => pokemonSettings.Single(x => x.PokemonId == p.PokemonId).FamilyId == settings.FamilyId)*
(pokemonToEvolve.Count(
p => pokemonSettings.Single(x => x.PokemonId == p.PokemonId).FamilyId == settings.FamilyId) + 1) *
settings.CandyToEvolve;

if (familyCandy.Candy_ - pokemonCandyNeededAlready > settings.CandyToEvolve)
if (familyCandy.Candy_ >= pokemonCandyNeededAlready)
{
pokemonToEvolve.Add(pokemon);
}
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/State/FarmState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class FarmState : IState
public async Task<IState> Execute(ISession session, CancellationToken cancellationToken)
{

if (session.LogicSettings.EvolveAllPokemonAboveIv || session.LogicSettings.EvolveAllPokemonWithEnoughCandy)
if (session.LogicSettings.EvolveAllPokemonAboveIv || session.LogicSettings.EvolveAllPokemonWithEnoughCandy || session.LogicSettings.UseLuckyEggsWhileEvolving)
{
await EvolvePokemonTask.Execute(session, cancellationToken);
}
Expand Down
55 changes: 44 additions & 11 deletions PoGo.NecroBot.Logic/Tasks/EvolvePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using PoGo.NecroBot.Logic.Common;
using System.Collections.Generic;
using POGOProtos.Data;
using PoGo.NecroBot.Logic.Logging;
using POGOProtos.Settings.Master;

#endregion

Expand All @@ -31,32 +33,63 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
Evolves = pokemonToEvolve.Count
} );

var myPokemonFamilies = await session.Inventory.GetPokemonFamilies();
var pokemonFamilies = myPokemonFamilies.ToArray();
var familyCandy = pokemonFamilies.Where(p => p.FamilyId == POGOProtos.Enums.PokemonFamilyId.FamilyPidgey || p.FamilyId == POGOProtos.Enums.PokemonFamilyId.FamilyWeedle);
Logger.Write(String.Join(",", pokemonToEvolve.Select(p => p.PokemonId)), LogLevel.Update);
Logger.Write(String.Join(",", familyCandy), LogLevel.Update);
if (pokemonToEvolve.Any())
{
if (session.LogicSettings.KeepPokemonsThatCanEvolve)
if (session.LogicSettings.KeepPokemonsThatCanEvolve || session.LogicSettings.UseLuckyEggsWhileEvolving)
{
var luckyEggMin = session.LogicSettings.UseLuckyEggsMinPokemonAmount;
var eggNeededToEvolve = luckyEggMin - pokemonToEvolve.Count();
var maxStorage = session.Profile.PlayerData.MaxPokemonStorage;
var totalPokemon = await session.Inventory.GetPokemons();
var totalEggs = await session.Inventory.GetEggs();

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

var deltaCount = needPokemonToStartEvolve - totalPokemon.Count();

if (deltaCount > 0)
if (session.LogicSettings.UseLuckyEggsWhileEvolving)
{
session.EventDispatcher.Send(new NoticeEvent()
if(luckyEggMin > maxStorage)
{
Message = session.Translation.GetTranslation(TranslationString.WaitingForMorePokemonToEvolve,
pokemonToEvolve.Count, deltaCount, totalPokemon.Count(), needPokemonToStartEvolve, session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage)
});
return;
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.UseLuckyEggsMinPokemonAmountTooHigh,
luckyEggMin, maxStorage)
});
return;
}
}
if(eggNeededToEvolve <= deltaCount)
{
if (eggNeededToEvolve > 0)
{
session.EventDispatcher.Send(new UpdateEvent()
{
Message = session.Translation.GetTranslation(TranslationString.CatchMorePokemonToUseLuckyEgg,
eggNeededToEvolve)
});
}
}
else
{
if (deltaCount > 0)
{
session.EventDispatcher.Send(new UpdateEvent()
{
Message = session.Translation.GetTranslation(TranslationString.WaitingForMorePokemonToEvolve,
pokemonToEvolve.Count, deltaCount, totalPokemon.Count(), needPokemonToStartEvolve, session.LogicSettings.EvolveKeptPokemonsAtStorageUsagePercentage)
});
}
}
return;
}

if (await shouldUseLuckyEgg(session, pokemonToEvolve))
{
await UseLuckyEgg(session);
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/Tasks/Farm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public Farm(ISession session)

public void Run(CancellationToken cancellationToken)
{
if (_session.LogicSettings.EvolveAllPokemonAboveIv || _session.LogicSettings.EvolveAllPokemonWithEnoughCandy)
if (_session.LogicSettings.EvolveAllPokemonAboveIv || _session.LogicSettings.EvolveAllPokemonWithEnoughCandy || _session.LogicSettings.UseLuckyEggsWhileEvolving)
{
EvolvePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
}
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/FarmPokestopsGPXTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,8 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
await RecycleItemsTask.Execute(session, cancellationToken);

if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
session.LogicSettings.EvolveAllPokemonAboveIv)
session.LogicSettings.EvolveAllPokemonAboveIv ||
session.LogicSettings.UseLuckyEggsWhileEvolving)
{
await EvolvePokemonTask.Execute(session, cancellationToken);
}
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/FarmPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,8 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
await RecycleItemsTask.Execute(session, cancellationToken);

if (session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
session.LogicSettings.EvolveAllPokemonAboveIv)
session.LogicSettings.EvolveAllPokemonAboveIv ||
session.LogicSettings.UseLuckyEggsWhileEvolving)
{
await EvolvePokemonTask.Execute(session, cancellationToken);
}
Expand Down
3 changes: 2 additions & 1 deletion PoGo.NecroBot.Logic/Tasks/SnipePokemonTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -373,7 +373,8 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
else if (encounter.Status == EncounterResponse.Types.Status.PokemonInventoryFull)
{
if (session.LogicSettings.EvolveAllPokemonAboveIv ||
session.LogicSettings.EvolveAllPokemonWithEnoughCandy)
session.LogicSettings.EvolveAllPokemonWithEnoughCandy ||
session.LogicSettings.UseLuckyEggsWhileEvolving)
{
await EvolvePokemonTask.Execute(session, cancellationToken);
}
Expand Down

0 comments on commit 1fc1353

Please sign in to comment.