Exemplo n.º 1
0
 private void Pause()
 {
     CancelRun();
     _fishingState = FishingState.Paused;
     _mouth.Say(Translate.GetTranslate("frmMain", "LABEL_PAUSED"));
     _mManagerEventHandler.Paused();
 }
Exemplo n.º 2
0
        private void btnStart_Click(object sender, EventArgs e)
        {
            btnSettings.Enabled = false;
            btnStop.Enabled     = true;

            if (m_manager.GetActualState() == Manager.FishingState.Stopped)
            {
                m_manager.Start();
                btnStart.Text   = Translate.GetTranslate("frmMain", "BUTTON_PAUSE");
                lblStatus.Text  = Translate.GetTranslate("frmMain", "LABEL_STARTED");
                lblStatus.Image = Resources.online;
            }
            else if (m_manager.GetActualState() == Manager.FishingState.Paused)
            {
                m_manager.Resume();
                btnStart.Text   = Translate.GetTranslate("frmMain", "BUTTON_PAUSE");
                lblStatus.Text  = Translate.GetTranslate("frmMain", "LABEL_RESUMED");
                lblStatus.Image = Resources.online;
            }
            else
            {
                btnSettings.Enabled = true;
                m_manager.Pause();
                btnStart.Text   = Translate.GetTranslate("frmMain", "BUTTON_RESUME");
                lblStatus.Text  = Translate.GetTranslate("frmMain", "LABEL_PAUSED");
                lblStatus.Image = Resources.online;
            }
        }
Exemplo n.º 3
0
        private void CheckStatus()
        {
            lblWarn.Text   = Translate.GetTranslate("frmMain", "LABEL_CHECKING_STATUS");
            lblWarn.Parent = PictureBox1;

            try
            {
                Task.Factory.StartNew(() => (new WebClient()).DownloadString("http://www.fishbot.net/status.txt"),
                                      TaskCreationOptions.LongRunning).ContinueWith(x =>
                {
                    if (x.Result.ToLower().Trim() != "safe")
                    {
                        lblWarn.Text      = Translate.GetTranslate("frmMain", "LABEL_NO_LONGER_SAFE");
                        lblWarn.ForeColor = Color.Red;
                        lblWarn.BackColor = Color.Black;
                    }
                    else
                    {
                        lblWarn.Visible = false;
                    }
                }, TaskScheduler.FromCurrentSynchronizationContext());
            }
            catch (Exception ex)
            {
                lblWarn.Text = (Translate.GetTranslate("frmMain", "LABEL_COULD_NOT_CHECK_STATUS") + ex.ToString());
            }
        }
Exemplo n.º 4
0
 private void btnStop_Click(object sender, EventArgs e)
 {
     btnSettings.Enabled = true;
     btnStop.Enabled     = false;
     m_manager.Stop();
     btnStart.Text   = Translate.GetTranslate("frmMain", "BUTTON_START");
     lblStatus.Text  = Translate.GetTranslate("frmMain", "LABEL_STOPPED");
     lblStatus.Image = Resources.offline;
 }
Exemplo n.º 5
0
 public void Stop()
 {
     CancelRun();
     _fishingState = FishingState.Stopped;
     _mouth.Say(Translate.GetTranslate("frmMain", "LABEL_STOPPED"));
     _mManagerEventHandler.Stopped();
     _lureTimer.Enabled        = false;
     _raftTimer.Enabled        = false;
     _charmTimer.Enabled       = false;
     _baitTimer.Enabled        = false;
     _hearthStoneTimer.Enabled = false;
 }
Exemplo n.º 6
0
        private async Task RunBotUntilCanceled()
        {
            var wowWindowPointer = Win32.FindWowWindow(); // update window pointer in case wow started after fishbot or restarted.

            _eyes.SetWow(wowWindowPointer);
            _hands.SetWow(wowWindowPointer);
            ResetTimers();
            EnableTimers();
            _mouth.Say(Translate.GetTranslate("frmMain", "LABEL_STARTED"));
            _mManagerEventHandler.Started();
            await RunBot();
        }
Exemplo n.º 7
0
 private async void frmMain_Load(object sender, EventArgs e)
 {
     btnStart.Text      = Translate.GetTranslate("frmMain", "BUTTON_START");
     btnStop.Text       = Translate.GetTranslate("frmMain", "BUTTON_STOP");
     btnSettings.Text   = Translate.GetTranslate("frmMain", "BUTTON_SETTINGS");
     btnStatistics.Text = Translate.GetTranslate("frmMain", "BUTTON_STATISTICS");
     btnHowTo.Text      = Translate.GetTranslate("frmMain", "BUTTON_HTU");
     btnClose.Text      = Translate.GetTranslate("frmMain", "BUTTON_EXIT");
     btnAbout.Text      = Translate.GetTranslate("frmMain", "BUTTON_ABOUT");
     lblStatus.Text     = Translate.GetTranslate("frmMain", "LABEL_STOPPED");
     this.Text          = "UltimateFishBot - v " + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString();
     ReloadHotkeys();
     await CheckStatus();
 }
Exemplo n.º 8
0
        private async Task CheckStatus()
        {
            lblWarn.Text   = Translate.GetTranslate("frmMain", "LABEL_CHECKING_STATUS");
            lblWarn.Parent = PictureBox1;

            try
            {
                string result = await(new WebClient()).DownloadStringTaskAsync("http://www.fishbot.net/status.txt");
                if (result.ToLower().Trim() != "safe")
                {
                    lblWarn.Text      = Translate.GetTranslate("frmMain", "LABEL_NO_LONGER_SAFE");
                    lblWarn.ForeColor = Color.Red;
                    lblWarn.BackColor = Color.Black;
                }
                else
                {
                    lblWarn.Visible = false;
                }
            }
            catch (Exception ex)
            {
                lblWarn.Text = (Translate.GetTranslate("frmMain", "LABEL_COULD_NOT_CHECK_STATUS") + ex.ToString());
            }
        }
Exemplo n.º 9
0
 public void Paused()
 {
     btnSettings.Enabled = true;
     btnStart.Text       = Translate.GetTranslate("frmMain", "BUTTON_RESUME");
     lblStatus.Image     = Resources.online;
 }
Exemplo n.º 10
0
 public void Resumed()
 {
     ToggleButtonEnabledRunning();
     btnStart.Text   = Translate.GetTranslate("frmMain", "BUTTON_PAUSE");
     lblStatus.Image = Resources.online;
 }
Exemplo n.º 11
0
 public void Stopped()
 {
     ToggleButtonEnabledNotRunning();
     btnStart.Text   = Translate.GetTranslate("frmMain", "BUTTON_START");
     lblStatus.Image = Resources.offline;
 }
Exemplo n.º 12
0
        private async Task Fish(BotSession session, CancellationToken cancellationToken)
        {
            _mouth.Say(Translate.GetTranslate("manager", "LABEL_CASTING"));
            _eyes.UpdateBackground();
            await _hands.Cast(cancellationToken);

            _mouth.Say(Translate.GetTranslate("manager", "LABEL_FINDING"));
            // Make bobber found async, so can check fishing sound in parallel, the result only important when we hear fish.
            // The position used for repositioning.
            var eyeCancelTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            var eyeCancelToken       = eyeCancelTokenSource.Token;
            var eyeTask = Task.Run(async() => await _eyes.LookForBobber(session, eyeCancelToken), eyeCancelToken);

            // Update UI with wait status
            var uiUpdateCancelTokenSource = CancellationTokenSource.CreateLinkedTokenSource(cancellationToken);
            var uiUpdateCancelToken       = uiUpdateCancelTokenSource.Token;
            var progress = new Progress <long>(msecs =>
            {
                if (!uiUpdateCancelToken.IsCancellationRequested && !cancellationToken.IsCancellationRequested)
                {
                    _mouth.Say(Translate.GetTranslate(
                                   "manager",
                                   "LABEL_WAITING",
                                   msecs / Second,
                                   _aFishWait / Second));
                }
            });
            var uiUpdateTask = Task.Run(
                async() => await UpdateUiWhileWaitingToHearFish(progress, uiUpdateCancelToken),
                uiUpdateCancelToken);

            var rnd = new Random();

            _aFishWait = rnd.Next(Properties.Settings.Default.FishWaitLow, Properties.Settings.Default.FishWaitHigh);
            var fishHeard = await _ears.Listen(
                _aFishWait,
                cancellationToken);

            //Log.Information("Ear result: "+a_FishWait.ToString());

            uiUpdateCancelTokenSource.Cancel();
            try {
                uiUpdateTask.GetAwaiter().GetResult(); // Wait & Unwrap
                // https://github.com/StephenCleary/AsyncEx/blob/dc54d22b06566c76db23af06afcd0727cac625ef/Source/Nito.AsyncEx%20(NET45%2C%20Win8%2C%20WP8%2C%20WPA81)/Synchronous/TaskExtensions.cs#L18
            } catch (TaskCanceledException) {
            } finally {
                uiUpdateCancelTokenSource.Dispose();
            }

            if (!fishHeard)
            {
                _fishingStats.RecordNotHeard();
                _fishErrorLength++;
                return;
            }

            // We heard the fish, let's check bobbers position
            if (!eyeTask.IsCompleted)
            {
                // the search is not finished yet, but fish is heard, we have 2 seconds left to find and hook it
                eyeTask.Wait(2000, cancellationToken);
                eyeCancelTokenSource.Cancel();
            }
            eyeCancelTokenSource.Dispose();

            if (eyeTask.IsCompleted)
            {
                // search is ended what's the result?
                var bobberPos = eyeTask.Result;

                if (bobberPos != null && bobberPos.X != 0 && bobberPos.Y != 0)
                {
                    // bobber found
                    if (await _eyes.SetMouseToBobber(session, bobberPos, cancellationToken))
                    {
                        // bobber is still there
                        Log.Information("Bobber databl: ({bx},{by})", bobberPos.X, bobberPos.Y);
                        await _hands.Loot();

                        _mouth.Say(Translate.GetTranslate("manager", "LABEL_HEAR_FISH"));
                        _fishingStats.RecordSuccess();
                        _fishErrorLength = 0;
                        Log.Information("Fish success");
                        return;
                    }
                }
            }
            _fishingStats.RecordBobberNotFound();
            _fishErrorLength++;
        }
Exemplo n.º 13
0
 private async Task Resume()
 {
     _mouth.Say(Translate.GetTranslate("frmMain", "LABEL_RESUMED"));
     _mManagerEventHandler.Resumed();
     await RunBot();
 }