Skip to content

Commit

Permalink
Merge pull request #1450 from bornsupercharged/master
Browse files Browse the repository at this point in the history
Added pokeball output for counts and an alert if they have none
  • Loading branch information
NecronomiconCoding authored Jul 30, 2016
2 parents 7f3b649 + ed66947 commit 201ecfd
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 18 deletions.
28 changes: 22 additions & 6 deletions PoGo.NecroBot.Logic/Common/Translations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ public enum TranslationString
UpdateFinished,
LookingForIncensePokemon,
PokemonSkipped,
ZeroPokeballInv,
CurrentPokeballInv,
CheckingForBallsToRecycle,
CheckingForPotionsToRecycle,
CheckingForRevivesToRecycle,
PokeballsToKeepIncorrect,
PotionsToKeepIncorrect,
RevivesToKeepIncorrect,
InvFullTransferring,
InvFullTransferManually,
InvFullPokestopLooting,
Expand Down Expand Up @@ -196,15 +204,23 @@ public class Translation : ITranslation
new KeyValuePair<TranslationString, string>(Common.TranslationString.FinishedUnpackingFiles, "Finished unpacking files..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.FinishedTransferringConfig, "Finished transferring your config to the new version..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.UpdateFinished, "Update finished, you can close this window now."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.LookingForIncensePokemon, "Looking for incense pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.LookingForPokemon, "Looking for pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.LookingForLurePokemon, "Looking for lure pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.LookingForIncensePokemon, "Looking for incense Pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.LookingForPokemon, "Looking for Pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.LookingForLurePokemon, "Looking for lure Pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.PokemonSkipped, "Skipped {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.InvFullTransferring, "PokemonInventory is Full.Transferring pokemons..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.InvFullTransferManually, "PokemonInventory is Full.Please Transfer pokemon manually or set TransferDuplicatePokemon to true in settings..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.ZeroPokeballInv, "You have no pokeballs in your inventory, no more Pokemon can be caught!"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.CurrentPokeballInv, "[Current Inventory] Pokeballs: {0} | Greatballs: {1} | Ultraballs: {2} | Masterballs: {3}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.CheckingForBallsToRecycle, "Checking for balls to recycle, keeping {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.CheckingForPotionsToRecycle, "Checking for potions to recycle, keeping {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.CheckingForRevivesToRecycle, "Checking for revives to recycle, keeping {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.PokeballsToKeepIncorrect, "TotalAmountOfPokebalsToKeep is configured incorrectly. The number is smaller than 1."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.PotionsToKeepIncorrect, "TotalAmountOfPotionsToKeep is configured incorrectly. The number is smaller than 1."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.RevivesToKeepIncorrect, "TotalAmountOfRevivesToKeep is configured incorrectly. The number is smaller than 1."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.InvFullTransferring, "Pokemon Inventory is full, transferring Pokemon..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.InvFullTransferManually, "Pokemon Inventory is full! Please transfer Pokemon manually or set TransferDuplicatePokemon to true in settings..."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.InvFullPokestopLooting, "Inventory is full, no items looted!"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.EncounterProblem, "Encounter problem: {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.EncounterProblemLurePokemon, "Encounter problem: Lure pokemon {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.EncounterProblemLurePokemon, "Encounter problem: Lure Pokemon {0}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.DesiredDestTooFar, "Your desired destination of {0}, {1} is too far from your current position of {2}, {3}"),
new KeyValuePair<TranslationString, string>(Common.TranslationString.PokemonRename, "Pokemon {0} ({1}) renamed from {2} to {3}."),
new KeyValuePair<TranslationString, string>(Common.TranslationString.PokemonIgnoreFilter, "[Pokemon ignore filter] - Ignoring {0} as defined in settings"),
Expand Down
42 changes: 31 additions & 11 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using PoGo.NecroBot.Logic.Event;
using PoGo.NecroBot.Logic.State;
using PoGo.NecroBot.Logic.Utils;
using PoGo.NecroBot.Logic.PoGoUtils;
using PokemonGo.RocketAPI;
using POGOProtos.Data;
Expand Down Expand Up @@ -235,27 +238,41 @@ public async Task<IEnumerable<ItemData>> GetItems()
.Where(p => p != null);
}

public async Task<IEnumerable<ItemData>> GetItemsToRecycle(ISettings settings)
public async Task<IEnumerable<ItemData>> GetItemsToRecycle(ISession session)
{
var settings = session.Settings;
var itemsToRecylce = new List<ItemData>();
var myItems = (await GetItems()).ToList();

var amountOfPokeballsToKeep = _logicSettings.TotalAmountOfPokebalsToKeep;
var amountOfPotionsToKeep = _logicSettings.TotalAmountOfPotionsToKeep;
var amountOfRevivesToKeep = _logicSettings.TotalAmountOfRevivesToKeep;

int currentAmountOfPokeballs = await GetItemAmountByType(ItemId.ItemPokeBall);
int currentAmountOfGreatballs = await GetItemAmountByType(ItemId.ItemGreatBall);
int currentAmountOfUltraballs = await GetItemAmountByType(ItemId.ItemUltraBall);
int currentAmountOfMasterballs = await GetItemAmountByType(ItemId.ItemMasterBall);

Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.CurrentPokeballInv, currentAmountOfPokeballs, currentAmountOfGreatballs, currentAmountOfUltraballs, currentAmountOfMasterballs));

if (!_logicSettings.ItemRecycleFilter.Any(s => Pokeballs.Contains(s.Key)))
{
var pokeballsToRecycle = GetPokeballsToRecycle(settings, myItems);
Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.CheckingForBallsToRecycle, amountOfPokeballsToKeep));
var pokeballsToRecycle = GetPokeballsToRecycle(session, myItems);
itemsToRecylce.AddRange(pokeballsToRecycle);
}

if (!_logicSettings.ItemRecycleFilter.Any(s => Potions.Contains(s.Key)))
{
var potionsToRecycle = GetPotionsToRecycle(settings, myItems);
Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.CheckingForPotionsToRecycle, amountOfPotionsToKeep));
var potionsToRecycle = GetPotionsToRecycle(session, myItems);
itemsToRecylce.AddRange(potionsToRecycle);
}

if (!_logicSettings.ItemRecycleFilter.Any(s => Revives.Contains(s.Key)))
{
var revivesToRecycle = GetRevivesToRecycle(settings, myItems);
Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.CheckingForRevivesToRecycle, amountOfRevivesToKeep));
var revivesToRecycle = GetRevivesToRecycle(session, myItems);
itemsToRecylce.AddRange(revivesToRecycle);
}

Expand All @@ -269,18 +286,19 @@ public async Task<IEnumerable<ItemData>> GetItemsToRecycle(ISettings settings)
Count = x.Count - _logicSettings.ItemRecycleFilter.Single(f => f.Key == x.ItemId).Value,
Unseen = x.Unseen
});

itemsToRecylce.AddRange(otherItemsToRecylce);

return itemsToRecylce;
}

private List<ItemData> GetPokeballsToRecycle(ISettings settings, IReadOnlyList<ItemData> myItems)
private List<ItemData> GetPokeballsToRecycle(ISession session, IReadOnlyList<ItemData> myItems)
{
var settings = session.Settings;
var amountOfPokeballsToKeep = _logicSettings.TotalAmountOfPokebalsToKeep;
if (amountOfPokeballsToKeep < 1)
{
Logging.Logger.Write("TotalAmountOfPokebalsToKeep is wrong configured. The number is smaller than 1.", Logging.LogLevel.Error, ConsoleColor.Red);
Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.PokeballsToKeepIncorrect), Logging.LogLevel.Error, ConsoleColor.Red);
return new List<ItemData>();
}

Expand All @@ -290,12 +308,13 @@ private List<ItemData> GetPokeballsToRecycle(ISettings settings, IReadOnlyList<I
return TakeAmountOfItems(allPokeballs, amountOfPokeballsToKeep).ToList();
}

private List<ItemData> GetPotionsToRecycle(ISettings settings, IReadOnlyList<ItemData> myItems)
private List<ItemData> GetPotionsToRecycle(ISession session, IReadOnlyList<ItemData> myItems)
{
var settings = session.Settings;
var amountOfPotionsToKeep = _logicSettings.TotalAmountOfPotionsToKeep;
if (amountOfPotionsToKeep < 1)
{
Logging.Logger.Write("TotalAmountOfPotionsToKeep is wrong configured. The number is smaller than 1.", Logging.LogLevel.Error, ConsoleColor.Red);
Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.PotionsToKeepIncorrect), Logging.LogLevel.Error, ConsoleColor.Red);
return new List<ItemData>();
}

Expand All @@ -305,12 +324,13 @@ private List<ItemData> GetPotionsToRecycle(ISettings settings, IReadOnlyList<Ite
return TakeAmountOfItems(allPotions, amountOfPotionsToKeep).ToList();
}

private List<ItemData> GetRevivesToRecycle(ISettings settings, IReadOnlyList<ItemData> myItems)
private List<ItemData> GetRevivesToRecycle(ISession session, IReadOnlyList<ItemData> myItems)
{
var settings = session.Settings;
var amountOfRevivesToKeep = _logicSettings.TotalAmountOfRevivesToKeep;
if (amountOfRevivesToKeep < 1)
{
Logging.Logger.Write("TotalAmountOfRevivesToKeep is wrong configured. The number is smaller than 1.", Logging.LogLevel.Error, ConsoleColor.Red);
Logging.Logger.Write(session.Translation.GetTranslation(Common.TranslationString.RevivesToKeepIncorrect), Logging.LogLevel.Error, ConsoleColor.Red);
return new List<ItemData>();
}

Expand Down
3 changes: 3 additions & 0 deletions PoGo.NecroBot.Logic/Tasks/CatchNearbyPokemonsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
var masterBallsCount = await session.Inventory.GetItemAmountByType(POGOProtos.Inventory.Item.ItemId.ItemMasterBall);

if (pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount == 0)
{
Logger.Write(session.Translation.GetTranslation(Common.TranslationString.ZeroPokeballInv));
return;
}

if (session.LogicSettings.UsePokemonToNotCatchFilter &&
session.LogicSettings.PokemonsNotToCatch.Contains(pokemon.PokemonId))
Expand Down
2 changes: 1 addition & 1 deletion PoGo.NecroBot.Logic/Tasks/RecycleItemsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
{
cancellationToken.ThrowIfCancellationRequested();

var items = await session.Inventory.GetItemsToRecycle(session.Settings);
var items = await session.Inventory.GetItemsToRecycle(session);

foreach (var item in items)
{
Expand Down

0 comments on commit 201ecfd

Please sign in to comment.