Example #1
0
        public void doFetchHeroAdventures(object o)
        {
            lock (Level2Lock)
            {
                int    VillageID = (int)o;
                string data      = PageQuery(VillageID, "hero_inventory.php");  //	查询英雄状态

                if (string.IsNullOrEmpty(data))
                {
                    return;
                }

                string hero_status = HtmlUtility.GetElementWithClass(
                    data, "div", "attribute heroStatus");
                if (string.IsNullOrEmpty(hero_status))
                {
                    return;
                }
                Match m        = Regex.Match(hero_status, "karte.php\\?d=(\\d+)");
                int   hero_loc = 0;
                if (m.Success)
                {
                    int z = Convert.ToInt32(m.Groups[1].Value);
                    foreach (var x in TD.Villages)
                    {
                        TVillage v = x.Value;
                        if (v.Z == z)
                        {
                            hero_loc = x.Key;
                            TD.Adv_Sta.HeroLocate = hero_loc;
                            break;
                        }
                    }
                }
                else
                {
                    hero_loc = (TD.Adv_Sta.HeroLocate == 0 ? VillageID : TD.Adv_Sta.HeroLocate);
                }

                data = PageQuery(hero_loc, "hero_adventure.php");       //	查询探险地点
                if (string.IsNullOrEmpty(data))
                {
                    return;
                }
                string[] places = HtmlUtility.GetElements(data, "tr");
                if (places.Length <= 1)
                {
                    return;
                }

                int      coord_x, coord_y;
                string   dur, dgr, lnk;
                DateTime fin;
                TD.Adv_Sta.HeroAdventures.Clear();
                for (int i = 1; i < places.Length; i++)
                {
                    //	坐标
                    string coords = HtmlUtility.GetElementWithClass(
                        places[i], "td", "coords");
                    if (coords == null)
                    {
                        continue;
                    }
                    m = Regex.Match(coords, "karte.php\\?x=(\\-?\\d+)&amp;y=(\\-?\\d+)");
                    if (!m.Success)
                    {
                        continue;
                    }
                    coord_x = Convert.ToInt32(m.Groups[1].Value);
                    coord_y = Convert.ToInt32(m.Groups[2].Value);

                    //	持续时间
                    string move_time = HtmlUtility.GetElementWithClass(
                        places[i], "td", "moveTime");
                    if (move_time == null)
                    {
                        continue;
                    }
                    m = Regex.Match(move_time, "\\d+:\\d+:\\d+");
                    if (!m.Success)
                    {
                        continue;
                    }
                    dur = m.Groups[0].Value;

                    //	难度
                    string difficulty = HtmlUtility.GetElementWithClass(
                        places[i], "td", "difficulty");
                    if (difficulty == null)
                    {
                        continue;
                    }
                    m = Regex.Match(difficulty, "alt=\"([^\"]*?)\"");
                    if (!m.Success)
                    {
                        continue;
                    }
                    dgr = m.Groups[1].Value;

                    //	难度
                    string timeLeft = HtmlUtility.GetElementWithClass(
                        places[i], "td", "timeLeft");
                    if (timeLeft == null)
                    {
                        continue;
                    }
                    m = Regex.Match(timeLeft, "\\d+:\\d+:\\d+");
                    if (!m.Success)
                    {
                        continue;
                    }
                    fin = DateTime.Now.Add(TimeSpanParse(m.Groups[0].Value));

                    //	链接
                    string goTo = HtmlUtility.GetElementWithClass(
                        places[i], "td", "goTo");
                    if (goTo == null)
                    {
                        continue;
                    }
                    m = Regex.Match(goTo, "href=\"([^\"]*?)\"");
                    if (!m.Success)
                    {
                        continue;
                    }
                    lnk = m.Groups[1].Value;

                    //	增加新的探险地点
                    HeroAdventureInfo adv_info = new HeroAdventureInfo()
                    {
                        axis_x      = coord_x,
                        axis_y      = coord_y,
                        duration    = dur,
                        danger      = dgr,
                        finish_time = fin,
                        link        = lnk
                    };
                    TD.Adv_Sta.HeroAdventures.Add(adv_info);
                }

                TD.Adv_Sta.bIsHeroAdventureInitialize     = true;
                TD.Adv_Sta.bShouldRefreshAdventureDisplay = true;
                TD.Dirty = true;
            }
        }
Example #2
0
        private int PMParse(string data)
        {
            string strPMTitles = HtmlUtility.GetElement(data, "tbody");

            if (strPMTitles == null)
            {
                return(-1);
            }
            string[] strPMTitleList = HtmlUtility.GetElements(strPMTitles, "tr");
            int      len            = strPMTitleList.Length;
            int      cnt            = 0;

            foreach (string eachPMTitle in strPMTitleList)
            {
                Match m = Regex.Match(
                    eachPMTitle, "class=\"status \" title=\"unread\" alt=\"unread\" />");
                if (!m.Success)
                {
                    continue;
                }

                m = Regex.Match(
                    eachPMTitle, "<a href=\"spieler\\.php\\?uid=(\\d+)\">([^<]*?)</a>");
                if (!m.Success)
                {
                    continue;
                }
                int    uid  = Convert.ToInt32(m.Groups[1].Value);
                string name = m.Groups[2].Value;
                if (!DicPMSender.ContainsKey(uid))
                {
                    PMSender sender = new PMSender
                    {
                        _uid  = uid,
                        _name = name
                    };
                    DicPMSender.Add(uid, sender);
                }

                m = Regex.Match(
                    eachPMTitle, "<a href=\"(nachrichten\\.php\\?id=\\d+)\">([^<]*?)</a>");
                if (!m.Success)
                {
                    continue;
                }
                string link    = m.Groups[1].Value;
                string subject = m.Groups[2].Value.Trim();

                m = Regex.Match(
                    eachPMTitle, "<td class=\"dat\">([^<]*?)</td>");
                if (!m.Success)
                {
                    continue;
                }
                string date = m.Groups[1].Value;

                PMInfo info = new PMInfo
                {
                    _subject = subject,
                    _date    = date
                };

                string content = UpCall.PageQuery(VillageID, link);
                m = Regex.Match(content, @"<div id=""message"">(.+?)</div>", RegexOptions.Singleline);
                if (!m.Success)
                {
                    continue;
                }
                info._content = m.Groups[1].Value;
                DicPMSender[uid].PMInfoList.Add(info);
                cnt++;
            }

            if (cnt > 0 && cnt == len)
            {
                return(1);
            }
            else if (cnt > 0 && cnt < len)
            {
                return(0);
            }
            else
            {
                return(-1);
            }
        }