Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.59 KB | None | 0 0
  1. #region
  2.  
  3. using System;
  4. using System.Collections.Generic;
  5. using System.IO;
  6. using PokemonGo.RocketAPI.Enums;
  7. using PokemonGo.RocketAPI.GeneratedCode;
  8. using System.Text.RegularExpressions;
  9.  
  10. #endregion
  11.  
  12. namespace PokemonGo.RocketAPI.Console
  13. {
  14. public class Settings : ISettings
  15. {
  16. private ICollection<PokemonId> _pokemonsNotToTransfer;
  17. private ICollection<PokemonId> _pokemonsToEvolve;
  18. private ICollection<PokemonId> _pokemonsNotToCatch;
  19. private ICollection<KeyValuePair<ItemId, int>> _itemRecycleFilter;
  20.  
  21. public AuthType AuthType => (AuthType)Enum.Parse(typeof(AuthType), UserSettings.Default.AuthType, true);
  22. public string PtcUsername => UserSettings.Default.PtcUsername;
  23. public string PtcPassword => UserSettings.Default.PtcPassword;
  24. public double DefaultLatitude => UserSettings.Default.DefaultLatitude;
  25. public double DefaultLongitude => UserSettings.Default.DefaultLongitude;
  26. public double DefaultAltitude => UserSettings.Default.DefaultAltitude;
  27. public float KeepMinIVPercentage => UserSettings.Default.KeepMinIVPercentage;
  28. public int KeepMinCP => UserSettings.Default.KeepMinCP;
  29. public double WalkingSpeedInKilometerPerHour => UserSettings.Default.WalkingSpeedInKilometerPerHour;
  30. public bool EvolveAllPokemonWithEnoughCandy => UserSettings.Default.EvolveAllPokemonWithEnoughCandy;
  31. public bool TransferDuplicatePokemon => UserSettings.Default.TransferDuplicatePokemon;
  32. public int DelayBetweenPokemonCatch => UserSettings.Default.DelayBetweenPokemonCatch;
  33. public bool UsePokemonToNotCatchFilter => UserSettings.Default.UsePokemonToNotCatchFilter;
  34. public int KeepMinDuplicatePokemon => UserSettings.Default.KeepMinDuplicatePokemon;
  35. public bool PrioritizeIVOverCP => UserSettings.Default.PrioritizeIVOverCP;
  36. public int MaxTravelDistanceInMeters => UserSettings.Default.MaxTravelDistanceInMeters;
  37. public string GPXFile => UserSettings.Default.GPXFile;
  38. public bool UseGPXPathing => UserSettings.Default.UseGPXPathing;
  39. public bool useLuckyEggsWhileEvolving => UserSettings.Default.useLuckyEggsWhileEvolving;
  40. public bool EvolveAllPokemonAboveIV => UserSettings.Default.EvolveAllPokemonAboveIV;
  41. public float EvolveAboveIVValue => UserSettings.Default.EvolveAboveIVValue;
  42.  
  43. //Type and amount to keep
  44. public ICollection<KeyValuePair<ItemId, int>> ItemRecycleFilter
  45. {
  46.  
  47. get
  48. {
  49. //Type of pokemons to evolve
  50. var defaultItems = new List<KeyValuePair<ItemId, int>> {
  51. new KeyValuePair<ItemId, int>(ItemId.ItemUnknown, 0),
  52. new KeyValuePair<ItemId, int>(ItemId.ItemPokeBall, 25),
  53. new KeyValuePair<ItemId, int>(ItemId.ItemGreatBall, 50),
  54. new KeyValuePair<ItemId, int>(ItemId.ItemUltraBall, 75),
  55. new KeyValuePair<ItemId, int>(ItemId.ItemMasterBall, 100),
  56. new KeyValuePair<ItemId, int>(ItemId.ItemPotion, 0),
  57. new KeyValuePair<ItemId, int>(ItemId.ItemSuperPotion, 25),
  58. new KeyValuePair<ItemId, int>(ItemId.ItemHyperPotion, 50),
  59. new KeyValuePair<ItemId, int>(ItemId.ItemMaxPotion, 75),
  60. new KeyValuePair<ItemId, int>(ItemId.ItemRevive, 25),
  61. new KeyValuePair<ItemId, int>(ItemId.ItemMaxRevive, 50),
  62. new KeyValuePair<ItemId, int>(ItemId.ItemLuckyEgg, 200),
  63. new KeyValuePair<ItemId, int>(ItemId.ItemIncenseOrdinary, 100),
  64. new KeyValuePair<ItemId, int>(ItemId.ItemIncenseSpicy, 100),
  65. new KeyValuePair<ItemId, int>(ItemId.ItemIncenseCool, 100),
  66. new KeyValuePair<ItemId, int>(ItemId.ItemIncenseFloral, 100),
  67. new KeyValuePair<ItemId, int>(ItemId.ItemTroyDisk, 100),
  68. new KeyValuePair<ItemId, int>(ItemId.ItemXAttack, 100),
  69. new KeyValuePair<ItemId, int>(ItemId.ItemXDefense, 100),
  70. new KeyValuePair<ItemId, int>(ItemId.ItemXMiracle, 100),
  71. new KeyValuePair<ItemId, int>(ItemId.ItemRazzBerry, 50),
  72. new KeyValuePair<ItemId, int>(ItemId.ItemBlukBerry, 10),
  73. new KeyValuePair<ItemId, int>(ItemId.ItemNanabBerry, 10),
  74. new KeyValuePair<ItemId, int>(ItemId.ItemWeparBerry, 30),
  75. new KeyValuePair<ItemId, int>(ItemId.ItemPinapBerry, 30),
  76. new KeyValuePair<ItemId, int>(ItemId.ItemSpecialCamera, 100),
  77. new KeyValuePair<ItemId, int>(ItemId.ItemIncubatorBasicUnlimited, 100),
  78. new KeyValuePair<ItemId, int>(ItemId.ItemIncubatorBasic, 100),
  79. new KeyValuePair<ItemId, int>(ItemId.ItemPokemonStorageUpgrade, 100),
  80. new KeyValuePair<ItemId, int>(ItemId.ItemItemStorageUpgrade, 100)
  81. };
  82. _itemRecycleFilter = _itemRecycleFilter ?? LoadItemList("Configs\\ConfigItemList.ini", defaultItems);
  83. return _itemRecycleFilter;
  84. }
  85.  
  86.  
  87. }
  88.  
  89. public ICollection<KeyValuePair<ItemId, int>> LoadItemList(string filename, List<KeyValuePair<ItemId, int>> defaultItems)
  90. {
  91. ICollection<KeyValuePair<ItemId, int>> result = new List<KeyValuePair<ItemId, int>>();
  92.  
  93. DirectoryInfo di = Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\Configs");
  94.  
  95. if (File.Exists(Directory.GetCurrentDirectory() + "\\" + filename))
  96. {
  97. Logger.Write($"Loading File: {filename}");
  98.  
  99. var content = string.Empty;
  100. using (StreamReader reader = new StreamReader(filename))
  101. {
  102. content = reader.ReadToEnd();
  103. reader.Close();
  104. }
  105.  
  106. content = Regex.Replace(content, @"\\/\*(.|\n)*?\*\/", ""); //todo: supposed to remove comment blocks
  107.  
  108.  
  109. StringReader tr = new StringReader(content);
  110.  
  111. var itemInfo = tr.ReadLine();
  112. while (itemInfo != null)
  113. {
  114. string[] itemInfoArray = itemInfo.Split(' ');
  115. string itemName = itemInfoArray.Length > 1 ? itemInfoArray[0] : "";
  116. int itemAmount = 0;
  117. if (Int32.TryParse(itemInfoArray.Length > 1 ? itemInfoArray[1] : "100", out itemAmount)) itemAmount = 100;
  118.  
  119. ItemId item;
  120. if (Enum.TryParse<ItemId>(itemName, out item))
  121. {
  122. result.Add(new KeyValuePair<ItemId, int>(item, itemAmount));
  123. }
  124. itemInfo = tr.ReadLine();
  125. }
  126. }
  127. else
  128. {
  129. Logger.Write($"File: {filename} not found, creating new...", LogLevel.Warning);
  130. using (var w = File.AppendText(Directory.GetCurrentDirectory() + "\\" + filename))
  131. {
  132. defaultItems.ForEach(itemInfo => w.WriteLine($"{itemInfo.Key} {itemInfo.Value}"));
  133. defaultItems.ForEach(itemInfo => result.Add(itemInfo));
  134. w.Close();
  135. }
  136. }
  137. return result;
  138. }
  139.  
  140.  
  141. public ICollection<PokemonId> PokemonsToEvolve
  142. {
  143. get
  144. {
  145. //Type of pokemons to evolve
  146. List<PokemonId> defaultPokemon = new List<PokemonId> {
  147. PokemonId.Zubat, PokemonId.Pidgey, PokemonId.Rattata
  148. };
  149. _pokemonsToEvolve = _pokemonsToEvolve ?? LoadPokemonList("Configs\\ConfigPokemonsToEvolve.ini", defaultPokemon);
  150. return _pokemonsToEvolve;
  151. }
  152. }
  153.  
  154. public ICollection<PokemonId> PokemonsNotToTransfer
  155. {
  156. get
  157. {
  158. //Type of pokemons not to transfer
  159. List<PokemonId> defaultPokemon = new List<PokemonId> {
  160. PokemonId.Dragonite, PokemonId.Charizard, PokemonId.Zapdos, PokemonId.Snorlax, PokemonId.Alakazam, PokemonId.Mew, PokemonId.Mewtwo
  161. };
  162. _pokemonsNotToTransfer = _pokemonsNotToTransfer ?? LoadPokemonList("Configs\\ConfigPokemonsToKeep.ini", defaultPokemon);
  163. return _pokemonsNotToTransfer;
  164. }
  165. }
  166.  
  167. //Do not catch those
  168. public ICollection<PokemonId> PokemonsNotToCatch
  169. {
  170. get
  171. {
  172. //Type of pokemons not to catch
  173. List<PokemonId> defaultPokemon = new List<PokemonId> {
  174. PokemonId.Zubat, PokemonId.Pidgey, PokemonId.Rattata
  175. };
  176. _pokemonsNotToCatch = _pokemonsNotToCatch ?? LoadPokemonList("Configs\\ConfigPokemonsNotToCatch.ini", defaultPokemon);
  177. return _pokemonsNotToCatch;
  178. }
  179. }
  180.  
  181. private static ICollection<PokemonId> LoadPokemonList(string filename, List<PokemonId> defaultPokemon)
  182. {
  183. ICollection<PokemonId> result = new List<PokemonId>();
  184.  
  185. DirectoryInfo di = Directory.CreateDirectory(Directory.GetCurrentDirectory() + "\\Configs");
  186.  
  187. if (File.Exists(Directory.GetCurrentDirectory() + "\\" + filename))
  188. {
  189. Logger.Write($"Loading File: {filename}");
  190.  
  191. var content = string.Empty;
  192. using (StreamReader reader = new StreamReader(filename))
  193. {
  194. content = reader.ReadToEnd();
  195. reader.Close();
  196. }
  197.  
  198. content = Regex.Replace(content, @"\\/\*(.|\n)*?\*\/", ""); //todo: supposed to remove comment blocks
  199.  
  200.  
  201. StringReader tr = new StringReader(content);
  202.  
  203. var pokemonName = tr.ReadLine();
  204. while (pokemonName != null)
  205. {
  206. PokemonId pokemon;
  207. if (Enum.TryParse<PokemonId>(pokemonName, out pokemon))
  208. {
  209. result.Add((PokemonId)pokemon);
  210. }
  211. pokemonName = tr.ReadLine();
  212. }
  213. }
  214. else
  215. {
  216. Logger.Write($"File: {filename} not found, creating new...", LogLevel.Warning);
  217. using (var w = File.AppendText(Directory.GetCurrentDirectory() + "\\" + filename))
  218. {
  219. defaultPokemon.ForEach(pokemon => w.WriteLine(pokemon.ToString()));
  220. defaultPokemon.ForEach(pokemon => result.Add((PokemonId)pokemon));
  221. w.Close();
  222. }
  223. }
  224. return result;
  225. }
  226.  
  227.  
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement