Exemplo n.º 1
0
        /// <summary>
        /// Resets the executing position in Overwatch.
        /// </summary>
        /// <returns>The state of Overwatch.</returns>
        public OverwatchState Reset()
        {
            using (LockHandler.Interactive)
            {
                Chat.CloseChat();

                for (int i = 0; i < 10; i++)
                {
                    UpdateScreen();
                    // Check if Ovewratch is disconnected.
                    if (IsDisconnected())
                    {
                        return(OverwatchState.Disconnected);
                    }

                    // Check if Overwatch is in the main menu
                    if (Capture.CompareTo(Points.LOBBY_NAV_MAINMENU, Markups.NAV_MAINMENU, 60, 90, DBCompareFlags.IgnoreBlack))
                    {
                        // Overwatch is in the main menu.
                        if (OpenChatIsDefault)
                        {
                            Chat.OpenChat();
                        }
                        return(OverwatchState.MainMenu);
                    }

                    // Check if Overwatch is in the escape menu.
                    if (Capture.CompareTo(Points.LOBBY_NAV_ESCAPEMENU, Markups.NAV_ESCAPEMENU, 50, 95, DBCompareFlags.IgnoreBlack))
                    {
                        // Overwatch is in the escape menu.
                        KeyPress(DefaultKeys.OpenCustomGameLobbyKey.Key);
                        Thread.Sleep(Timing.LOBBY_FADE);
                        UpdateScreen();
                    }

                    // Check if Overwatch is in the custom game menu.
                    if (Capture.CompareTo(Points.LOBBY_NAV_CREATEGAME, Markups.NAV_LOBBY, new int[] { 152, 149, 151 }, 30, 90))
                    {
                        // Overwatch is in the custom game menu.
                        if (OpenChatIsDefault)
                        {
                            Chat.OpenChat();
                        }
                        return(OverwatchState.Ready);
                    }

                    KeyPress(Keys.Escape);
                    Thread.Sleep(500);
                    Activate();
                }
                throw new UnknownOverwatchStateException();
            }
        }
        /// <summary>
        /// Starts the game.
        /// </summary>
        public void StartGame()
        {
            using (LockHandler.Interactive)
            {
                if (OpenChatIsDefault)
                    Chat.CloseChat();

                LeftClick(Points.LOBBY_START_GAME, 3000);
                LoadStall();
                BackToMenu();

                if (OpenChatIsDefault)
                    Chat.OpenChat();
            }
        }
        /// <summary>
        /// Restarts the game.
        /// </summary>
        public void RestartGame()
        {
            if (OpenChatIsDefault)
            {
                Chat.CloseChat();
            }

            LeftClick(500, 455);
            LoadStall();
            BackToMenu();

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
        /// <summary>
        /// Starts the game.
        /// </summary>
        public void StartGame()
        {
            if (OpenChatIsDefault)
            {
                Chat.CloseChat();
            }

            LeftClick(451, 458, 3000);
            LoadStall();
            BackToMenu();

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
Exemplo n.º 5
0
        /// <summary>
        /// Starts the game.
        /// </summary>
        public void StartGame()
        {
            if (OpenChatIsDefault)
            {
                Chat.CloseChat();
            }

            LeftClick(Points.LOBBY_START_GAME, 3000);
            LoadStall();
            BackToMenu();

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
Exemplo n.º 6
0
        /// <summary>
        /// Restarts the game.
        /// </summary>
        public void RestartGame()
        {
            using (LockHandler.Interactive)
            {
                if (OpenChatIsDefault)
                {
                    Chat.CloseChat();
                }

                LeftClick(Points.LOBBY_RESTART);
                LoadStall();
                BackToMenu();

                if (OpenChatIsDefault)
                {
                    Chat.OpenChat();
                }
            }
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates a Custom Game from the main menu.
        /// </summary>
        public void CreateCustomGame()
        {
            OverwatchState gameState = Reset();

            Chat.CloseChat();
            ResetMouse();

            if (gameState == OverwatchState.MainMenu)
            {
                KeyPress(100, Keys.Tab, Keys.Space);
                Thread.Sleep(500);
                KeyPress(100, Keys.Tab, Keys.Tab, Keys.Tab, Keys.Tab, Keys.Space);
                Thread.Sleep(500);
                KeyPress(100, Keys.Tab, Keys.Tab, Keys.Tab, Keys.Tab, Keys.Space);
                Thread.Sleep(500);
            }

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
        /// <summary>
        /// Toggles what heroes can be selected.
        /// </summary>
        /// <param name="ta">Determines if all heroes should be enabled, disabled or neither before toggling</param>
        /// <param name="team">Team to change roster for.</param>
        /// <param name="heroes">Heroes to toggle.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if <paramref name="team"/> is Spectator or Queue.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="heroes"/> is null.</exception>
        /// <include file='docs.xml' path='doc/setHeroRoster/example'></include>
        public void SetHeroRoster(ToggleAction ta, Team team, params Hero[] heroes)
        {
            using (LockHandler.Interactive)
            {
                if (team.HasFlag(Team.Spectator) || team.HasFlag(Team.Queue))
                {
                    throw new ArgumentOutOfRangeException(nameof(team), team, "Team cannot be Spectator or Queue.");
                }

                if (heroes == null)
                {
                    throw new ArgumentNullException(nameof(heroes));
                }

                GoToSettings();
                LeftClick(Points.SETTINGS_HEROES);        // click heroes
                LeftClick(Points.SETTINGS_HEROES_ROSTER); // click hero roster
                                                          // If team doesn't equal both, click a team to change hero roster for.
                if (team == Team.Blue)
                {
                    LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_DROPDOWN, 250);
                    LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_BLUE, 250);
                }
                if (team == Team.Red)
                {
                    LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_DROPDOWN, 250);
                    LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_RED, 250);
                }
                // If the toggle action is disable all, disable all heroes before toggling.
                if (ta == ToggleAction.DisableAll)
                {
                    LeftClick(Points.SETTINGS_HEROES_ROSTER_DISABLE_ALL, 250);
                }
                // If the toggle action is enable all, enable all heroes before toggling.
                else if (ta == ToggleAction.EnableAll)
                {
                    LeftClick(Points.SETTINGS_HEROES_ROSTER_ENABLE_ALL, 250);
                }

                if (OpenChatIsDefault)
                {
                    Chat.CloseChat();
                }

                KeyPress(Keys.Down);
                Thread.Sleep(1);
                if (team == Team.BlueAndRed)
                {
                    KeyPress(Keys.Down);
                    Thread.Sleep(1);
                }

                // For each hero
                for (int i = 0; i < Enum.GetNames(typeof(Hero)).Length; i++)
                {
                    // Toggle hero if current hero selected is set in the heroes array.
                    for (int hi = 0; hi < heroes.Length; hi++)
                    {
                        if ((int)heroes[hi] == i)
                        {
                            KeyPress(Keys.Space);
                            Thread.Sleep(1);
                        }
                    }
                    KeyPress(Keys.Down);
                    Thread.Sleep(1);
                }

                GoBack(3, 0);

                if (OpenChatIsDefault)
                {
                    Chat.OpenChat();
                }
            }
        }
        /// <summary>
        /// Change individual hero settings.
        /// </summary>
        /// <param name="herodata">Settings of the heroes you want to change.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown if a <paramref name="herodata"/>'s set and setto length are not equal length.</exception>
        /// <exception cref="InvalidSetheroException">Thrown if a setting does not exist for their respective heros or if a set's respective setto is not the correct type.</exception>
        /// <exception cref="ArgumentNullException">Thrown if <paramref name="herodata"/> is null.</exception>
        /// <remarks>
        /// The complete list of settings can be found <a href="https://github.com/ItsDeltin/Overwatch-Custom-Game-Automation/blob/master/CustomGameLib/CustomGameLib/Resources/hero_settings.txt" content="here."/>
        /// Toggle settings require a boolean. Value and dropdown settings require an integer.
        /// </remarks>
        /// <include file='docs.xml' path='doc/setHeroSettings/example'></include>
        /// <seealso cref="SetHero"/>
        public void SetHeroSettings(params SetHero[] herodata)
        {
            const int keyPressWait = 50;

            using (LockHandler.Interactive)
            {
                if (herodata == null)
                {
                    throw new ArgumentNullException(nameof(herodata));
                }

                if (OpenChatIsDefault)
                {
                    Chat.CloseChat();
                }

                GoToSettings();                    // Open settings (SETTINGS/)
                LeftClick(Points.SETTINGS_HEROES); // click heroes (SETTINGS/HEROES/)
                                                   // For each hero to change settings for
                foreach (SetHero hero in herodata)
                {
                    int heroid = 0;
                    // Click the hero selected's settings.
                    if (hero.Hero == null)
                    {
                        // *General
                        LeftClick(Points.SETTINGS_HEROES_GENERAL); // Open general settings
                    }
                    else
                    {
                        // *Everyone else
                        // Open the hero's settings.
                        heroid = (int)hero.Hero;

                        KeyPress(Keys.Down, Keys.Down);
                        GridNavigator(heroid);
                        KeyPress(500, Keys.Space);

                        heroid += 1;
                    }
                    // heroid is now 0 = General, 1 = Ana, 2 = Bastion, etc.

                    if (hero.Team != Team.BlueAndRed)
                    {
                        // Click team to change settings for.
                        if (hero.Team == Team.Blue)
                        {
                            LeftClick(Points.SETTINGS_HEROES_SETTINGS_TEAM_DROPDOWN); // click team menu
                            LeftClick(Points.SETTINGS_HEROES_SETTINGS_TEAM_BLUE);     // click blue
                        }
                        if (hero.Team == Team.Red)
                        {
                            LeftClick(Points.SETTINGS_HEROES_SETTINGS_TEAM_DROPDOWN); // click team menu
                            LeftClick(Points.SETTINGS_HEROES_SETTINGS_TEAM_RED);      // click red
                        }
                        // Make topmost option highlighted
                        KeyPress(Keys.Down);
                        Thread.Sleep(25);
                    }
                    else
                    {
                        // Make topmost option highlighted
                        KeyPress(Keys.Down);
                        Thread.Sleep(keyPressWait);
                        // <image url="$(ProjectDir)\ImageComments\HeroSettings.cs\TopOption.png" scale="0.55" />
                        UpdateScreen();
                        // Check if the second option is highlighted.
                        if (Capture.CompareColor(422, 200, Colors.WHITE, 10))
                        {
                            // If it is, press the up arrow.
                            KeyPress(Keys.Up);
                            Thread.Sleep(keyPressWait);
                        }
                    }

                    // Get the last setting to change.
                    int max = 0;
                    for (int si = 0; si < HeroSettings.HeroSettingsList[heroid].Count; si++)
                    {
                        if (hero.Set.Contains(HeroSettings.HeroSettingsList[heroid][si].Setting))
                        {
                            max = si;
                        }
                    }
                    max += 1;

                    // si stands for setting index.
                    for (int si = 0; si < max; si++)
                    {
                        // Test if current setting selected is a setting that needs to be changed.
                        for (int setSettingIndex = 0; setSettingIndex < hero.Set.Length; setSettingIndex++)
                        {
                            if (hero.Set[setSettingIndex] == HeroSettings.HeroSettingsList[heroid][si].Setting)
                            {
                                // <image url="$(ProjectDir)\ImageComments\HeroSettings.cs\SettingType.png" scale="0.5" />
                                // If the setting selected a toggle setting...
                                if (HeroSettings.HeroSettingsList[heroid][si].Type == SettingType.toggle)
                                {
                                    // Check what the toggle setting selected is set to.
                                    bool value  = (bool)GetHighlightedSettingValue(true);
                                    bool option = (bool)hero.SetTo[setSettingIndex];

                                    if (value != option)
                                    {
                                        KeyPress(Keys.Space);
                                        Thread.Sleep(keyPressWait);
                                    }
                                }
                                // If the selected setting is a dropdown menu...
                                else if (HeroSettings.HeroSettingsList[heroid][si].Type == SettingType.dropdown)
                                {
                                    KeyPress(Keys.Space);
                                    Thread.Sleep(keyPressWait);
                                    KeyPress(Keys.Up); Thread.Sleep(keyPressWait); KeyPress(Keys.Up);
                                    int option = (int)hero.SetTo[setSettingIndex];

                                    /* If the option variable equals 2, only Torbjorn's hammer can be used.
                                     * 0 = ALL
                                     * 1 = RIVET GUN ONLY
                                     * 2 = FORGE HAMMER ONLY */
                                    for (int oi = 0; oi < option; oi++)
                                    {
                                        KeyPress(Keys.Down);
                                        Thread.Sleep(keyPressWait);
                                    }
                                    KeyPress(Keys.Space);
                                    Thread.Sleep(keyPressWait);
                                }
                                // If the selected setting is a numeric value...
                                else // the last possible thing Settings[heroid][si].type could be is SettingType.value
                                {
                                    var keys = GetNumberKeys((int)hero.SetTo[setSettingIndex]); // The numeric value to set the setting to as a string.
                                    for (int sk = 0; sk < keys.Length; sk++)
                                    {
                                        KeyDown(keys[sk]);
                                        Thread.Sleep(keyPressWait);
                                    }
                                    KeyPress(Keys.Return);
                                    Thread.Sleep(keyPressWait);
                                }
                            }
                        }

                        // Go to next setting
                        KeyPress(Keys.Down);
                        Thread.Sleep(keyPressWait);
                    }
                    GoBack(1);
                }
                // Go back to custom game menu.
                GoBack(2);
                if (OpenChatIsDefault)
                {
                    Chat.OpenChat();
                }
            }
        }
        /// <summary>
        /// Creates new CustomGame object.
        /// </summary>
        public CustomGame(CustomGameBuilder customGameBuilder = null)
        {
            if (customGameBuilder == null)
            {
                customGameBuilder = new CustomGameBuilder();
            }

            // Get the overwatch process.
            if (customGameBuilder.OverwatchProcess != null)
            {
                OverwatchProcess = customGameBuilder.OverwatchProcess;
            }
            else
            {
                OverwatchProcess = GetOverwatchProcess();
            }

            if (OverwatchProcess == null)
            {
                throw new MissingOverwatchProcessException("Could not find any Overwatch processes running.");
            }

            // Initialize the LockHandler.
            LockHandler = new LockHandler(this);

            // Save the customGameBuilder values to the class.
            ScreenshotMethod  = customGameBuilder.ScreenshotMethod;
            OpenChatIsDefault = customGameBuilder.OpenChatIsDefault;
            DefaultKeys       = customGameBuilder.DefaultKeys;
            DisableInput      = customGameBuilder.DisableInput;

            // Create a link between OnExit and OverwatchProcess.Exited.
            OverwatchProcess.EnableRaisingEvents = true;
            OverwatchProcess.Exited += InvokeOnExit;

            // Move the window to the correct position on the desktop for scanning and input.
            SetupWindow(OverwatchHandle, ScreenshotMethod);
            Thread.Sleep(250);

            // Create subclass instances.
            Commands   = new Commands(this);
            AI         = new AI(this);
            Chat       = new Chat(this);
            Pause      = new Pause(this);
            PlayerInfo = new PlayerInfo(this);
            Interact   = new Interact(this);
            Settings   = new Settings(this);

            UpdateScreen();

#if DEBUG
            if (customGameBuilder.DebugMode)
            {
                SetupDebugWindow();
            }
#endif

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
            else
            {
                Chat.CloseChat();
            }

            StartPersistentScanning();
        }
Exemplo n.º 11
0
        /// <summary>
        /// Change individual hero settings.
        /// </summary>
        /// <param name="herodata">Settings of the heroes you want to change.</param>
        /// <exception cref="ArgumentOutOfRangeException">Thrown when a herodata's set and setto length are not equal length.</exception>
        /// <exception cref="InvalidSetheroException">Thrown when any of the settings do not exist for their respective heros or if a set's respective setto is not the correct type.</exception>
        public void SetHeroSettings(params SetHero[] herodata)
        {
            // Throw exception if any of the set or setto values in herodata are not the same length.
            for (int i = 0; i < herodata.Length; i++)
            {
                if (herodata[i].Set.Length != herodata[i].SetTo.Length)
                {
                    throw new ArgumentOutOfRangeException("herodata", "The values \"set\" and \"setto\" must be equal length.");
                }
            }
            // Throw exception if any of the settings do not exist for their respective heros or if a set's respective setto is not the correct type.
            foreach (SetHero hero in herodata)
            {
                for (int i = 0; i < hero.Set.Length; i++)
                {
                    SettingType?st = GetSettingType(hero.Hero, hero.Set[i]);
                    // If the setting does not exist.
                    if (st == null)
                    {
                        if (hero.Hero != null)
                        {
                            throw new InvalidSetheroException(string.Format("The setting \"{0}\" does not exist in {1}'s settings.", hero.Set[i], hero.Hero.ToString()));
                        }
                        else
                        {
                            throw new InvalidSetheroException(string.Format("The setting \"{0}\" does not exist in the general settings.", hero.Set[i]));
                        }
                    }
                    // For setting types that require a boolean.
                    if (st == SettingType.toggle)
                    {
                        if (hero.SetTo[i] is bool == false)
                        {
                            throw new InvalidSetheroException(string.Format("The setting \"{0}\" requires a boolean on index '{1}' of setto.", hero.Set[i], i));
                        }
                    }
                    // For setting types that require an integer.
                    else if (st == SettingType.value || st == SettingType.dropdown)
                    {
                        if (hero.SetTo[i] is int == false)
                        {
                            throw new InvalidSetheroException(string.Format("The setting \"{0}\" requires a integer on index '{1}' of setto.", hero.Set[i], i));
                        }
                    }
                }
            }

            if (OpenChatIsDefault)
            {
                Chat.CloseChat();
            }
            GoToSettings();      // Open settings (SETTINGS/)
            LeftClick(351, 311); // click heroes (SETTINGS/HEROES/)
            // For each hero to change settings for
            foreach (SetHero hero in herodata)
            {
                int heroid = 0;
                // Click the hero selected's settings.
                if (hero.Hero == null)
                {
                    // *General
                    LeftClick(80, 146); // Open general settings
                }
                else
                {
                    // *Everyone else
                    // Open the hero in hero.Hero's settings.
                    heroid = (int)hero.Hero; // Get int value of hero from the enum.
                    int select = heroid;
                    int y      = 208;        // Y coordinate of first hero row (Ana, Bastion, Dva, Doomfist). Increments by 33 for each row.
                    while (true)
                    {
                        if (select > 3)
                        {
                            y      += 33; // add y by length of hero selection row
                            select -= 4;
                        }
                        else
                        {
                            // <image url="$(ProjectDir)\ImageComments\SelectHero.cs\Column.png" scale="0.7" />
                            // Select the first column
                            if (select == 0)
                            {
                                LeftClick(80, y);
                            }
                            // Select the second column
                            else if (select == 1)
                            {
                                LeftClick(224, y);
                            }
                            // Select the third column
                            else if (select == 2)
                            {
                                LeftClick(368, y);
                            }
                            // Select the fourth column
                            else if (select == 3)
                            {
                                LeftClick(511, y);
                            }
                            break;
                        }
                    }
                    heroid++;
                }
                // heroid is now 0 = general, 1 = ana, 2 = bastion and so on.

                if (hero.Team != BotTeam.Both)
                {
                    // Click team to change settings for.
                    if (hero.Team == BotTeam.Blue)
                    {
                        LeftClick(572, 126); // click team menu
                        LeftClick(572, 173); // click blue
                    }
                    if (hero.Team == BotTeam.Red)
                    {
                        LeftClick(572, 126); // click team menu
                        LeftClick(572, 192); // click red
                    }
                    // Make topmost option highlighted
                    KeyPress(Keys.Down);
                    Thread.Sleep(25);
                }
                else
                {
                    // Make topmost option highlighted
                    KeyPress(Keys.Down);
                    Thread.Sleep(KeyPressWait);
                    // <image url="$(ProjectDir)\ImageComments\SelectHero.cs\TopOption.png" scale="0.55" />
                    updateScreen();
                    // Check if the second option is highlighted.
                    if (CompareColor(422, 200, CALData.WhiteColor, 10))
                    {
                        // If it is, press the up arrow.
                        KeyPress(Keys.Up);
                        Thread.Sleep(KeyPressWait);
                    }
                }

                // Get the last setting to change.
                int max = 0;
                for (int si = 0; si < Settings[heroid].Length; si++)
                {
                    if (hero.Set.Contains(Settings[heroid][si].setting))
                    {
                        max = si;
                    }
                }
                max += 1;

                // si stands for setting index.
                for (int si = 0; si < max; si++)
                {
                    // Test if current setting selected is a setting that needs to be changed.
                    for (int setSettingIndex = 0; setSettingIndex < hero.Set.Length; setSettingIndex++)
                    {
                        if (hero.Set[setSettingIndex] == Settings[heroid][si].setting)
                        {
                            // <image url="$(ProjectDir)\ImageComments\SelectHero.cs\SettingType.png" scale="0.5" />
                            // If the setting selected a toggle setting...
                            if (Settings[heroid][si].type == SettingType.toggle)
                            {
                                // Check what the toggle setting selected is set to.
                                bool value  = (bool)GetHighlightedSettingValue(true);
                                bool option = (bool)hero.SetTo[setSettingIndex];

                                if (value != option)
                                {
                                    KeyPress(Keys.Space);
                                    Thread.Sleep(KeyPressWait);
                                }
                            }
                            // If the selected setting is a dropdown menu...
                            else if (Settings[heroid][si].type == SettingType.dropdown)
                            {
                                KeyPress(Keys.Space);
                                Thread.Sleep(KeyPressWait);
                                KeyPress(Keys.Up); Thread.Sleep(KeyPressWait); KeyPress(Keys.Up);
                                int option = (int)hero.SetTo[setSettingIndex];

                                /* If the option variable equals 2, only Torbjorn's hammer can be used.
                                 * 0 = ALL
                                 * 1 = RIVET GUN ONLY
                                 * 2 = FORGE HAMMER ONLY */
                                for (int oi = 0; oi < option; oi++)
                                {
                                    KeyPress(Keys.Down);
                                    Thread.Sleep(KeyPressWait);
                                }
                                KeyPress(Keys.Space);
                                Thread.Sleep(KeyPressWait);
                            }
                            // If the selected setting is a numeric value...
                            else // the last possible thing Settings[heroid][si].type could be is SettingType.value
                            {
                                var keys = GetNumberKeys((int)hero.SetTo[setSettingIndex]); // The numeric value to set the setting to as a string.
                                for (int sk = 0; sk < keys.Length; sk++)
                                {
                                    KeyDown(keys[sk]);
                                    Thread.Sleep(KeyPressWait);
                                }
                                KeyPress(Keys.Return);
                                Thread.Sleep(KeyPressWait);
                            }
                        }
                    }

                    // Go to next setting
                    KeyPress(Keys.Down);
                    Thread.Sleep(KeyPressWait);
                }
                GoBack(1);
            }
            // Go back to custom game menu.
            GoBack(2);
            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
Exemplo n.º 12
0
        /// <summary>
        /// Toggles what heroes can be selected.
        /// </summary>
        /// <param name="ta">Determines if all heroes should be enabled, disabled or neither before toggling</param>
        /// <param name="team">Team to change roster for.</param>
        /// <param name="heroes">Heroes to toggle.</param>
        public void SetHeroRoster(ToggleAction ta, BotTeam team, params Hero[] heroes)
        {
            GoToSettings();
            LeftClick(351, 311); // click heroes
            LeftClick(287, 158); // click hero roster
            // If team doesn't equal both, click a team to change hero roster for.
            if (team == BotTeam.Blue)
            {
                LeftClick(492, 127, 250);
                LeftClick(484, 173, 250);
            }
            if (team == BotTeam.Red)
            {
                LeftClick(492, 127, 250);
                LeftClick(484, 193, 250);
            }
            // If the toggle action is disable all, disable all heroes before toggling.
            if (ta == ToggleAction.DisableAll)
            {
                LeftClick(635, 130, 250);
            }
            // If the toggle action is enable all, enable all heroes before toggling.
            else if (ta == ToggleAction.EnableAll)
            {
                LeftClick(597, 130, 250);
            }

            if (OpenChatIsDefault)
            {
                Chat.CloseChat();
            }

            KeyPress(Keys.Down);
            Thread.Sleep(1);
            if (team == BotTeam.Both)
            {
                KeyPress(Keys.Down);
                Thread.Sleep(1);
            }

            // For each hero
            for (int i = 0; i < Enum.GetNames(typeof(Hero)).Length; i++)
            {
                // Toggle hero if current hero selected is set in the heroes array.
                for (int hi = 0; hi < heroes.Length; hi++)
                {
                    if ((int)heroes[hi] == i)
                    {
                        KeyPress(Keys.Space);
                        Thread.Sleep(1);
                    }
                }
                KeyPress(Keys.Down);
                Thread.Sleep(1);
            }

            GoBack(3, 0);

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
Exemplo n.º 13
0
        private SlotIdentity GetSlotIdentity(int slot)
        {
            using (LockHandler.Passive)
            {
                if (!AllSlots.Contains(slot))
                {
                    return(null);
                }

                if (slot == 5 && OpenChatIsDefault)
                {
                    Chat.CloseChat();
                }
                if (slot == 0)
                {
                    ResetMouse();
                }

                Point origin = Point.Empty;
                int   width  = 0;
                int   height = 0;

                if (IsSlotBlueOrRed(slot))
                {
                    width  = 158;
                    height = Distances.LOBBY_SLOT_HEIGHT;

                    int comp = slot;
                    if (IsSlotBlue(slot))
                    {
                        origin = new Point(145, 239);
                    }
                    else if (IsSlotRed(slot))
                    {
                        origin = new Point(372, 239);
                        comp  -= 6;
                    }
                    origin.Y += Distances.LOBBY_SLOT_DISTANCE * comp;
                }
                else if (IsSlotSpectatorOrQueue(slot))
                {
                    width  = 158;
                    height = Distances.LOBBY_SPECTATOR_SLOT_HEIGHT;
                    origin = new Point(666, 245);

                    int comp = slot;
                    if (IsSlotSpectator(slot))
                    {
                        origin.Y += FindSpectatorOffset(true);
                        comp     -= SpectatorID;
                    }
                    else if (IsSlotInQueue(slot))
                    {
                        origin.Y -= Distances.LOBBY_QUEUE_OFFSET;
                        comp     -= QueueID;
                    }
                    origin.Y += Distances.LOBBY_SPECTATOR_SLOT_DISTANCE * comp;
                }

                UpdateScreen();
                DirectBitmap identity = Capture.Clone(origin.X, origin.Y, width, height);

                if (slot == 5 && OpenChatIsDefault)
                {
                    Chat.OpenChat();
                }

                return(new SlotIdentity(identity, slot));
            }
        }
Exemplo n.º 14
0
        /// <summary>
        /// Toggles what heroes can be selected.
        /// </summary>
        /// <param name="ta">Determines if all heroes should be enabled, disabled or neither before toggling</param>
        /// <param name="team">Team to change roster for.</param>
        /// <param name="heroes">Heroes to toggle.</param>
        /// <example>
        /// The example below will enable random heroes for a team.
        /// <code>
        /// using System;
        /// using System.Collections.Generic;
        /// using System.Linq;
        /// using Deltin.CustomGameAutomation;
        ///
        /// public class SetHeroRosterExample
        /// {
        ///     public static void ChooseRandomHeroes(CustomGame cg, BotTeam team, int randomHeroCount)
        ///     {
        ///         Random rnd = new Random();
        ///         int heroCount = Enum.GetNames(typeof(MyEnum)).Length - 1;
        ///
        ///         List&lt;Hero&gt; chooseHeroes = new List&lt;Hero&gt;();
        ///         while (chooseHeroes.Count &lt; randomHeroCount)
        ///         {
        ///             int heroID = rnd.Next(heroCount);
        ///             if (chooseHeroes.Select(v => v as int).Contains(heroID))
        ///                 continue;
        ///             chooseHeroes.Add(heroID as Hero);
        ///         }
        ///
        ///         cg.SetHeroRoster(ToggleAction.DisableAll, team, chooseHeroes.ToArray());
        ///     }
        /// }
        /// </code>
        /// </example>
        public void SetHeroRoster(ToggleAction ta, BotTeam team, params Hero[] heroes)
        {
            GoToSettings();
            LeftClick(Points.SETTINGS_HEROES);        // click heroes
            LeftClick(Points.SETTINGS_HEROES_ROSTER); // click hero roster
            // If team doesn't equal both, click a team to change hero roster for.
            if (team == BotTeam.Blue)
            {
                LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_DROPDOWN, 250);
                LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_BLUE, 250);
            }
            if (team == BotTeam.Red)
            {
                LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_DROPDOWN, 250);
                LeftClick(Points.SETTINGS_HEROES_ROSTER_TEAM_RED, 250);
            }
            // If the toggle action is disable all, disable all heroes before toggling.
            if (ta == ToggleAction.DisableAll)
            {
                LeftClick(Points.SETTINGS_HEROES_ROSTER_DISABLE_ALL, 250);
            }
            // If the toggle action is enable all, enable all heroes before toggling.
            else if (ta == ToggleAction.EnableAll)
            {
                LeftClick(Points.SETTINGS_HEROES_ROSTER_ENABLE_ALL, 250);
            }

            if (OpenChatIsDefault)
            {
                Chat.CloseChat();
            }

            KeyPress(Keys.Down);
            Thread.Sleep(1);
            if (team == BotTeam.Both)
            {
                KeyPress(Keys.Down);
                Thread.Sleep(1);
            }

            // For each hero
            for (int i = 0; i < Enum.GetNames(typeof(Hero)).Length; i++)
            {
                // Toggle hero if current hero selected is set in the heroes array.
                for (int hi = 0; hi < heroes.Length; hi++)
                {
                    if ((int)heroes[hi] == i)
                    {
                        KeyPress(Keys.Space);
                        Thread.Sleep(1);
                    }
                }
                KeyPress(Keys.Down);
                Thread.Sleep(1);
            }

            GoBack(3, 0);

            if (OpenChatIsDefault)
            {
                Chat.OpenChat();
            }
        }
Exemplo n.º 15
0
        /// <summary>
        /// Gets the slots that are invited.
        /// </summary>
        /// <returns>The list of slots invited.</returns>
        public List <int> GetInvitedSlots()
        {
            using (LockHandler.Interactive)
            {
                // Get all non-AI players
                List <int> players = GetSlots(SlotFlags.Blue | SlotFlags.Red | SlotFlags.Spectators | SlotFlags.Queue);

                // Close the chat if it is opened
                if (OpenChatIsDefault && players.Contains(5))
                {
                    Chat.CloseChat();
                }

                List <InviteScanData> slotData = new List <InviteScanData>();

                Stopwatch sw = new Stopwatch();
                sw.Start();

                double iterations = 0;

                while (sw.ElapsedMilliseconds <= InviteScanData.MSToScan)
                {
                    UpdateScreen();
                    foreach (int slot in players)
                    {
                        // Get the data relating to the slot.
                        InviteScanData previousSlotData = slotData.FirstOrDefault(v => v.Slot == slot);

                        // Copy a 20x20 (10x10 if spectator) pixel square of the invite icon animation.
                        Point        scanAt = AddToSlotOrigin(IsSlotBlueOrRed(slot) ? InviteScanData.Origin : InviteScanData.SpectatorOrigin, slot, true);
                        int          range  = IsSlotBlueOrRed(slot) ? InviteScanData.PlayerRange : InviteScanData.SpectatorRange;
                        DirectBitmap markup = Capture.Clone(scanAt.X - range, scanAt.Y - range, range * 2, range * 2);

                        // If there is no previous record of the animation for the slot, create it.
                        if (previousSlotData == null)
                        {
                            slotData.Add(new InviteScanData(slot, markup));
                        }
                        else
                        {
                            // If there is, compare it to the previous one.

                            bool matching = previousSlotData.Markup.CompareTo(markup, InviteScanData.MarkupFade, InviteScanData.MarkupDifference, DBCompareFlags.Multithread);

                            previousSlotData.Markup.Dispose();
                            previousSlotData.Markup = markup;

                            if (!matching)
                            {
                                previousSlotData.Changes++;
                            }
                        }
                    }

                    iterations++;
                    Thread.Sleep(20);
                }

                for (int i = 0; i < slotData.Count; i++)
                {
                    slotData[i].Markup.Dispose();
                }

                if (OpenChatIsDefault && players.Contains(5))
                {
                    Chat.OpenChat();
                }

                return(slotData.Where(slot => slot.Changes / iterations * 100 >
                                      (IsSlotBlueOrRed(slot.Slot) ? InviteScanData.Player_MarkInvitedWithPercentageChanged : InviteScanData.Spectator_MarkInvitedWithPercentageChanged))
                       .Select(slot => slot.Slot).ToList());
            }
        }