From 715ad48230fa7eb0e8ee3c0747fcb50637c56cc8 Mon Sep 17 00:00:00 2001 From: Skuld Date: Wed, 16 Nov 2016 13:59:19 -0800 Subject: [PATCH 1/6] Revert Pull #315 - this monkey-patching no longer needed with fixes to the Rocket API. --- PoGo.NecroBot.Logic/Inventory.cs | 47 +++++++++++--------------------- 1 file changed, 16 insertions(+), 31 deletions(-) diff --git a/PoGo.NecroBot.Logic/Inventory.cs b/PoGo.NecroBot.Logic/Inventory.cs index b1eda46da..2d78279de 100644 --- a/PoGo.NecroBot.Logic/Inventory.cs +++ b/PoGo.NecroBot.Logic/Inventory.cs @@ -267,11 +267,7 @@ public int GetStarDust() public async void GetPlayerData() { - for (int i = 0; i < 3; i++) - { - _player = await _client.Player.GetPlayer(); - if (_player != null) break; - } + _player = await _client.Player.GetPlayer(); } public async Task GetHighestPokemonOfTypeByIv(PokemonData pokemon) @@ -440,36 +436,27 @@ public async Task> GetPokemons() inventory.InventoryDelta.InventoryItems.Select(i => i.InventoryItemData?.PokemonData) .Where(p => p != null && p.PokemonId > 0); } - public async Task> GetFaveriotPokemon() + public async Task> GetFavoritePokemons() { var inventory = await GetPokemons(); return inventory.Where(i => i.Favorite == 1); + } + public async Task> GetDeployedPokemons() + { + var inventory = await GetPokemons(); + return + inventory.Where(i => !string.IsNullOrEmpty(i.DeployedFortId)); } public async Task> GetPokemonSettings() { - var ss = new SemaphoreSlim(1); - - await ss.WaitAsync(); - try + if (_templates == null || _pokemonSettings == null) { - if (_templates == null || _pokemonSettings == null) - { - for (int j = 0; j < 3; j++) - { - _templates = await _client.Download.GetItemTemplates(); - _pokemonSettings = _templates.ItemTemplates.Select(i => i.PokemonSettings).Where(p => p != null && p.FamilyId != PokemonFamilyId.FamilyUnset); - if (_templates.ItemTemplates.Count > 10) break; - } - } + _templates = await _client.Download.GetItemTemplates(); + _pokemonSettings = _templates.ItemTemplates.Select(i => i.PokemonSettings).Where(p => p != null && p.FamilyId != PokemonFamilyId.FamilyUnset); } - finally - { - ss.Release(); - } - return _pokemonSettings; } @@ -591,7 +578,9 @@ public TransferFilter GetPokemonTransferFilter(PokemonId pokemon) if (_logicSettings.PokemonsTransferFilter != null && _logicSettings.PokemonsTransferFilter.ContainsKey(pokemon)) { - return _logicSettings.PokemonsTransferFilter[pokemon]; + var filter = _logicSettings.PokemonsTransferFilter[pokemon]; + if(filter.Moves == null ) { filter.Moves = new List>(); } + return filter; } return new TransferFilter(_logicSettings.KeepMinCp, _logicSettings.KeepMinLvl, _logicSettings.UseKeepMinLvl, _logicSettings.KeepMinIvPercentage, _logicSettings.KeepMinOperator, _logicSettings.KeepMinDuplicatePokemon); @@ -605,12 +594,8 @@ public async Task RefreshCachedInventory() await ss.WaitAsync(); try { - for (int i = 0; i < 3; i++) - { - _lastRefresh = now; - _cachedInventory = await _client.Inventory.GetInventory(); - if (_cachedInventory != null && _cachedInventory.InventoryDelta.InventoryItems.Count > 0) break; - } + _lastRefresh = now; + _cachedInventory = await _client.Inventory.GetInventory(); return _cachedInventory; } finally From 63ad8cbb5e673d10c90511bb9a24ca14ffa01c37 Mon Sep 17 00:00:00 2001 From: Skuld Date: Wed, 16 Nov 2016 14:07:37 -0800 Subject: [PATCH 2/6] Fix bug - Terms of Service needs to be checked first before other API calls are made. --- PoGo.NecroBot.Logic/State/CheckTosState.cs | 2 +- PoGo.NecroBot.Logic/State/InfoState.cs | 2 +- PoGo.NecroBot.Logic/State/LoadSaveState.cs | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/PoGo.NecroBot.Logic/State/CheckTosState.cs b/PoGo.NecroBot.Logic/State/CheckTosState.cs index a8d5564ea..66a5b09c1 100644 --- a/PoGo.NecroBot.Logic/State/CheckTosState.cs +++ b/PoGo.NecroBot.Logic/State/CheckTosState.cs @@ -104,7 +104,7 @@ await session.Client.Misc.MarkTutorialComplete(new RepeatedField( await DelayingUtils.DelayAsync(3000, 2000); } } - return new FarmState(); + return new InfoState(); } public async Task CatchFirstPokemon(ISession session) diff --git a/PoGo.NecroBot.Logic/State/InfoState.cs b/PoGo.NecroBot.Logic/State/InfoState.cs index 16af645a3..ad6d31eda 100644 --- a/PoGo.NecroBot.Logic/State/InfoState.cs +++ b/PoGo.NecroBot.Logic/State/InfoState.cs @@ -15,7 +15,7 @@ public async Task Execute(ISession session, CancellationToken cancellati cancellationToken.ThrowIfCancellationRequested(); await DisplayPokemonStatsTask.Execute(session); - return new CheckTosState(); + return new FarmState(); } } } diff --git a/PoGo.NecroBot.Logic/State/LoadSaveState.cs b/PoGo.NecroBot.Logic/State/LoadSaveState.cs index 55af34126..10220e5eb 100644 --- a/PoGo.NecroBot.Logic/State/LoadSaveState.cs +++ b/PoGo.NecroBot.Logic/State/LoadSaveState.cs @@ -87,7 +87,7 @@ public async Task Execute(ISession session, CancellationToken cancellati } await Task.Delay(3000, cancellationToken); - return new InfoState(); + return new CheckTosState(); } private static Tuple LoadPositionFromDisk(ISession session) From 0fd6060469fcf6fc85dc016673dbe236dc618c78 Mon Sep 17 00:00:00 2001 From: Skuld Date: Wed, 16 Nov 2016 15:21:14 -0800 Subject: [PATCH 3/6] When starting up account for first time, prompt user for required values. --- .../Model/Settings/GlobalSettings.cs | 18 +- PoGo.NecroBot.Logic/State/CheckTosState.cs | 257 +++++++++--------- 2 files changed, 139 insertions(+), 136 deletions(-) diff --git a/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs b/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs index f72bed43c..a9f98b404 100644 --- a/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs +++ b/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs @@ -677,11 +677,11 @@ public void Save(string fullPath, bool validate = false) Console.ReadKey(); } - private static bool PromptForBoolean(ITranslation translator, string initialPrompt, string errorPrompt = null) + public static bool PromptForBoolean(ITranslation translator, string initialPrompt, string errorPrompt = null) { - Logger.Write(initialPrompt, LogLevel.Info); while (true) { + Logger.Write(initialPrompt, LogLevel.Info); var strInput = Console.ReadLine().ToLower(); switch (strInput) @@ -700,11 +700,11 @@ private static bool PromptForBoolean(ITranslation translator, string initialProm } } - private static double PromptForDouble(ITranslation translator, string initialPrompt, string errorPrompt = null) + public static double PromptForDouble(ITranslation translator, string initialPrompt, string errorPrompt = null) { - Logger.Write(initialPrompt, LogLevel.Info); while (true) { + Logger.Write(initialPrompt, LogLevel.Info); var strInput = Console.ReadLine(); double doubleVal; @@ -722,11 +722,11 @@ private static double PromptForDouble(ITranslation translator, string initialPro } } - private static int PromptForInteger(ITranslation translator, string initialPrompt, string errorPrompt = null) + public static int PromptForInteger(ITranslation translator, string initialPrompt, string errorPrompt = null) { - Logger.Write(initialPrompt, LogLevel.Info); while (true) { + Logger.Write(initialPrompt, LogLevel.Info); var strInput = Console.ReadLine(); int intVal; @@ -744,12 +744,11 @@ private static int PromptForInteger(ITranslation translator, string initialPromp } } - private static string PromptForString(ITranslation translator, string initialPrompt, string[] validStrings = null, string errorPrompt = null, bool caseSensitive = true) + public static string PromptForString(ITranslation translator, string initialPrompt, string[] validStrings = null, string errorPrompt = null, bool caseSensitive = true) { - Logger.Write(initialPrompt, LogLevel.Info); - while (true) { + Logger.Write(initialPrompt, LogLevel.Info); // For now this just reads from the console, but in the future, we may change this to read from the GUI. string strInput = Console.ReadLine(); @@ -774,7 +773,6 @@ private static string PromptForString(ITranslation translator, string initialPro } Logger.Write(errorPrompt, LogLevel.Error); } - } } } diff --git a/PoGo.NecroBot.Logic/State/CheckTosState.cs b/PoGo.NecroBot.Logic/State/CheckTosState.cs index 66a5b09c1..e969f96b5 100644 --- a/PoGo.NecroBot.Logic/State/CheckTosState.cs +++ b/PoGo.NecroBot.Logic/State/CheckTosState.cs @@ -10,6 +10,7 @@ using POGOProtos.Networking.Responses; using PoGo.NecroBot.Logic.Event; using PoGo.NecroBot.Logic.Utils; +using PoGo.NecroBot.Logic.Model.Settings; #endregion @@ -21,89 +22,86 @@ public async Task Execute(ISession session, CancellationToken cancellati { cancellationToken.ThrowIfCancellationRequested(); - if (session.LogicSettings.AutoCompleteTutorial) + var tutState = session.Profile.PlayerData.TutorialState; + if (!tutState.Contains(TutorialState.LegalScreen)) { - var tutState = session.Profile.PlayerData.TutorialState; - if (!tutState.Contains(TutorialState.LegalScreen)) - { - await - session.Client.Misc.MarkTutorialComplete(new RepeatedField() - { - TutorialState.LegalScreen - }); - session.EventDispatcher.Send(new NoticeEvent() + await + session.Client.Misc.MarkTutorialComplete(new RepeatedField() { - Message = "Just read the Niantic ToS, looks legit, accepting!" + TutorialState.LegalScreen }); - await DelayingUtils.DelayAsync(9000, 2000); - } - if (!tutState.Contains(TutorialState.AvatarSelection)) + session.EventDispatcher.Send(new NoticeEvent() { - var gen = Gender.Male; - switch (session.LogicSettings.DesiredGender) - { - case "Male": - gen = Gender.Male; - break; - case "Female": - gen = Gender.Female; - break; - default: - session.EventDispatcher.Send(new NoticeEvent() - { - Message = "You didn't set a valid gender, setting to default: MALE" - }); - //I know it is useless, but I prefer keep it - gen = Gender.Male; - break; - } - var avatarRes = await session.Client.Player.SetAvatar(new PlayerAvatar() - { - Backpack = 0, - Eyes = 0, - Gender = gen, - Hair = 0, - Hat = 0, - Pants = 0, - Shirt = 0, - Shoes = 0, - Skin = 0 - }); - if (avatarRes.Status == SetAvatarResponse.Types.Status.AvatarAlreadySet || - avatarRes.Status == SetAvatarResponse.Types.Status.Success) - { - await session.Client.Misc.MarkTutorialComplete(new RepeatedField() - { - TutorialState.AvatarSelection - }); - session.EventDispatcher.Send(new NoticeEvent() - { - Message = $"Selected your avatar, now you are {gen}!" - }); - } - } - if (!tutState.Contains(TutorialState.PokemonCapture)) + Message = "Just read the Niantic ToS, looks legit, accepting!" + }); + await DelayingUtils.DelayAsync(9000, 2000); + } + if (!tutState.Contains(TutorialState.AvatarSelection)) + { + string genderString = GlobalSettings.PromptForString(session.Translation, "Enter desired gender for your avatar (\"Male\" or \"Female\")", new string[] { "Male", "Female" }, "You didn't set a valid gender.", false); + + Gender gen; + switch (genderString) { - await CatchFirstPokemon(session); + case "Male": + case "male": + gen = Gender.Male; + break; + case "Female": + case "female": + gen = Gender.Female; + break; + default: + // We should never get here, since the prompt should only allow valid options. + gen = Gender.Male; + break; } - if (!tutState.Contains(TutorialState.NameSelection)) + var avatarRes = await session.Client.Player.SetAvatar(new PlayerAvatar() { - await SelectNicnname(session); - } - if (!tutState.Contains(TutorialState.FirstTimeExperienceComplete)) + Backpack = 0, + Eyes = 0, + Gender = gen, + Hair = 0, + Hat = 0, + Pants = 0, + Shirt = 0, + Shoes = 0, + Skin = 0 + }); + if (avatarRes.Status == SetAvatarResponse.Types.Status.AvatarAlreadySet || + avatarRes.Status == SetAvatarResponse.Types.Status.Success) { - await - session.Client.Misc.MarkTutorialComplete(new RepeatedField() - { - TutorialState.FirstTimeExperienceComplete - }); + await session.Client.Misc.MarkTutorialComplete(new RepeatedField() + { + TutorialState.AvatarSelection + }); session.EventDispatcher.Send(new NoticeEvent() { - Message = "First time experience complete, looks like i just spinned an virtual pokestop :P" + Message = $"Selected your avatar, now you are {gen}!" }); - await DelayingUtils.DelayAsync(3000, 2000); } } + if (!tutState.Contains(TutorialState.PokemonCapture)) + { + await CatchFirstPokemon(session); + } + if (!tutState.Contains(TutorialState.NameSelection)) + { + await SelectNickname(session); + } + if (!tutState.Contains(TutorialState.FirstTimeExperienceComplete)) + { + await + session.Client.Misc.MarkTutorialComplete(new RepeatedField() + { + TutorialState.FirstTimeExperienceComplete + }); + session.EventDispatcher.Send(new NoticeEvent() + { + Message = "First time experience complete, looks like i just spinned an virtual pokestop :P" + }); + await DelayingUtils.DelayAsync(3000, 2000); + } return new InfoState(); } @@ -115,24 +113,24 @@ public async Task CatchFirstPokemon(ISession session) PokemonId.Charmander, PokemonId.Squirtle }; + string pokemonString = GlobalSettings.PromptForString(session.Translation, "Enter pokemon you want to catch first (\"Bulbasaur\", \"Charmander\", or \"Squirtle\")", new string[] { "Bulbasaur", "Charmander", "Squirtle" }, "You didn't enter a valid pokemon.", false); var firstpokenum = 0; - switch (session.LogicSettings.DesiredStarter) + switch (pokemonString) { case "Bulbasaur": + case "bulbasaur": firstpokenum = 0; break; case "Charmander": + case "charmander": firstpokenum = 1; break; case "Squirtle": + case "squirtle": firstpokenum = 2; break; default: - session.EventDispatcher.Send(new NoticeEvent() - { - Message = "You didn't set a valid starter, setting to default: Bulbasaur" - }); - //I know it is useless, but I prefer keep it + // We should never get here. firstpokenum = 0; break; } @@ -149,80 +147,87 @@ public async Task CatchFirstPokemon(ISession session) return true; } - public async Task SelectNicnname(ISession session) + public async Task SelectNickname(ISession session) { - if (string.IsNullOrEmpty(session.LogicSettings.DesiredNickname)) + while (true) { - session.EventDispatcher.Send(new NoticeEvent() - { - Message = "You didn't pick the desired nickname!" - }); - return false; - } + string nickname = GlobalSettings.PromptForString(session.Translation, "Enter desired nickname for your avatar (max length 15 characters)", null, "You entered an invalid nickname."); - if (session.LogicSettings.DesiredNickname.Length > 15) - { - session.EventDispatcher.Send(new NoticeEvent() - { - Message = "You selected too long Desired name, max length: 15!" - }); - return false; - } - - var res = await session.Client.Misc.ClaimCodename(session.LogicSettings.DesiredNickname); - if (res.Status == ClaimCodenameResponse.Types.Status.Success) - { - session.EventDispatcher.Send(new NoticeEvent() + if (nickname.Length > 15 || nickname.Length == 0) { - Message = $"Your name is now: {res.Codename}" - }); - await session.Client.Misc.MarkTutorialComplete(new RepeatedField() - { - TutorialState.NameSelection - }); - } - else if (res.Status == ClaimCodenameResponse.Types.Status.CodenameChangeNotAllowed || res.Status == ClaimCodenameResponse.Types.Status.CurrentOwner) - { - await session.Client.Misc.MarkTutorialComplete(new RepeatedField() - { - TutorialState.NameSelection - }); - } - else - { - var errorText = "Niantic error"; + session.EventDispatcher.Send(new ErrorEvent() + { + Message = "Your desired nickname is too long (max length 15 characters)!" + }); + continue; + } + + var res = await session.Client.Misc.ClaimCodename(nickname); + + bool markTutorialComplete = false; + string errorText = null; + string warningText = null; + string infoText = null; switch (res.Status) { case ClaimCodenameResponse.Types.Status.Unset: errorText = "Unset, somehow"; break; case ClaimCodenameResponse.Types.Status.Success: - errorText = "No errors, nickname changed"; + infoText = $"Your name is now: {res.Codename}"; + markTutorialComplete = true; break; case ClaimCodenameResponse.Types.Status.CodenameNotAvailable: - errorText = "That nickname isn't available, pick another one and restart the bot!"; + errorText = $"That nickname ({nickname}) isn't available, pick another one!"; break; case ClaimCodenameResponse.Types.Status.CodenameNotValid: - errorText = "That nickname isn't valid, pick another one!"; + errorText = $"That nickname ({nickname}) isn't valid, pick another one!"; break; case ClaimCodenameResponse.Types.Status.CurrentOwner: - errorText = "You already own that nickname!"; + warningText = $"You already own that nickname!"; + markTutorialComplete = true; break; case ClaimCodenameResponse.Types.Status.CodenameChangeNotAllowed: - errorText = "You can't change your nickname anymore!"; + warningText = "You can't change your nickname anymore!"; + markTutorialComplete = true; + break; + default: + errorText = "Unknown Niantic error while changing nickname."; break; } + + if (!string.IsNullOrEmpty(infoText)) + { + session.EventDispatcher.Send(new NoticeEvent() + { + Message = infoText + }); + } + else if (!string.IsNullOrEmpty(warningText)) + { + session.EventDispatcher.Send(new WarnEvent() + { + Message = warningText + }); + } + else if (!string.IsNullOrEmpty(errorText)) + { + session.EventDispatcher.Send(new ErrorEvent() + { + Message = errorText + }); + } - session.EventDispatcher.Send(new NoticeEvent() + if (markTutorialComplete) { - Message = $"Name selection failed! Error: {errorText}" - }); + await session.Client.Misc.MarkTutorialComplete(new RepeatedField() + { + TutorialState.NameSelection + }); - // Pause here so the user can restart the bot. - Console.ReadKey(); + return res.Status == ClaimCodenameResponse.Types.Status.Success; + } } - await DelayingUtils.DelayAsync(3000, 2000); - return res.Status == ClaimCodenameResponse.Types.Status.Success; } } } \ No newline at end of file From 0b71192daad006a7900bba0af6dd94af71cdb30e Mon Sep 17 00:00:00 2001 From: Skuld Date: Wed, 16 Nov 2016 15:21:42 -0800 Subject: [PATCH 4/6] Bug fix - Correctly mimic first request sent by client, which is now GetPlayer with common requests. This also fixes first time login for new accounts. --- FeroxRev | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/FeroxRev b/FeroxRev index 4a267b464..103b867ca 160000 --- a/FeroxRev +++ b/FeroxRev @@ -1 +1 @@ -Subproject commit 4a267b464c003169e4b46997c62f479d21987aa9 +Subproject commit 103b867cadc01d52777a357c7b140469bff5d0ee From fcee64863ab68f1225d3fdb9a09fb95eef1f8727 Mon Sep 17 00:00:00 2001 From: Skuld Date: Wed, 16 Nov 2016 16:34:08 -0800 Subject: [PATCH 5/6] Remove first time tutorial auto complete settings from the config file. These don't need to be stored in the config. Now the user will be prompted for these values as needed. Also clean up config migration code to not throw error if backup file already exists. --- PoGo.NecroBot.Logic/Common/Translations.cs | 8 ++-- .../Configuration/ILogicSettings.cs | 4 -- .../Model/Settings/GlobalSettings.cs | 42 ++++++------------- .../Model/Settings/LogicSettings.cs | 4 -- .../Model/Settings/PlayerConfig.cs | 33 --------------- .../Model/Settings/UpdateConfig.cs | 2 +- PoGo.NecroBot.Logic/State/CheckTosState.cs | 7 ++-- 7 files changed, 21 insertions(+), 79 deletions(-) diff --git a/PoGo.NecroBot.Logic/Common/Translations.cs b/PoGo.NecroBot.Logic/Common/Translations.cs index 55c71859e..2825a17d1 100644 --- a/PoGo.NecroBot.Logic/Common/Translations.cs +++ b/PoGo.NecroBot.Logic/Common/Translations.cs @@ -530,13 +530,13 @@ public class Translation : ITranslation new KeyValuePair(TranslationString.FirstStartSetupProxyUsernameConfirm, "Accepted Proxy Username: {0}"), new KeyValuePair(TranslationString.FirstStartSetupProxyPasswordPrompt, "Please enter your Proxy Password (Right click to paste)"), new KeyValuePair(TranslationString.FirstStartSetupProxyPasswordConfirm, "Accepted Proxy Password: {0}"), - new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutPrompt, "Would you like to enable the Auto-Complete Tutorial Feature? {0}/{1}"), + //new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutPrompt, "Would you like to enable the Auto-Complete Tutorial Feature? {0}/{1}"), new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutNicknamePrompt, "Please enter your desired Nickname"), - new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutNicknameConfirm, "Accepted Nickname: {0}"), + //new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutNicknameConfirm, "Accepted Nickname: {0}"), new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutGenderPrompt, "Please enter your desired Gender (ENGLISH WORD: Male or Female)"), - new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutGenderConfirm, "Accepted Gender: {0}"), + //new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutGenderConfirm, "Accepted Gender: {0}"), new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutStarterPrompt, "Please enter your desired Starter (ENGLISH NAME: Bulbasaur, Charmander, Squirtle)"), - new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutStarterConfirm, "Accepted Starter: {0}"), + //new KeyValuePair(TranslationString.FirstStartSetupAutoCompleteTutStarterConfirm, "Accepted Starter: {0}"), new KeyValuePair(TranslationString.FirstStartSetupWebSocketPrompt, "Would you like to enable the WebSocket Feature? {0}/{1}"), new KeyValuePair(TranslationString.FirstStartSetupWebSocketPortPrompt, "Please enter your WebSocket Port (default 14251)"), new KeyValuePair(TranslationString.FirstStartSetupWebSocketPortConfirm, "Accepted Port: {0}"), diff --git a/PoGo.NecroBot.Logic/Interfaces/Configuration/ILogicSettings.cs b/PoGo.NecroBot.Logic/Interfaces/Configuration/ILogicSettings.cs index b3b94736b..e04094a0c 100644 --- a/PoGo.NecroBot.Logic/Interfaces/Configuration/ILogicSettings.cs +++ b/PoGo.NecroBot.Logic/Interfaces/Configuration/ILogicSettings.cs @@ -140,10 +140,6 @@ public interface ILogicSettings bool UsePokeStopLimit { get; } bool UseCatchLimit { get; } bool UseNearActionRandom { get; } - bool AutoCompleteTutorial { get; } - string DesiredNickname { get; } - string DesiredGender { get; } - string DesiredStarter { get; } ICollection> ItemRecycleFilter { get; } ICollection PokemonsToEvolve { get; } diff --git a/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs b/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs index a9f98b404..9dbfb8a2e 100644 --- a/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs +++ b/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs @@ -19,6 +19,7 @@ using PokemonGo.RocketAPI.Enums; using POGOProtos.Enums; using PoGo.NecroBot.Logic.Service.Elevation; +using PokemonGo.RocketAPI.Extensions; #endregion @@ -377,7 +378,8 @@ private static void MigrateSettings(JObject settings, string configFile, string } // Backup old config file. - string backupPath = configFile.Replace(".json", $"-{schemaVersion}.backup.json"); + long ts = DateTime.UtcNow.ToUnixTime(); // Add timestamp to avoid file conflicts + string backupPath = configFile.Replace(".json", $"-{schemaVersion}-{ts}.backup.json"); Logger.Write($"Backing up config.json to: {backupPath}", LogLevel.Info); File.Copy(configFile, backupPath); @@ -388,11 +390,12 @@ private static void MigrateSettings(JObject settings, string configFile, string Logger.Write($"Migrating configuration from schema version {version} to {version + 1}", LogLevel.Info); switch(version) { - case 0: - settings["UpdateConfig"]["SchemaVersion"] = UpdateConfig.CURRENT_SCHEMA_VERSION; - break; case 1: - // TODO Add schema migrations from version 1 to 2 here. + // Delete the auto complete tutorial settings. + ((JObject)settings["PlayerConfig"]).Remove("AutoCompleteTutorial"); + ((JObject)settings["PlayerConfig"]).Remove("DesiredNickname"); + ((JObject)settings["PlayerConfig"]).Remove("DesiredGender"); + ((JObject)settings["PlayerConfig"]).Remove("DesiredStarter"); break; case 2: @@ -402,6 +405,9 @@ private static void MigrateSettings(JObject settings, string configFile, string // Add more here. } } + + // After migration we need to update the schema version to the latest version. + settings["UpdateConfig"]["SchemaVersion"] = UpdateConfig.CURRENT_SCHEMA_VERSION; } public void CheckProxy(ITranslation translator) @@ -428,7 +434,6 @@ public static Session SetupSettings(Session session, GlobalSettings settings, IE SetupWalkingConfig(newSession.Translation, settings); SetupTelegramConfig(newSession.Translation, settings); SetupProxyConfig(newSession.Translation, settings); - SetupAutoCompleteTutConfig(newSession.Translation, settings); SetupWebSocketConfig(newSession.Translation, settings); SaveFiles(settings, configPath); @@ -494,30 +499,7 @@ private static void SetupWalkingConfig(ITranslation translator, GlobalSettings s settings.LocationConfig.WalkingSpeedVariant = PromptForDouble(translator, translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedVariantPrompt)); Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupWalkingSpeedVariantConfirm, settings.LocationConfig.WalkingSpeedVariant.ToString())); } - - private static void SetupAutoCompleteTutConfig(ITranslation translator, GlobalSettings settings) - { - if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutPrompt, "Y", "N"))) - return; - - settings.PlayerConfig.AutoCompleteTutorial = true; - - string strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknamePrompt)); - settings.PlayerConfig.DesiredNickname = strInput; - Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknameConfirm, - strInput)); - - strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderPrompt)); - settings.PlayerConfig.DesiredGender = strInput; - Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderConfirm, - strInput)); - - strInput = PromptForString(translator, translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterPrompt)); - settings.PlayerConfig.DesiredStarter = strInput; - Logger.Write(translator.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterConfirm, - strInput)); - } - + private static void SetupWebSocketConfig(ITranslation translator, GlobalSettings settings) { if (false == PromptForBoolean(translator, translator.GetTranslation(TranslationString.FirstStartSetupWebSocketPrompt, "Y", "N"))) diff --git a/PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs b/PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs index e5cd884c2..19d5edc8f 100644 --- a/PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs +++ b/PoGo.NecroBot.Logic/Model/Settings/LogicSettings.cs @@ -98,10 +98,6 @@ public LogicSettings(GlobalSettings settings) public int RecycleActionDelay => _settings.PlayerConfig.RecycleActionDelay; public int RenamePokemonActionDelay => _settings.PlayerConfig.RenamePokemonActionDelay; public bool UseNearActionRandom => _settings.PlayerConfig.UseNearActionRandom; - public bool AutoCompleteTutorial => _settings.PlayerConfig.AutoCompleteTutorial; - public string DesiredNickname => _settings.PlayerConfig.DesiredNickname; - public string DesiredGender => _settings.PlayerConfig.DesiredGender; - public string DesiredStarter => _settings.PlayerConfig.DesiredStarter; public bool UsePokemonToNotCatchFilter => _settings.PokemonConfig.UsePokemonToNotCatchFilter; public bool UsePokemonSniperFilterOnly => _settings.PokemonConfig.UsePokemonSniperFilterOnly; public int KeepMinDuplicatePokemon => _settings.PokemonConfig.KeepMinDuplicatePokemon; diff --git a/PoGo.NecroBot.Logic/Model/Settings/PlayerConfig.cs b/PoGo.NecroBot.Logic/Model/Settings/PlayerConfig.cs index 5249a4cd7..ef340d054 100644 --- a/PoGo.NecroBot.Logic/Model/Settings/PlayerConfig.cs +++ b/PoGo.NecroBot.Logic/Model/Settings/PlayerConfig.cs @@ -7,19 +7,6 @@ namespace PoGo.NecroBot.Logic.Model.Settings [JsonObject(Title = "Player Config", Description = "Set your player settings.", ItemRequired = Required.DisallowNull)] public class PlayerConfig { - internal enum Gender - { - Male, - Female - } - - internal enum Starter - { - Bulbasaur, - Charmander, - Squirtle - } - [DefaultValue(10000)] [Range(0, 999999)] [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 1)] @@ -48,25 +35,5 @@ internal enum Starter [DefaultValue(true)] [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 6)] public bool UseNearActionRandom = true; - - [DefaultValue(false)] - [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 7)] - public bool AutoCompleteTutorial; - - [DefaultValue("Nickname")] - [MinLength(0)] - [MaxLength(15)] - [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 8)] - public string DesiredNickname = "Nickname"; - - [DefaultValue("Male")] - [EnumDataType(typeof(Gender))] - [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 9)] - public string DesiredGender = "Male"; - - [DefaultValue("Squirtle")] - [EnumDataType(typeof(Starter))] - [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 10)] - public string DesiredStarter = "Squirtle"; } } \ No newline at end of file diff --git a/PoGo.NecroBot.Logic/Model/Settings/UpdateConfig.cs b/PoGo.NecroBot.Logic/Model/Settings/UpdateConfig.cs index 01008ca24..788a78ef7 100644 --- a/PoGo.NecroBot.Logic/Model/Settings/UpdateConfig.cs +++ b/PoGo.NecroBot.Logic/Model/Settings/UpdateConfig.cs @@ -6,7 +6,7 @@ namespace PoGo.NecroBot.Logic.Model.Settings [JsonObject(Title = "Update Config", Description = "Set your update settings.", ItemRequired = Required.DisallowNull)] public class UpdateConfig { - public const int CURRENT_SCHEMA_VERSION = 1; + public const int CURRENT_SCHEMA_VERSION = 2; [DefaultValue(CURRENT_SCHEMA_VERSION)] [JsonProperty(Required = Required.DisallowNull, DefaultValueHandling = DefaultValueHandling.Populate, Order = 1)] diff --git a/PoGo.NecroBot.Logic/State/CheckTosState.cs b/PoGo.NecroBot.Logic/State/CheckTosState.cs index e969f96b5..2f0b236f1 100644 --- a/PoGo.NecroBot.Logic/State/CheckTosState.cs +++ b/PoGo.NecroBot.Logic/State/CheckTosState.cs @@ -11,6 +11,7 @@ using PoGo.NecroBot.Logic.Event; using PoGo.NecroBot.Logic.Utils; using PoGo.NecroBot.Logic.Model.Settings; +using PoGo.NecroBot.Logic.Common; #endregion @@ -38,7 +39,7 @@ public async Task Execute(ISession session, CancellationToken cancellati } if (!tutState.Contains(TutorialState.AvatarSelection)) { - string genderString = GlobalSettings.PromptForString(session.Translation, "Enter desired gender for your avatar (\"Male\" or \"Female\")", new string[] { "Male", "Female" }, "You didn't set a valid gender.", false); + string genderString = GlobalSettings.PromptForString(session.Translation, session.Translation.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutGenderPrompt), new string[] { "Male", "Female" }, "You didn't set a valid gender.", false); Gender gen; switch (genderString) @@ -113,7 +114,7 @@ public async Task CatchFirstPokemon(ISession session) PokemonId.Charmander, PokemonId.Squirtle }; - string pokemonString = GlobalSettings.PromptForString(session.Translation, "Enter pokemon you want to catch first (\"Bulbasaur\", \"Charmander\", or \"Squirtle\")", new string[] { "Bulbasaur", "Charmander", "Squirtle" }, "You didn't enter a valid pokemon.", false); + string pokemonString = GlobalSettings.PromptForString(session.Translation, session.Translation.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutStarterPrompt), new string[] { "Bulbasaur", "Charmander", "Squirtle" }, "You didn't enter a valid pokemon.", false); var firstpokenum = 0; switch (pokemonString) { @@ -151,7 +152,7 @@ public async Task SelectNickname(ISession session) { while (true) { - string nickname = GlobalSettings.PromptForString(session.Translation, "Enter desired nickname for your avatar (max length 15 characters)", null, "You entered an invalid nickname."); + string nickname = GlobalSettings.PromptForString(session.Translation, session.Translation.GetTranslation(TranslationString.FirstStartSetupAutoCompleteTutNicknamePrompt), null, "You entered an invalid nickname."); if (nickname.Length > 15 || nickname.Length == 0) { From 1b730e471c173c8d8b2f30d37cbcb82bc511b7bb Mon Sep 17 00:00:00 2001 From: Skuld Date: Wed, 16 Nov 2016 16:55:50 -0800 Subject: [PATCH 6/6] Make sure that we update the version schema and write out new migrated configuration. --- PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs b/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs index 9dbfb8a2e..611e6ceeb 100644 --- a/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs +++ b/PoGo.NecroBot.Logic/Model/Settings/GlobalSettings.cs @@ -305,6 +305,9 @@ public static GlobalSettings Load(string path, bool boolSkipSave = false, bool v LogLevel.Warning); Console.ReadKey(); } + + // Now we know it's valid so update input with the migrated version. + input = jsonObj.ToString(); } settings = JsonConvert.DeserializeObject(input, jsonSettings);