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

Throw away low level pokeballs, potions, revives and keep the better ones. #1362

Merged
merged 6 commits into from
Jul 29, 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
3 changes: 3 additions & 0 deletions PoGo.NecroBot.Logic/ILogicSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ public interface ILogicSettings
bool UseSnipeLocationServer { get; }
bool UseTransferIVForSnipe { get; }
int MinDelayBetweenSnipes { get; }
int TotalAmountOfPokebalsToKeep { get; }
int TotalAmountOfPotionsToKeep { get; }
int TotalAmountOfRevivesToKeep { get; }

ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter { get; }

Expand Down
143 changes: 129 additions & 14 deletions PoGo.NecroBot.Logic/Inventory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ public class Inventory
private GetInventoryResponse _cachedInventory;
private DateTime _lastRefresh;

private List<ItemId> Pokeballs = new List<ItemId> { ItemId.ItemPokeBall, ItemId.ItemGreatBall, ItemId.ItemUltraBall, ItemId.ItemMasterBall };
private List<ItemId> Potions = new List<ItemId> { ItemId.ItemPotion, ItemId.ItemSuperPotion, ItemId.ItemHyperPotion, ItemId.ItemMaxPotion };
private List<ItemId> Revives = new List<ItemId> { ItemId.ItemRevive, ItemId.ItemMaxRevive };

public Inventory(Client client, ILogicSettings logicSettings)
{
_client = client;
Expand Down Expand Up @@ -90,7 +94,7 @@ public async Task<IEnumerable<PokemonData>> GetDuplicatePokemonToTransfer(

if (settings.CandyToEvolve > 0)
{
var amountPossible = familyCandy.Candy_ /settings.CandyToEvolve;
var amountPossible = familyCandy.Candy_ / settings.CandyToEvolve;
if (amountPossible > amountToSkip)
amountToSkip = amountPossible;
}
Expand Down Expand Up @@ -204,19 +208,130 @@ public async Task<IEnumerable<ItemData>> GetItems()

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


if (!_logicSettings.ItemRecycleFilter.Any(s => Pokeballs.Contains(s.Key)))
{
var pokeballsToRecycle = GetPokeballsToRecycle(settings, myItems);
itemsToRecylce.AddRange(pokeballsToRecycle);
}
else
{
Logging.Logger.Write("Using ItemRecycleFilter for pokeballs", Logging.LogLevel.Info, ConsoleColor.Yellow);
}

if (!_logicSettings.ItemRecycleFilter.Any(s => Potions.Contains(s.Key)))
{
var potionsToRecycle = GetPotionsToRecycle(settings, myItems);
itemsToRecylce.AddRange(potionsToRecycle);
}
else
{
Logging.Logger.Write("Using ItemRecycleFilter for potions", Logging.LogLevel.Info, ConsoleColor.Yellow);
}

if (!_logicSettings.ItemRecycleFilter.Any(s => Revives.Contains(s.Key)))
{
var revivesToRecycle = GetRevivesToRecycle(settings, myItems);
itemsToRecylce.AddRange(revivesToRecycle);
}
else
{
Logging.Logger.Write("Using ItemRecycleFilter for revives", Logging.LogLevel.Info, ConsoleColor.Yellow);
}

return myItems
var otherItemsToRecylce = myItems
.Where(x => _logicSettings.ItemRecycleFilter.Any(f => f.Key == x.ItemId && x.Count > f.Value))
.Select(
x =>
new ItemData
{
ItemId = x.ItemId,
Count =
x.Count - _logicSettings.ItemRecycleFilter.Single(f => f.Key == x.ItemId).Value,
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)
{
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);
return new List<ItemData>();
}

var allPokeballs = myItems.Where(s => Pokeballs.Contains(s.ItemId)).ToList();
allPokeballs.Sort((ball1, ball2) => ((int)ball1.ItemId).CompareTo((int)ball2.ItemId));

return TakeAmountOfItems(allPokeballs, amountOfPokeballsToKeep).ToList();
}

private List<ItemData> GetPotionsToRecycle(ISettings settings, IReadOnlyList<ItemData> myItems)
{
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);
return new List<ItemData>();
}

var allPotions = myItems.Where(s => Potions.Contains(s.ItemId)).ToList();
allPotions.Sort((i1, i2) => ((int)i1.ItemId).CompareTo((int)i2.ItemId));

return TakeAmountOfItems(allPotions, amountOfPotionsToKeep).ToList();
}

private List<ItemData> GetRevivesToRecycle(ISettings settings, IReadOnlyList<ItemData> myItems)
{
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);
return new List<ItemData>();
}

var allRevives = myItems.Where(s => Revives.Contains(s.ItemId)).ToList();
allRevives.Sort((i1, i2) => ((int)i1.ItemId).CompareTo((int)i2.ItemId));

return TakeAmountOfItems(allRevives, amountOfRevivesToKeep).ToList();
}

private IEnumerable<ItemData> TakeAmountOfItems(IReadOnlyList<ItemData> items, int ammountToLeave)
{
var itemsAvailable = 0;
foreach (var item in items)
{
itemsAvailable += item.Count;
}

int itemsToRemove = itemsAvailable - ammountToLeave;

foreach (var item in items)
{
if (itemsToRemove > 0 && item.Count > 0)
{
if (item.Count < itemsToRemove)
{
// Recylce all of this type
itemsToRemove -= item.Count;
yield return item;
}
else
{
// Recycle remaining amount
var count = itemsToRemove;
itemsToRemove = 0;
yield return new ItemData { ItemId = item.ItemId, Count = count };
}
}
}
}

public async Task<IEnumerable<PlayerStats>> GetPlayerStats()
Expand All @@ -232,15 +347,15 @@ public async Task<List<Candy>> GetPokemonFamilies()
var inventory = await GetCachedInventory();

var families = from item in inventory.InventoryDelta.InventoryItems
where item.InventoryItemData?.Candy != null
where item.InventoryItemData?.Candy.FamilyId != PokemonFamilyId.FamilyUnset
group item by item.InventoryItemData?.Candy.FamilyId
where item.InventoryItemData?.Candy != null
where item.InventoryItemData?.Candy.FamilyId != PokemonFamilyId.FamilyUnset
group item by item.InventoryItemData?.Candy.FamilyId
into family
select new Candy
{
FamilyId = family.First().InventoryItemData.Candy.FamilyId,
Candy_ = family.First().InventoryItemData.Candy.Candy_
};
select new Candy
{
FamilyId = family.First().InventoryItemData.Candy.FamilyId,
Candy_ = family.First().InventoryItemData.Candy.Candy_
};


return families.ToList();
Expand Down Expand Up @@ -302,7 +417,7 @@ public async Task<IEnumerable<PokemonData>> GetPokemonToEvolve(IEnumerable<Pokem

var pokemonCandyNeededAlready =
pokemonToEvolve.Count(
p => pokemonSettings.Single(x => x.PokemonId == p.PokemonId).FamilyId == settings.FamilyId)*
p => pokemonSettings.Single(x => x.PokemonId == p.PokemonId).FamilyId == settings.FamilyId) *
settings.CandyToEvolve;

if (familyCandy.Candy_ - pokemonCandyNeededAlready > settings.CandyToEvolve)
Expand Down
19 changes: 8 additions & 11 deletions PoGo.NecroBot.Logic/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -120,20 +120,14 @@ public class GlobalSettings
public bool UseSnipeLocationServer = false;
public bool UseTransferIVForSnipe = false;
public int MinDelayBetweenSnipes = 20000;
public int TotalAmountOfPokebalsToKeep = 150;
public int TotalAmountOfPotionsToKeep = 100;
public int TotalAmountOfRevivesToKeep = 50;


public List<KeyValuePair<ItemId, int>> ItemRecycleFilter = new List<KeyValuePair<ItemId, int>>
{
new KeyValuePair<ItemId, int>(ItemId.ItemUnknown, 0),
new KeyValuePair<ItemId, int>(ItemId.ItemPokeBall, 25),
new KeyValuePair<ItemId, int>(ItemId.ItemGreatBall, 50),
new KeyValuePair<ItemId, int>(ItemId.ItemUltraBall, 100),
new KeyValuePair<ItemId, int>(ItemId.ItemMasterBall, 100),
new KeyValuePair<ItemId, int>(ItemId.ItemPotion, 0),
new KeyValuePair<ItemId, int>(ItemId.ItemSuperPotion, 10),
new KeyValuePair<ItemId, int>(ItemId.ItemHyperPotion, 40),
new KeyValuePair<ItemId, int>(ItemId.ItemMaxPotion, 75),
new KeyValuePair<ItemId, int>(ItemId.ItemRevive, 25),
new KeyValuePair<ItemId, int>(ItemId.ItemMaxRevive, 50),
new KeyValuePair<ItemId, int>(ItemId.ItemLuckyEgg, 200),
new KeyValuePair<ItemId, int>(ItemId.ItemIncenseOrdinary, 100),
new KeyValuePair<ItemId, int>(ItemId.ItemIncenseSpicy, 100),
Expand Down Expand Up @@ -525,8 +519,11 @@ public LogicSettings(GlobalSettings settings)
public SnipeSettings PokemonToSnipe => _settings.PokemonToSnipe;
public string SnipeLocationServer => _settings.SnipeLocationServer;
public int SnipeLocationServerPort => _settings.SnipeLocationServerPort;
public bool UseSnipeLocationServer=> _settings.UseSnipeLocationServer;
public bool UseSnipeLocationServer => _settings.UseSnipeLocationServer;
public bool UseTransferIVForSnipe => _settings.UseTransferIVForSnipe;
public int MinDelayBetweenSnipes => _settings.MinDelayBetweenSnipes;
public int TotalAmountOfPokebalsToKeep => _settings.TotalAmountOfPokebalsToKeep;
public int TotalAmountOfPotionsToKeep => _settings.TotalAmountOfPotionsToKeep;
public int TotalAmountOfRevivesToKeep => _settings.TotalAmountOfRevivesToKeep;
}
}