Пример #1
0
        /// <summary>
        ///     Method that sets up event listeners
        /// </summary>
        ///
        public static void DefaultBuild()
        {
            try
            {
                // Use Default build
                if (Builds.Keys.Any(b => b.Equals(Build.BuildName())) && Builds.FirstOrDefault(b => b.Key.Equals(Build.BuildName())).Value.TryParseData(out CurrentChampionBuild))
                {
                    Logger.Send(Build.BuildName() + " build Loaded!", Logger.LogLevel.Info);

                    // 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("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);
            }
        }
Пример #2
0
        /// <summary>
        ///     Initializes the AutoShop system
        /// </summary>
        public static void Init()
        {
            try
            {
                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;

                // Item Bought Event, reduce the temp value when we buy the item.
                Events.OnBuyItem += delegate
                {
                    Core.DelayAction(
                        () =>
                    {
                        // Try to buy more than one item if we can afford it
                        Buy.BuyNextItem(CurrentChampionBuild);
                    },
                        new Random().Next(900 + Game.Ping, 2750 + Game.Ping));
                };

                // Create the build path directory
                Directory.CreateDirectory(BuildPath);

                // Check if the index file exists
                if (!File.Exists(TempFile))
                {
                    // If not, create the index file
                    Buy.CreateIndexFile();
                }

                // 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));
                }

                // Check if there are any builds for our champion
                if (Builds.Keys.All(b => b != Player.Instance.ChampionName))
                {
                    // If not, warn the user
                    Logger.Send("There are no builds for your champion. " + Player.Instance.ChampionName, Logger.LogLevel.Warn);

                    // and Use Default build
                    if (Builds.Keys.Any(b => b.Equals(Build.BuildName())))
                    {
                        DefaultBuild();
                        Logger.Send("Using default build path!", Logger.LogLevel.Warn);
                    }
                    else
                    {
                        // Creates Default Build for the AutoShop
                        Logger.Send("Creating default build path!", Logger.LogLevel.Warn);
                        Build.Create();
                        useDefaultBuild = true;
                    }
                }

                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 => b.Key == Player.Instance.ChampionName) && Builds.FirstOrDefault(b => b.Key == Player.Instance.ChampionName).Value.TryParseData(out CurrentChampionBuild))
                {
                    // If the parse is successful, notify the user that the initialization process is finished
                    Logger.Send("AutoShop has been fully and succesfully initialized!", Logger.LogLevel.Info);

                    // 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);
            }
        }
Пример #3
0
        /// <summary>
        ///     Initializes the AutoShop system
        /// </summary>
        public static void Init()
        {
            try
            {
                // When the game starts
                AramBuddy.Events.OnGameStart += Events_OnGameStart;

                // Create the build path directory
                Directory.CreateDirectory(BuildPath);

                // Check if the index file exists
                if (!File.Exists(TempPath + "\\buildindex" + Player.Instance.NetworkId + ".dat"))
                {
                    // If not, create the index file
                    Buy.CreateIndexFile();
                }

                // Loop through all the builds in the build path directory
                foreach (string build in Directory.GetFiles(BuildPath))
                {
                    // Get the name of the champion from the build
                    string parsed = build.Replace(".json", "").Replace(BuildPath + "\\", "");

                    // Add the build to the Builds dictionary in a ChampionName : BuildData format
                    Builds.Add(parsed, File.ReadAllText(build));
                }

                // Check if there are any builds for our champion
                if (Builds.Keys.All(b => b != Player.Instance.ChampionName))
                {
                    // If not, warn the user
                    Console.ForegroundColor = ConsoleColor.Magenta;
                    Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Warning] There are no builds for your champion.");

                    // and Use Default build
                    if (Builds.Keys.Any(b => b.Equals(Build.BuildName())))
                    {
                        Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Warning] Using default build path!");
                        Console.ResetColor();
                    }
                    else
                    {
                        // Creates Default Build for the AutoShop
                        Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Warning] Creating default build path!");
                        Build.Create();
                        Console.ResetColor();
                    }
                }

                // Check if the parse of the build for the champion completed successfully and output it to public
                // variable CurrentChampionBuild
                if (Builds.Any(b => b.Key == Player.Instance.ChampionName) &&
                    Builds.FirstOrDefault(b => b.Key == Player.Instance.ChampionName).Value.TryParseData(out CurrentChampionBuild))
                {
                    // If the parse is successful, notify the user that the initialization process is finished
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Info] AutoShop has been fully and succesfully initialized!");

                    // and set up event listeners
                    SetUpEventListeners();
                    Console.ResetColor();
                }
                else
                {
                    Core.DelayAction(
                        () =>
                    {
                        // Use Default build
                        if (Builds.Keys.Any(b => b.Equals(Build.BuildName())) &&
                            Builds.FirstOrDefault(b => b.Key.Equals(Build.BuildName())).Value.TryParseData(out CurrentChampionBuild))
                        {
                            Console.ForegroundColor = ConsoleColor.Cyan;
                            Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Info] " + Build.BuildName() + " build Loaded!");
                            Console.ResetColor();

                            // 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
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Error] The selected AutoShop JSON could not be parsed.");
                            Console.ResetColor();

                            Console.ForegroundColor = ConsoleColor.Magenta;
                            Console.WriteLine(DateTime.Now.ToString("[H:mm:ss - ") + "AramBuddy Warning] No build is currently used!");
                            Console.ResetColor();
                        }
                    }, 9000);
                }
            }
            catch (Exception ex)
            {
                // An exception occured somewhere else. Notify the user of the error, and print the exception to the console
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(
                    DateTime.Now.ToString(Environment.NewLine + "[H:mm:ss - ") + "AramBuddy Error] Exception occurred on initialization of AutoShop:");
                Console.ResetColor();
                Console.Write(ex);

                // Warn the user about the exception
                Console.ForegroundColor = ConsoleColor.Magenta;
                Console.WriteLine(
                    DateTime.Now.ToString("H:mm:ss - ")
                    + "AramBuddy Warning] Exception occurred during AutoShop initialization. AutoShop will most likely NOT work properly!");
                Console.ResetColor();
            }
        }