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 #378

Closed
wants to merge 5 commits 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
7 changes: 6 additions & 1 deletion PoGo.PokeMobBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ public interface ILogicSettings

//transfer
bool TransferDuplicatePokemon { get; }
bool TransferLowStatPokemon { get; }
bool PrioritizeIvOverCp { get; }
int KeepMinCp { get; }
float KeepMinIvPercentage { get; }
Expand Down Expand Up @@ -155,7 +156,11 @@ public interface ILogicSettings
int TotalAmountOfMaxPotionsToKeep { get; }
int TotalAmountOfRevivesToKeep { get; }
int TotalAmountOfMaxRevivesToKeep { get; }
int TotalAmountOfBerriesToKeep { get; }
int TotalAmountOfRazzToKeep { get; }
//int TotalAmountOfBerriesToKeep { get; }
//int TotalAmountOfBlukToKeep { get; }
//int TotalAmountOfNanabToKeep { get; }
//int TotalAmountOfPinapToKeep { get; }
double RecycleInventoryAtUsagePercentage { get; }

//snipe
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
14 changes: 12 additions & 2 deletions PoGo.PokeMobBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,7 @@ public class GlobalSettings

//transfer
public bool TransferDuplicatePokemon = true;
public bool TransferLowStatPokemon = false;
public bool PrioritizeIvOverCp = true;
public int KeepMinCp = 1250;
public float KeepMinIvPercentage = 95;
Expand Down Expand Up @@ -203,7 +204,11 @@ public class GlobalSettings
public int TotalAmountOfMaxPotionsToKeep = 20;
public int TotalAmountOfRevivesToKeep = 20;
public int TotalAmountOfMaxRevivesToKeep = 30;
public int TotalAmountOfBerriesToKeep = 40;
public int TotalAmountOfRazzToKeep = 40;
//public int TotalAmountOfBlukToKeep = 40;
//public int TotalAmountOfNanabToKeep = 40;
//public int TotalAmountOfPinapToKeep = 40;
//public int TotalAmountOfWeparToKeep = 40;
public double RecycleInventoryAtUsagePercentage = 0.90;

//snipe
Expand Down Expand Up @@ -646,6 +651,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 Down Expand Up @@ -696,7 +702,11 @@ public LogicSettings(GlobalSettings settings)
public int TotalAmountOfGreatballsToKeep => _settings.TotalAmountOfGreatballsToKeep;
public int TotalAmountOfUltraballsToKeep => _settings.TotalAmountOfUltraballsToKeep;
public int TotalAmountOfMasterballsToKeep => _settings.TotalAmountOfMasterballsToKeep;
public int TotalAmountOfBerriesToKeep => _settings.TotalAmountOfBerriesToKeep;
public int TotalAmountOfRazzToKeep => _settings.TotalAmountOfRazzToKeep;
//public int TotalAmountOfBlukToKeep => _settings.TotalAmountOfBlukToKeep;
//public int TotalAmountOfNanabToKeep => _settings.TotalAmountOfNanabToKeep;
//public int TotalAmountOfPinapToKeep => _settings.TotalAmountOfPinapToKeep;
//public int TotalAmountOfWeparToKeep => _settings.TotalAmountOfWeparToKeep;
public int TotalAmountOfPotionsToKeep => _settings.TotalAmountOfPotionsToKeep;
public int TotalAmountOfSuperPotionsToKeep => _settings.TotalAmountOfSuperPotionsToKeep;
public int TotalAmountOfHyperPotionsToKeep => _settings.TotalAmountOfHyperPotionsToKeep;
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 @@ public static async Task Teleport(ISession session, CancellationToken cancellati
{
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
71 changes: 37 additions & 34 deletions PoGo.PokeMobBot.Logic/Tasks/RecycleItemsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace PoGo.PokeMobBot.Logic.Tasks
{
public class RecycleItemsTask
{
private static int diff;

public static async Task Execute(ISession session, CancellationToken cancellationToken)
{
Expand Down Expand Up @@ -109,41 +108,45 @@ private static async Task OptimizedRecyclePotions(ISession session, Cancellation

private static async Task OptimizedRecycleBerries(ISession session, CancellationToken cancellationToken)
{
var razz = await session.Inventory.GetItemAmountByType(ItemId.ItemRazzBerry);
var bluk = await session.Inventory.GetItemAmountByType(ItemId.ItemBlukBerry);
var nanab = await session.Inventory.GetItemAmountByType(ItemId.ItemNanabBerry);
var pinap = await session.Inventory.GetItemAmountByType(ItemId.ItemPinapBerry);
var wepar = await session.Inventory.GetItemAmountByType(ItemId.ItemWeparBerry);

int totalBerryCount = razz + bluk + nanab + pinap + wepar;
if (totalBerryCount > session.LogicSettings.TotalAmountOfBerriesToKeep)
var razzCount = await session.Inventory.GetItemAmountByType(ItemId.ItemRazzBerry);
//var blukCount = await session.Inventory.GetItemAmountByType(ItemId.ItemBlukBerry);
//var nanabCount = await session.Inventory.GetItemAmountByType(ItemId.ItemNanabBerry);
//var pinapCount = await session.Inventory.GetItemAmountByType(ItemId.ItemPinapBerry);
//var weparCount = await session.Inventory.GetItemAmountByType(ItemId.ItemWeparBerry);
int razzToKeep = session.LogicSettings.TotalAmountOfRazzToKeep;
//int blukToKeep = session.LogicSettings.TotalAmountOfBlukToKeep;
//int nanabToKeep = session.LogicSettings.TotalAmountOfNanabToKeep;
//int pinapToKeep = session.LogicSettings.TotalAmountOfPinapToKeep;
//int weparToKeep = session.LogicSettings.TotalAmountOfWeparToKeep;
int razzToRecycle = razzCount - razzToKeep;
//int blukToRecycle = blukCount - blukToKeep;
//int nanabToRecycle = nanabCount - nanabToKeep;
//int pinapToRecycle = pinapCount - pinapToKeep;
//int weparToRecycle = weparCount - weparToKeep;
if (razzCount > razzToKeep)
{
diff = totalBerryCount - session.LogicSettings.TotalAmountOfBerriesToKeep;
if (diff > 0)
{
await RemoveItems(razz, ItemId.ItemRazzBerry, cancellationToken, session);
}

if (diff > 0)
{
await RemoveItems(bluk, ItemId.ItemBlukBerry, cancellationToken, session);
}

if (diff > 0)
{
await RemoveItems(nanab, ItemId.ItemNanabBerry, cancellationToken, session);
}

if (diff > 0)
{
await RemoveItems(pinap, ItemId.ItemPinapBerry, cancellationToken, session);
}

if (diff > 0)
{
await RemoveItems(wepar, ItemId.ItemWeparBerry, cancellationToken, session);
}
await RemoveItems(razzToRecycle, ItemId.ItemRazzBerry, cancellationToken, session);
}

//if (blukCount > blukToKeep)
//{
// await RemoveItems(blukToRecycle, ItemId.ItemBlukBerry, cancellationToken, session);
//}

//if nanabCount > nanabToKeep)
//{
// await RemoveItems(nanabToRecycle, ItemId.ItemNanabBerry, cancellationToken, session);
//}

//if (pinapCount > pinapToKeep)
//{
// await RemoveItems(pinapToRecycle, ItemId.ItemPinapBerry, cancellationToken, session);
//}

//if (weparCount > weparToKeep)
//{
// await RemoveItems(weparToRecycle, ItemId.ItemWeparBerry, cancellationToken, session);
//}
}

private static async Task OptimizedRecycleRevives(ISession session, CancellationToken cancellationToken)
Expand Down
77 changes: 77 additions & 0 deletions PoGo.PokeMobBot.Logic/Tasks/TransferLowStatPokemon.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
#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.Cp >= session.LogicSettings.KeepMinCp || pokemon.Favorite == 1) //dont toss if above minimum CP or if its a favorite
{
continue;
}
if (PokemonInfo.CalculatePokemonPerfection(pokemon) >= session.LogicSettings.KeepMinIvPercentage && session.LogicSettings.PrioritizeIvOverCp) //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