Example #1
0
        /// <summary>
        /// Clicks a UI Element after a random interval.
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static bool SafeClick(UIElement uiElement, ClickDelay delayOption, string name = "", int postClickThreadSleepDuration = 0, bool fireWorldTransferStart = false)
        {
            try
            {
                if (DateTime.UtcNow.Subtract(_lastClick).TotalMilliseconds < 500)
                {
                    return(false);
                }

                if (ElementIsVisible(uiElement, name))
                {
                    if (!string.IsNullOrEmpty(name))
                    {
                        Log.Debug("{0} button is visible", name);
                    }
                    else
                    {
                        Log.Debug("{0}={1} is visible", uiElement.Hash, uiElement.Name);
                    }

                    if (!clickTimer.IsRunning && delayOption == ClickDelay.Delay)
                    {
                        clickTimer.Start();
                        SetClickTimerRandomVal();
                    }
                    else if ((ClickTimerRandomReady() && ElementIsVisible(uiElement, name)) || delayOption == ClickDelay.NoDelay)
                    {
                        if (!string.IsNullOrEmpty(name))
                        {
                            Log.Info("Clicking {0} button", name);
                        }
                        else
                        {
                            Log.Info("Clicking {0}={1}", uiElement.Hash, uiElement.Name);
                        }

                        // sleep plugins for a bit
                        if (ZetaDia.IsInGame && fireWorldTransferStart)
                        {
                            GameEvents.FireWorldTransferStart();
                        }

                        _lastClick = DateTime.UtcNow;
                        uiElement.Click();
                        BotMain.PauseFor(TimeSpan.FromMilliseconds(ClickThreadSleepInterval));

                        if (postClickThreadSleepDuration > 0)
                        {
                            BotMain.PauseFor(TimeSpan.FromMilliseconds(postClickThreadSleepDuration));
                        }

                        clickTimer.Reset();
                    }
                    else
                    {
                        Log.Debug("Pausing bot, waiting for {0}={1}", uiElement.Hash, uiElement.Name);
                        BotMain.PauseWhile(ClickTimerRandomNotReady, 0, ClickTimerTimeout);
                    }
                }
                return(true);
            }
            catch (Exception ex)
            {
                Log.Info("Error clicking UI button {0}: " + ex, name);
                return(false);
            }
        }
Example #2
0
        /// <summary>
        /// Clicks a UI Element after a random interval. 
        /// </summary>
        /// <param name="uiElement"></param>
        /// <param name="name"></param>
        /// <returns></returns>
        internal static bool SafeClick(UIElement uiElement, ClickDelay delayOption, string name = "", int postClickThreadSleepDuration = 0, bool fireWorldTransferStart = false)
        {
            try
            {
                if (DateTime.UtcNow.Subtract(_lastClick).TotalMilliseconds < 500)
                    return false;

                if (ElementIsVisible(uiElement, name))
                {
                    if (!String.IsNullOrEmpty(name))
                    {
                        Logr.Debug("{0} button is visible", name);
                    }
                    else
                    {
                        Logr.Debug("{0}={1} is visible", uiElement.Hash, uiElement.Name);
                    }

                    if (!clickTimer.IsRunning && delayOption == ClickDelay.Delay)
                    {
                        clickTimer.Start();
                        SetClickTimerRandomVal();
                    }
                    else if ((ClickTimerRandomReady() && ElementIsVisible(uiElement, name)) || delayOption == ClickDelay.NoDelay)
                    {
                        if (!String.IsNullOrEmpty(name))
                        {
                            Logr.Log("Clicking {0} button", name);
                        }
                        else
                        {
                            Logr.Log("Clicking {0}={1}", uiElement.Hash, uiElement.Name);
                        }

                        // sleep plugins for a bit
                        if (ZetaDia.IsInGame && fireWorldTransferStart)
                            GameEvents.FireWorldTransferStart();

                        _lastClick = DateTime.UtcNow;
                        uiElement.Click();
                        //BotMain.PauseFor(TimeSpan.FromMilliseconds(ClickThreadSleepInterval));

                        //if (postClickThreadSleepDuration > 0)
                        //    BotMain.PauseFor(TimeSpan.FromMilliseconds(postClickThreadSleepDuration));

                        clickTimer.Reset();
                    }
                    else
                    {
                        Logr.Debug("Pausing bot, waiting for {0}={1}", uiElement.Hash, uiElement.Name);
                        BotMain.PauseWhile(ClickTimerRandomNotReady, 0, ClickTimerTimeout);
                    }
                }
                return true;
            }
            catch (Exception ex)
            {
                Logr.Log("Error clicking UI button {0}: " + ex.ToString(), name);
                return false;
            }
        }