示例#1
0
        private void AttentionGameTimer_Tick(object sender, EventArgs e)
        {
            this.Invoke(new MethodInvoker(delegate()
            {
                HtmlDocument doc            = webBrowser1.Document;
                HtmlElementCollection elems = doc.GetElementsByTagName("center");
                int readyIdx    = -1;
                int completeIdx = -1;

                foreach (HtmlElement ele in elems)
                {
                    string str1 = ele.InnerHtml;
                    readyIdx    = str1.IndexOf("오늘은");
                    if (0 <= readyIdx)
                    {
                        break;
                    }

                    completeIdx = str1.IndexOf("마지막");
                    if (0 <= completeIdx)
                    {
                        break;
                    }
                }

                bool isSkipGame = false;
                if (-1 != completeIdx)
                {
                    AddLogMsg("이미 출석게임을 완료한 상태입니다.");
                    skipAttentionGame = false;
                    isSkipGame        = true;
                }
                else if ((-1 == readyIdx) && (-1 == completeIdx))
                {
                    ++tryCount;
                    if (10 <= tryCount)
                    {
                        isSkipGame = true;
                    }
                    else
                    {
                        return;
                    }
                }

                if (isSkipGame)
                {
                    tryCount = 0;
                    webBrowser1.DocumentCompleted += this.PlayTypingGame;
                    webBrowser1.Navigate(EditAddress.Text + "/tazza/");
                    AttentionGameTimer.Stop();
                    return;
                }

                tryCount = 0;

                int dalInCount = 0;
                foreach (HtmlElement ele in doc.All)
                {
                    if (null == ele.InnerText)
                    {
                        continue;
                    }

                    if ((ele.GetAttribute("className") == "tbl_type") && (0 <= ele.InnerText.IndexOf("내 기록")))
                    {
                        string text = ele.InnerText;
                        Match m     = Regex.Match(text, @"[0-9]+회");
                        if (m.Success)
                        {
                            dalInCount = int.Parse(m.Value.Replace("회", ""));
                        }
                        else
                        {
                            dalInCount = 0;
                        }

                        attentionGameTotal = dalInCount;
                        for (m = m.NextMatch(); m.Success; m = m.NextMatch())
                        {
                            attentionGameTotal += int.Parse(m.Value.Replace("회", ""));
                        }

                        break;
                    }
                }

                AddLogMsg("달인 / 총 횟수 = " + dalInCount + " / " + attentionGameTotal);
                int goal = ((dalInCount * 100 / Math.Max(attentionGameTotal, 1)) < 25) ? 1 : 100;
                if (1 == goal)
                {
                    AddLogMsg("달인(1)을 노립니다.");
                }
                else
                {
                    AddLogMsg("능력자(100)를 노립니다.");
                }

                webBrowser1.DocumentCompleted += this.PlayTypingGame;
                webBrowser1.Navigate(js.GetAttentionGameScript(goal));
                AttentionGameTimer.Stop();
            }));
        }