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

Added TransferLowStatPokemon #447

Merged
merged 4 commits into from
Aug 2, 2016
Merged
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
2 changes: 2 additions & 0 deletions PoGo.PokeMobBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,9 @@ public interface ILogicSettings

//transfer
bool TransferDuplicatePokemon { get; }
bool TransferLowStatPokemon { get; }
bool PrioritizeIvOverCp { get; }
bool PrioritizeIvAndCp { get; }
int KeepMinCp { get; }
float KeepMinIvPercentage { get; }
int KeepMinDuplicatePokemon { get; }
Expand Down
1 change: 1 addition & 0 deletions PoGo.PokeMobBot.Logic/PoGo.PokeMobBot.Logic.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@
<Compile Include="Event\UseLuckyEggEvent.cs" />
<Compile Include="State\VersionCheckState.cs" />
<Compile Include="Event\WarnEvent.cs" />
<Compile Include="Tasks\TransferLowStatPokemon.cs" />
<Compile Include="Tasks\TransferPokemonTask.cs" />
<Compile Include="Tasks\UseIncubatorsTask.cs" />
<Compile Include="Tasks\UseNearbyPokestopsTask.cs" />
Expand Down
4 changes: 4 additions & 0 deletions PoGo.PokeMobBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,9 @@ public class GlobalSettings

//transfer
public bool TransferDuplicatePokemon = true;
public bool TransferLowStatPokemon = false;
public bool PrioritizeIvOverCp = true;
public bool PrioritizeIvAndCp = false;
public int KeepMinCp = 1250;
public float KeepMinIvPercentage = 95;
public int KeepMinDuplicatePokemon = 1;
Expand Down Expand Up @@ -646,6 +648,7 @@ public LogicSettings(GlobalSettings settings)
public bool EvolveAllPokemonWithEnoughCandy => _settings.EvolveAllPokemonWithEnoughCandy;
public bool KeepPokemonsThatCanEvolve => _settings.KeepPokemonsThatCanEvolve;
public bool TransferDuplicatePokemon => _settings.TransferDuplicatePokemon;
public bool TransferLowStatPokemon => _settings.TransferLowStatPokemon;
public bool UseEggIncubators => _settings.UseEggIncubators;
public int UseGreatBallAboveIv => _settings.UseGreatBallAboveIv;
public int UseUltraBallAboveIv => _settings.UseUltraBallAboveIv;
Expand All @@ -657,6 +660,7 @@ public LogicSettings(GlobalSettings settings)
public bool UsePokemonToNotCatchFilter => _settings.UsePokemonToNotCatchFilter;
public int KeepMinDuplicatePokemon => _settings.KeepMinDuplicatePokemon;
public bool PrioritizeIvOverCp => _settings.PrioritizeIvOverCp;
public bool PrioritizeIvAndCp => _settings.PrioritizeIvAndCp;
public int MaxTravelDistanceInMeters => _settings.MaxTravelDistanceInMeters;
public string GpxFile => _settings.GpxFile;
public bool UseGpxPathing => _settings.UseGpxPathing;
Expand Down
4 changes: 4 additions & 0 deletions PoGo.PokeMobBot.Logic/State/FarmState.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ public async Task<IState> Execute(ISession session, CancellationToken cancellati
{
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.AutomaticallyLevelUpPokemon)
{
await LevelUpPokemonTask.Execute(session, cancellationToken);
Expand Down
8 changes: 8 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/CatchIncensePokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,14 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
});
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
});
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}
else
session.EventDispatcher.Send(new WarnEvent
{
Expand Down
8 changes: 8 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/CatchLurePokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ public static async Task Execute(ISession session, FortData currentFortData, Can
});
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
});
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}
else
session.EventDispatcher.Send(new WarnEvent
{
Expand Down
8 changes: 8 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/CatchNearbyPokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
});
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
session.EventDispatcher.Send(new WarnEvent
{
Message = session.Translation.GetTranslation(TranslationString.InvFullTransferring)
});
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}
else
session.EventDispatcher.Send(new WarnEvent
{
Expand Down
4 changes: 4 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/Farm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ public void Run(CancellationToken cancellationToken)
{
TransferDuplicatePokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
}
if (_session.LogicSettings.TransferLowStatPokemon)
{
TransferLowStatPokemonTask.Execute(_session, cancellationToken).Wait(cancellationToken);
}

if (_session.LogicSettings.RenamePokemon)
{
Expand Down
4 changes: 4 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/FarmPokestopsGPXTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}

if (session.LogicSettings.RenamePokemon)
{
Expand Down
4 changes: 4 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/FarmPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,10 @@ await session.Navigation.HumanLikeWalking(new GeoCoordinate(pokeStop.Latitude, p
{
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.RenamePokemon)
{
await RenamePokemonTask.Execute(session, cancellationToken);
Expand Down
93 changes: 93 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/TransferLowStatPokemon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
#region using directives

using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using PoGo.PokeMobBot.Logic.Event;
using PoGo.PokeMobBot.Logic.PoGoUtils;
using PoGo.PokeMobBot.Logic.State;
using PoGo.PokeMobBot.Logic.Utils;

#endregion

namespace PoGo.PokeMobBot.Logic.Tasks
{
public class TransferLowStatPokemonTask
{
public static async Task Execute(ISession session, CancellationToken cancellationToken)
{
cancellationToken.ThrowIfCancellationRequested();

// Refresh inventory so that the player stats are fresh
await session.Inventory.RefreshCachedInventory();

var pokemons = await session.Inventory.GetPokemons();

var pokemonList = pokemons.Where(p => !session.LogicSettings.PokemonsNotToTransfer.Contains(p.PokemonId)).ToList(); //filter out the do not transfers

if (session.LogicSettings.KeepPokemonsThatCanEvolve)
{
pokemonList = pokemonList.Where(p => !session.LogicSettings.PokemonsToEvolve.Contains(p.PokemonId)).ToList(); //filter out the evolve list if evolve is true
}

var pokemonSettings = await session.Inventory.GetPokemonSettings();
var pokemonFamilies = await session.Inventory.GetPokemonFamilies();

foreach (var pokemon in pokemonList)
{
cancellationToken.ThrowIfCancellationRequested();

if (pokemon.Favorite == 1)
continue;

if (session.LogicSettings.PrioritizeIvAndCp) //combined mode - pokemon has to match minimum CP and IV requirements to be kept
{
if (pokemon.Cp >= session.LogicSettings.KeepMinCp && (PokemonInfo.CalculatePokemonPerfection(pokemon) >= session.LogicSettings.KeepMinIvPercentage))
{
continue;
}
}
else //normal filtering
{
if (pokemon.Cp >= session.LogicSettings.KeepMinCp) //dont toss if above minimum CP
{
continue;
}
if (session.LogicSettings.PrioritizeIvOverCp)
{
if (PokemonInfo.CalculatePokemonPerfection(pokemon) >= session.LogicSettings.KeepMinIvPercentage) //dont toss if its over min IV
{
continue;
}
}
}

await session.Client.Inventory.TransferPokemon(pokemon.Id);
await session.Inventory.DeletePokemonFromInvById(pokemon.Id);

var bestPokemonOfType = (session.LogicSettings.PrioritizeIvOverCp
? await session.Inventory.GetHighestPokemonOfTypeByIv(pokemon)
: await session.Inventory.GetHighestPokemonOfTypeByCp(pokemon)) ?? pokemon;

var setting = pokemonSettings.Single(q => q.PokemonId == pokemon.PokemonId);
var family = pokemonFamilies.First(q => q.FamilyId == setting.FamilyId);

family.Candy_++;

session.EventDispatcher.Send(new TransferPokemonEvent
{
Id = pokemon.PokemonId,
Perfection = PokemonInfo.CalculatePokemonPerfection(pokemon),
Cp = pokemon.Cp,
BestCp = bestPokemonOfType.Cp,
BestPerfection = PokemonInfo.CalculatePokemonPerfection(bestPokemonOfType),
FamilyCandies = family.Candy_
});
if (session.LogicSettings.Teleport)
await Task.Delay(session.LogicSettings.DelayTransferPokemon);
else
await DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 0);
}
}
}
}
4 changes: 4 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/UseNearbyPokestopsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
await TransferDuplicatePokemonTask.Execute(session, cancellationToken);
}
if (session.LogicSettings.TransferLowStatPokemon)
{
await TransferLowStatPokemonTask.Execute(session, cancellationToken);
}
}
}

Expand Down