Skip to content

Commit

Permalink
Merge pull request NecronomiconCoding#1596 from simplyphp/master
Browse files Browse the repository at this point in the history
Fixed recycling and first run bugs
  • Loading branch information
NecronomiconCoding authored Jul 31, 2016
2 parents c7f09d2 + e20532b commit 57588b1
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 60 deletions.
1 change: 1 addition & 0 deletions PoGo.NecroBot.CLI/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ private static void Main(string[] args)
Logger.Write("Press a Key to continue...",
LogLevel.Warning);
Console.ReadKey();
return;
}
var session = new Session(new ClientSettings(settings), new LogicSettings(settings));
session.Client.ApiFailure = new ApiFailureStrategy(session);
Expand Down
38 changes: 0 additions & 38 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -245,44 +245,6 @@ public async Task<IEnumerable<ItemData>> GetItemsToRecycle(ISession session)
var itemsToRecylce = new List<ItemData>();
var myItems = (await GetItems()).ToList();

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

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

if (session.LogicSettings.ShowPokeballCountsBeforeRecycle)
Logger.Write(session.Translation.GetTranslation(TranslationString.CurrentPokeballInv,
currentAmountOfPokeballs, currentAmountOfGreatballs, currentAmountOfUltraballs,
currentAmountOfMasterballs));

if (!_logicSettings.ItemRecycleFilter.Any(s => _pokeballs.Contains(s.Key)))
{
if (session.LogicSettings.VerboseRecycling)
Logger.Write(session.Translation.GetTranslation(TranslationString.CheckingForBallsToRecycle, amountOfPokeballsToKeep), LogLevel.Recycling);
var pokeballsToRecycle = GetPokeballsToRecycle(session, myItems);
itemsToRecylce.AddRange(pokeballsToRecycle);
}

if (!_logicSettings.ItemRecycleFilter.Any(s => _potions.Contains(s.Key)))
{
if (session.LogicSettings.VerboseRecycling)
Logger.Write(session.Translation.GetTranslation(TranslationString.CheckingForPotionsToRecycle, amountOfPotionsToKeep), LogLevel.Recycling);
var potionsToRecycle = GetPotionsToRecycle(session, myItems);
itemsToRecylce.AddRange(potionsToRecycle);
}

if (!_logicSettings.ItemRecycleFilter.Any(s => _revives.Contains(s.Key)))
{
if (session.LogicSettings.VerboseRecycling)
Logger.Write(session.Translation.GetTranslation(TranslationString.CheckingForRevivesToRecycle, amountOfRevivesToKeep), LogLevel.Recycling);
var revivesToRecycle = GetRevivesToRecycle(session, myItems);
itemsToRecylce.AddRange(revivesToRecycle);
}

var otherItemsToRecylce = myItems
.Where(x => _logicSettings.ItemRecycleFilter.Any(f => f.Key == x.ItemId && x.Count > f.Value))
.Select(
Expand Down
12 changes: 6 additions & 6 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,18 +243,18 @@ public class GlobalSettings
//PokemonId.Kangaskhan,
//PokemonId.MrMime,
//PokemonId.Tauros,
//PokemonId.Gyarados,
PokemonId.Gyarados,
//PokemonId.Lapras,
PokemonId.Ditto,
//PokemonId.Vaporeon,
//PokemonId.Jolteon,
//PokemonId.Flareon,
//PokemonId.Porygon,
//PokemonId.Snorlax,
PokemonId.Snorlax,
PokemonId.Articuno,
PokemonId.Zapdos,
PokemonId.Moltres,
//PokemonId.Dragonite,
PokemonId.Dragonite,
PokemonId.Mewtwo,
PokemonId.Mew
};
Expand Down Expand Up @@ -473,17 +473,17 @@ public static GlobalSettings Load(string path)
settings = new GlobalSettings();
}

if (settings.DefaultAltitude <= 0)
if (settings.DefaultAltitude == 0)
{
settings.DefaultAltitude = Default.DefaultAltitude;
}

if (settings.DefaultLatitude <= 0)
if (settings.DefaultLatitude == 0)
{
settings.DefaultLatitude = Default.DefaultLatitude;
}

if (settings.DefaultLongitude <= 0)
if (settings.DefaultLongitude == 0)
{
settings.DefaultLongitude = Default.DefaultLongitude;
}
Expand Down
47 changes: 31 additions & 16 deletions PoGo.NecroBot.Logic/Tasks/RecycleItemsTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,33 +26,50 @@ public static async Task Execute(ISession session, CancellationToken cancellatio
if (!session.LogicSettings.VerboseRecycling)
Logger.Write(session.Translation.GetTranslation(TranslationString.RecyclingQuietly), LogLevel.Recycling);

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

foreach (var item in items)
if (session.LogicSettings.TotalAmountOfPokeballsToKeep != 0)
{
cancellationToken.ThrowIfCancellationRequested();
var currentAmountOfPokeballs = await session.Inventory.GetItemAmountByType(ItemId.ItemPokeBall);
var currentAmountOfGreatballs = await session.Inventory.GetItemAmountByType(ItemId.ItemGreatBall);
var currentAmountOfUltraballs = await session.Inventory.GetItemAmountByType(ItemId.ItemUltraBall);
var currentAmountOfMasterballs = await session.Inventory.GetItemAmountByType(ItemId.ItemMasterBall);

await session.Client.Inventory.RecycleItem(item.ItemId, item.Count);
if (session.LogicSettings.ShowPokeballCountsBeforeRecycle)
Logger.Write(session.Translation.GetTranslation(TranslationString.CurrentPokeballInv,
currentAmountOfPokeballs, currentAmountOfGreatballs, currentAmountOfUltraballs,
currentAmountOfMasterballs));

if (session.LogicSettings.VerboseRecycling)
session.EventDispatcher.Send(new ItemRecycledEvent {Id = item.ItemId, Count = item.Count});
await OptimizedRecycleBalls(session, cancellationToken);
}

DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
if (session.LogicSettings.TotalAmountOfPotionsToKeep>=0)
{
await OptimizedRecyclePotions(session, cancellationToken);
}

if (session.LogicSettings.TotalAmountOfPokeballsToKeep != 0)
if (session.LogicSettings.TotalAmountOfRevivesToKeep>=0)
{
await OptimizedRecycleBalls(session, cancellationToken);
await OptimizedRecycleRevives(session, cancellationToken);
}

if (session.LogicSettings.TotalAmountOfPotionsToKeep != 0)
currentTotalItems = await session.Inventory.GetTotalItemCount();
if ((session.Profile.PlayerData.MaxItemStorage * session.LogicSettings.RecycleInventoryAtUsagePercentage) > currentTotalItems)
{
await OptimizedRecyclePotions(session, cancellationToken);
await session.Inventory.RefreshCachedInventory();
return;
}

if (session.LogicSettings.TotalAmountOfRevivesToKeep != 0)
var items = await session.Inventory.GetItemsToRecycle(session);

foreach (var item in items)
{
await OptimizedRecycleRevives(session, cancellationToken);
cancellationToken.ThrowIfCancellationRequested();

await session.Client.Inventory.RecycleItem(item.ItemId, item.Count);

if (session.LogicSettings.VerboseRecycling)
session.EventDispatcher.Send(new ItemRecycledEvent { Id = item.ItemId, Count = item.Count });

DelayingUtils.Delay(session.LogicSettings.DelayBetweenPlayerActions, 500);
}

await session.Inventory.RefreshCachedInventory();
Expand All @@ -67,8 +84,6 @@ private static async Task OptimizedRecycleBalls(ISession session, CancellationTo

int pokeBallsToRecycle = 0;
int greatBallsToRecycle = 0;
/*
*/

int totalBallsCount = pokeBallsCount + greatBallsCount + ultraBallsCount + masterBallsCount;
if (totalBallsCount > session.LogicSettings.TotalAmountOfPokeballsToKeep)
Expand Down

0 comments on commit 57588b1

Please sign in to comment.