public static void CustomBuildService() { try { if (Builds.Keys.Any(b => b.Equals(Build.CleanUpChampionName(Player.Instance.ChampionName))) && Builds.FirstOrDefault(b => b.Key.Equals(Build.CleanUpChampionName(Player.Instance.ChampionName))).Value.TryParseData(out CurrentChampionBuild)) { Logger.Send(Build.CleanUpChampionName(Player.Instance.ChampionName) + " build Loaded!"); // and set up event listeners SetUpEventListeners(); if (Player.Instance.IsInShopRange()) { Buy.BuyNextItem(CurrentChampionBuild); } } else { // An error occured during parsing. Catch the error and print it in the console Logger.Send("The selected AutoShop JSON could not be parsed.", Logger.LogLevel.Error); Logger.Send("Using Default Build!", Logger.LogLevel.Warn); UseDefaultBuild(); //Logger.Send("No build is currently used!", Logger.LogLevel.Warn); } } catch (Exception ex) { // An exception occured somewhere else. Notify the user of the error, and print the exception to the console Logger.Send("Exception occurred on initialization of AutoShop:", ex, Logger.LogLevel.Error); // Warn the user about the exception Logger.Send("Exception occurred during AutoShop initialization. AutoShop will most likely NOT work properly!", Logger.LogLevel.Warn); } }
/// <summary> /// Initializes the AutoShop system /// </summary> public static void Init() { try { var service = Config.CurrentBuildService == "" ? "" : "\\" + Config.CurrentPatchUsed + "\\" + Config.CurrentBuildService; Buy.CanShop = !Player.Instance.Buffs.Any(b => b.DisplayName.Equals("aramshopdisableplayer", StringComparison.CurrentCultureIgnoreCase)) || Player.Instance.IsDead; //var useDefaultBuild = false; // When the game starts AramBuddy.Events.OnGameStart += Events_OnGameStart; // Check if the index file exists if (!File.Exists(TempFile)) { // If not, create the index file Buy.CreateIndexFile(); } if (!Directory.Exists(BuildPath)) { Directory.CreateDirectory(BuildPath); } // Loop through all the builds in the build path directory foreach (var build in Directory.GetFiles(BuildPath)) { // Get the name of the champion from the build var parsed = build.Replace(".json", "").Replace(BuildPath + "\\", ""); // Add the build to the Builds dictionary in a ChampionName : BuildData format Builds.Add(parsed, File.ReadAllText(build)); } if (!Directory.Exists(BuildPath + service)) { Directory.CreateDirectory(BuildPath + service); } // Loop through all the builds in the build path directory foreach (var build in Directory.GetFiles(BuildPath + service)) { // Get the name of the champion from the build var parsed = build.Replace(".json", "").Replace(BuildPath + service + "\\", ""); // Add the build to the Builds dictionary in a ChampionName : BuildData format if (!Builds.ContainsKey(parsed)) { Builds.Add(parsed, File.ReadAllText(build)); } } // Check if there are any builds for our champion if (Builds.Keys.All(b => Build.CleanUpChampionName(b) != Build.CleanUpChampionName(Player.Instance.ChampionName))) { // If not, warn the user Logger.Send("There are no builds for your champion. " + Player.Instance.ChampionName, Logger.LogLevel.Warn); if (service != "") { Build.GetBuildFromService(); } else { UseDefaultBuild(); } } /*if (useDefaultBuild) * return;*/ // Check if the parse of the build for the champion completed successfully and output it to public // variable CurrentChampionBuild if (Builds.Any(b => Build.CleanUpChampionName(b.Key) == Build.CleanUpChampionName(Player.Instance.ChampionName)) && Builds.FirstOrDefault(b => Build.CleanUpChampionName(b.Key) == Build.CleanUpChampionName(Player.Instance.ChampionName)).Value.TryParseData(out CurrentChampionBuild)) { // If the parse is successful, notify the user that the initialization process is finished Logger.Send(Config.CurrentPatchUsed + " " + Player.Instance.ChampionName + " Build Loaded !"); Logger.Send("AutoShop has been fully and succesfully initialized!"); // and set up event listeners SetUpEventListeners(); Buy.BuyNextItem(CurrentChampionBuild); } } catch (Exception ex) { // An exception occured somewhere else. Notify the user of the error, and print the exception to the console Logger.Send("Exception occurred on initialization of AutoShop:", ex, Logger.LogLevel.Error); // Warn the user about the exception Logger.Send("Exception occurred during AutoShop initialization. AutoShop will most likely NOT work properly!", Logger.LogLevel.Warn); } }