From 5942733a66ed6a1184debe3a67b2ad8c4d2589e0 Mon Sep 17 00:00:00 2001 From: Sandro Wirth Date: Mon, 1 Aug 2016 17:46:29 +0200 Subject: [PATCH] Add Moves to TransferFilter --- PoGo.NecroBot.Logic/ILogicSettings.cs | 6 +++++- PoGo.NecroBot.Logic/Settings.cs | 7 +++++++ PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs | 8 ++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/PoGo.NecroBot.Logic/ILogicSettings.cs b/PoGo.NecroBot.Logic/ILogicSettings.cs index cc4e70fdf..866f9051c 100644 --- a/PoGo.NecroBot.Logic/ILogicSettings.cs +++ b/PoGo.NecroBot.Logic/ILogicSettings.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using POGOProtos.Enums; using POGOProtos.Inventory.Item; +using POGOProtos.Settings.Master.Item; #endregion @@ -46,16 +47,19 @@ public TransferFilter() { } - public TransferFilter(int keepMinCp, float keepMinIvPercentage, int keepMinDuplicatePokemon) + public TransferFilter(int keepMinCp, float keepMinIvPercentage, int keepMinDuplicatePokemon, + List moves = null) { KeepMinCp = keepMinCp; KeepMinIvPercentage = keepMinIvPercentage; KeepMinDuplicatePokemon = keepMinDuplicatePokemon; + Moves = moves ?? new List(); } public int KeepMinCp { get; set; } public float KeepMinIvPercentage { get; set; } public int KeepMinDuplicatePokemon { get; set; } + public List Moves { get; set; } } public interface ILogicSettings diff --git a/PoGo.NecroBot.Logic/Settings.cs b/PoGo.NecroBot.Logic/Settings.cs index 53dc949bf..916191df6 100644 --- a/PoGo.NecroBot.Logic/Settings.cs +++ b/PoGo.NecroBot.Logic/Settings.cs @@ -13,6 +13,7 @@ using System.ComponentModel; using System.Reflection; using System.Collections; +using System.Linq; #endregion @@ -440,6 +441,12 @@ public static GlobalSettings Load(string path) jsonSettings.DefaultValueHandling = DefaultValueHandling.Populate; settings = JsonConvert.DeserializeObject(input, jsonSettings); + + //This makes sure that existing config files dont get null values which lead to an exception + foreach (var filter in settings.PokemonsTransferFilter.Where(x => x.Value.Moves == null)) + { + filter.Value.Moves = new List(); + } // One day we might be able to better do this so its automatic /* diff --git a/PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs b/PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs index 413be6550..0bbbea6a5 100644 --- a/PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs +++ b/PoGo.NecroBot.Logic/Tasks/TransferDuplicatePokemonTask.cs @@ -7,6 +7,7 @@ using PoGo.NecroBot.Logic.PoGoUtils; using PoGo.NecroBot.Logic.State; using PoGo.NecroBot.Logic.Utils; +using POGOProtos.Enums; #endregion @@ -30,11 +31,14 @@ public static async Task Execute(ISession session, CancellationToken cancellatio foreach (var duplicatePokemon in duplicatePokemons) { cancellationToken.ThrowIfCancellationRequested(); + var pokemonTransferFilter = session.Inventory.GetPokemonTransferFilter(duplicatePokemon.PokemonId); if (duplicatePokemon.Cp >= - session.Inventory.GetPokemonTransferFilter(duplicatePokemon.PokemonId).KeepMinCp || + pokemonTransferFilter.KeepMinCp || PokemonInfo.CalculatePokemonPerfection(duplicatePokemon) > - session.Inventory.GetPokemonTransferFilter(duplicatePokemon.PokemonId).KeepMinIvPercentage) + pokemonTransferFilter.KeepMinIvPercentage || + pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move1) || + pokemonTransferFilter.Moves.Contains(duplicatePokemon.Move2)) { continue; }