示例#1
0
        public void Scan()
        {
            HtmlAgilityPack.HtmlDocument doc  = new HtmlAgilityPack.HtmlDocument();
            HtmlAgilityPack.HtmlDocument egov = new HtmlAgilityPack.HtmlDocument();

            using (WebClient wc = new WebClient())
            {
                doc.LoadHtml(wc.DownloadString("http://www.erepublik.com/en/citizen/profile/" + ID));
                egov.LoadHtml(wc.DownloadString("http://www.egov4you.info/citizen/overview/" + ID));
            }

            Citizen OldStatistics = (Citizen)this.MemberwiseClone();

            OldStatistics.Medals = Medals.Clone(); // Needed!!!

            Name            = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'citizen_profile_header')]/h2").InnerText.Trim();
            Strength        = (int)Convert.ToDecimal(doc.DocumentNode.SelectSingleNode("//*[@class='citizen_military'][1]/h4").InnerText.Trim(), GameInfo.Culture);
            Rank            = doc.DocumentNode.SelectSingleNode("//*[@class='citizen_military'][2]/h4/a").InnerHtml;
            RankPoints      = Convert.ToDouble(doc.DocumentNode.SelectSingleNode("//div[@class='citizen_military'][2]/div/small[@style]").InnerText.Split('/')[0].RemoveNonDigits(), GameInfo.Culture);
            Level           = Convert.ToInt16(doc.DocumentNode.SelectSingleNode("//strong[@class='citizen_level']").InnerText);
            Experience      = Convert.ToInt32(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_experience']/div/p").InnerText.Split('/')[0].RemoveNonDigits());
            NationalRank    = Convert.ToInt16(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_second']/small[3]/strong").InnerText);
            Friends         = Convert.ToInt16(doc.DocumentNode.SelectSingleNode("//div[@class='citizen_activity']/h4[@class='friends_title']").InnerText.Split('(')[1].Split(')')[0]);
            FirstFriendName = doc.DocumentNode.SelectSingleNode("//div[@class='citizen_activity']/ul/li/a").Attributes["title"].Value;
            Citizenship     = doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_info']/a[3]").InnerText.Trim();
            BirthDay        = new CitizenBirthDay(Convert.ToDateTime(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_second']/p[2]").InnerText.Trim(), GameInfo.Culture));

            #region Avatar
            AvatarLink = doc.DocumentNode.SelectSingleNode("//div[contains(@class, 'citizen_profile_header')]/img").Attributes["style"].Value;
            AvatarLink = AvatarLink.Substring(AvatarLink.IndexOf('(') + 1);
            AvatarLink = AvatarLink.Substring(0, AvatarLink.Length - 2);
            AvatarLink = AvatarLink.Replace("_142x142", "");
            #endregion
            #region Residence
            Residence = new CitizenResidence(
                doc.DocumentNode.SelectSingleNode("//div[@class='citizen_info']/a[1]").InnerText.Trim(),
                doc.DocumentNode.SelectSingleNode("//div[@class='citizen_info']/a[2]").InnerText.Trim());
            #endregion
            #region PoliticalParty
            try
            {
                PoliticalParty = new CitizenGroup(
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][1]/div/span/a").InnerText.Trim(),
                    Convert.ToInt32(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][1]/div/span/a").Attributes["href"].Value.Split('/')[3].Reverse().Split('-')[0].Reverse()),
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][1]/h3").InnerText.Trim(), -1);

                HtmlAgilityPack.HtmlDocument docParty = new HtmlAgilityPack.HtmlDocument();
                docParty.LoadHtml(new WebClient().DownloadString("http://www.erepublik.com/en/party/" + PoliticalParty.ID));

                PoliticalParty.Members = Convert.ToInt16(docParty.DocumentNode.SelectSingleNode("//div[@class='indent']/div[@class='infoholder']/p/span[2]").InnerText.Split(' ')[0]);

                if (PoliticalParty.Position == "Vice President")
                {
                    PoliticalParty.Position = "Vice Party President";
                }
            }
            catch
            { PoliticalParty = new CitizenGroup("N/A", -1, "N/A", -1); }
            #endregion
            #region MilitaryUnit
            try
            {
                MilitaryUnit = new CitizenGroup(
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][2]/div/a/span").InnerText.Trim(),
                    Convert.ToInt32(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][2]/div/a").Attributes["href"].Value.Split('/')[4]),
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][2]/h3").InnerText.Trim(), -1);

                HtmlAgilityPack.HtmlDocument docMu = new HtmlAgilityPack.HtmlDocument();
                docMu.LoadHtml(new WebClient().DownloadString("http://www.erepublik.com/en/main/group-list/members/" + MilitaryUnit.ID));

                MilitaryUnit.Members = Convert.ToInt16(docMu.DocumentNode.SelectSingleNode("//div[@class='header_content']/h2/big").InnerText.Split(' ')[0]);
            }
            catch
            { MilitaryUnit = new CitizenGroup("N/A", -1, "N/A", -1); }
            #endregion
            #region Newspaper
            try
            {
                Newspaper = new CitizenGroup(
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][3]/div/a/span").InnerText.Trim(),
                    Convert.ToInt32(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][3]/div/a").Attributes["href"].Value.Split('/')[3].Reverse().Split('-')[0].Reverse()),
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_activity']/div[@class='place'][3]/h3").InnerText.Trim(), -1);

                //HtmlAgilityPack.HtmlDocument docNews = new HtmlAgilityPack.HtmlDocument();
                //docNews.LoadHtml(new WebClient().DownloadString("http://www.erepublik.com/en/newspaper/" + Newspaper.ID));

                //Newspaper.Members = Convert.ToInt16(docNews.DocumentNode.SelectSingleNode("//div[@class='header_content']/h2/big").InnerText.Split(' ')[0]);
            }
            catch
            { Newspaper = new CitizenGroup("N/A", -1, "N/A", -1); }
            #endregion
            #region TruePatriotDamage
            try
            {
                TruePatriotDamage = new CitizenDamage(
                    Convert.ToInt64(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_military'][3]/h4").InnerText.RemoveNonDigits()),
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_military'][3]/h4/img").Attributes["alt"].Value);
            }
            catch
            {
                TruePatriotDamage = new CitizenDamage(0, "None");
            }
            #endregion
            #region TopCampaignDamage
            try
            {
                TopCampaignDamage = new CitizenDamage(
                    Convert.ToInt64(doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_military'][4]/h4").InnerText.RemoveNonDigits()),
                    doc.DocumentNode.SelectSingleNode(".//div[@class='citizen_military'][4]/h4/img").Attributes["alt"].Value);
            }
            catch
            {
                TopCampaignDamage = new CitizenDamage(0, "None");
            }
            #endregion
            #region MonthlyDamage
            if (egov.DocumentNode.SelectSingleNode("//*[@id='eContainer']/section[4]/table/tr/td[2]/table[1]/tbody/tr/td") != null)
            {
                MonthlyDamage = Convert.ToInt64(egov.DocumentNode.SelectSingleNode("//*[@id='eContainer']/section[4]/table/tr/td[2]/table[1]/tbody/tr/td").InnerText.Trim().Replace(",", ""));
            }
            else
            {
                MonthlyDamage = 0;
            }
            #endregion
            #region BombsUsed
            try
            {
                BombsUsed = new CitizenBombsUsed(
                    Convert.ToInt16(doc.DocumentNode.SelectSingleNode("//div[@class='citizen_mass_destruction']/strong[1]/b").InnerText),
                    Convert.ToInt16(doc.DocumentNode.SelectSingleNode("//div[@class='citizen_mass_destruction']/strong[2]/b").InnerText),
                    doc.DocumentNode.SelectSingleNode("//div[@class='citizen_mass_destruction']/em").ChildNodes[2].InnerText.Trim());
            }
            catch
            {
                BombsUsed = new CitizenBombsUsed(0, 0);
            }
            #endregion
            #region Decorations
            //try
            //{
            for (int i = 0; i < doc.DocumentNode.SelectNodes("//ul[@id='new_achievements']/li").Count; i++)
            {
                if (doc.DocumentNode.SelectSingleNode("//ul[@id='new_achievements']/li[" + (i + 1) + "]").Attributes["class"].Value != "unknown")
                {
                    Array.Resize(ref decoration, Decoration.Length + 1);
                    Decoration[i] = new Decoration(
                        doc.DocumentNode.SelectSingleNode("//ul[@id='new_achievements']/li[" + (i + 1) + "]/img").Attributes["src"].Value,
                        doc.DocumentNode.SelectSingleNode("//ul[@id='new_achievements']/li[" + (i + 1) + "]/div/span/p").InnerText.Trim());

                    if (doc.DocumentNode.SelectSingleNode("//ul[@id='new_achievements']/li[" + (i + 1) + "]/em") != null)
                    {
                        Decoration[i].Count = Convert.ToInt16(doc.DocumentNode.SelectSingleNode("//ul[@id='new_achievements']/li[" + (i + 1) + "]/em").InnerText);
                    }

                    //MessageBox.Show(
                    //    Decoration[i].ImageLink + Environment.NewLine +
                    //    Decoration[i].Text + Environment.NewLine +
                    //    Decoration[i].Count);
                }
            }
            //}
            //catch
            //{
            //}
            #endregion
            #region Medals
            string[] medalCodeNames = new string[]
            {
                "Freedom Fighter", "hard worker", "congressman", "president",
                "media mogul", "battle hero", "campaign hero", "resistance hero",
                "super soldier", "society builder", "mercenary", "Top Fighter",
                "true patriot",
            };

            for (int i = 0; i < medalCodeNames.Length; i++)
            {
                if (doc.DocumentNode.SelectSingleNode(".//ul[@id='achievment']/li[img[@alt='" + medalCodeNames[i] + "']]/div[@class='counter']") != null)
                {
                    Medals.Medal[i] = Convert.ToInt16(doc.DocumentNode.SelectSingleNode(".//ul[@id='achievment']/li[img[@alt='" + medalCodeNames[i] + "']]/div[@class='counter']").InnerText);
                }
            }
            #endregion
            #region WorldRankings
            try
            {
                WorldRanking = new CitizenRanking(
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[1]/td[2]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[1]/td[3]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[1]/td[4]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[1]/td[5]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[1]/td[6]").InnerText.RemoveNonDigits()));
            }
            catch
            {
                WorldRanking = new CitizenRanking(0, 0, 0, 0, 0);
            }
            #endregion
            #region CountryRankings
            try
            {
                CountryRanking = new CitizenRanking(
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[2]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[3]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[4]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[5]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[2]/td[6]").InnerText.RemoveNonDigits()));
            }
            catch
            {
                CountryRanking = new CitizenRanking(0, 0, 0, 0, 0);
            }
            #endregion
            #region UnitRankings
            try
            {
                UnitRanking = new CitizenRanking(
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[3]/td[2]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[3]/td[3]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[3]/td[4]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[3]/td[5]").InnerText.RemoveNonDigits()),
                    Convert.ToInt32(egov.DocumentNode.SelectSingleNode("//section[@id='eContainer']/section[4]/table/tr/td[1]/table[1]/tbody/tr/td/table/tbody/tr[3]/td[6]").InnerText.RemoveNonDigits()));
            }
            catch
            {
                UnitRanking = new CitizenRanking(0, 0, 0, 0, 0);
            }
            #endregion
            #region GuerillaScore
            GuerillaScore = new GuerillaScore(
                Convert.ToInt32(doc.DocumentNode.SelectSingleNode("//div[@class='guerilla_fights won']").InnerText),
                Convert.ToInt32(doc.DocumentNode.SelectSingleNode("//div[@class='guerilla_fights lost']").InnerText));
            #endregion

            Influence = (long)(RankPoints - OldStatistics.RankPoints) * 10;

            //if (OldStatistics.BombsUsed.Small < BombsUsed.Small)
            //    switch(Division)
            //    {
            //        case 1:
            //            Influence += 75000 * (BombsUsed.Small - OldStatistics.BombsUsed.Small);
            //            break;
            //        case 2:
            //            Influence += 375000 * (BombsUsed.Small - OldStatistics.BombsUsed.Small);
            //            break;
            //        case 3:
            //            Influence += 750000 * (BombsUsed.Small - OldStatistics.BombsUsed.Small);
            //            break;
            //        case 4:
            //            Influence += 1500000 * (BombsUsed.Small - OldStatistics.BombsUsed.Small);
            //            break;
            //    }

            //if (OldStatistics.BombsUsed.Big < BombsUsed.Big)
            //    Influence += (BombsUsed.Big - OldStatistics.BombsUsed.Big) * 5000000;

            StrengthGained   = Strength - OldStatistics.Strength;
            RankPointsGained = (int)(RankPoints - OldStatistics.RankPoints);
            ExperienceGained = Experience - OldStatistics.Experience;

            if (Rank != OldStatistics.Rank)
            {
                RankUp = OldStatistics.Rank + " → " + Rank;
            }
            else
            {
                RankUp = "";
            }

            if (Level != OldStatistics.Level)
            {
                LevelUp = OldStatistics.Level + " → " + Level;
            }
            else
            {
                LevelUp = "";
            }

            for (int i = 0; i < MedalsGained.Medal.Length; i++)
            {
                MedalsGained.Medal[i] = Medals.Medal[i] - OldStatistics.Medals.Medal[i];
            }

            if (ID == 2972052)
            {
                Name      = "Mlendea Horațiu";
                BirthDay  = new CitizenBirthDay(new DateTime(2011, 8, 21));
                Residence = new CitizenResidence("Romania", "Crisana");
            }
        }
示例#2
0
        public void Load(string path)
        {
            try
            {
                XmlDocument xml = new XmlDocument();
                xml.Load(path);

                XmlNode root = xml.SelectSingleNode("Citizen");

                //ID = Convert.ToInt32(root.SelectSingleNode("ID").InnerText);
                Name         = root.SelectSingleNode("Name").InnerText;
                Strength     = Convert.ToInt32(root.SelectSingleNode("Strength").InnerText);
                Rank         = root.SelectSingleNode("Rank").InnerText;
                RankPoints   = Convert.ToDouble(root.SelectSingleNode("RankPoints").InnerText);
                Influence    = Convert.ToInt32(root.SelectSingleNode("Influence").InnerText);
                Experience   = Convert.ToInt32(root.SelectSingleNode("Experience").InnerText);
                Level        = Convert.ToInt32(root.SelectSingleNode("Level").InnerText);
                NationalRank = Convert.ToInt32(root.SelectSingleNode("NationalRank").InnerText);
                Friends      = Convert.ToInt16(root.SelectSingleNode("Friends").InnerText);
                Citizenship  = root.SelectSingleNode("Citizenship").InnerText;
                BirthDay     = new CitizenBirthDay(Convert.ToDateTime(root.SelectSingleNode("BirthDay").InnerText, GameInfo.Culture));

                Residence = new CitizenResidence(
                    root.SelectSingleNode("Residence/Country").InnerText,
                    root.SelectSingleNode("Residence/Region").InnerText);

                PoliticalParty = new CitizenGroup(
                    root.SelectSingleNode("PoliticalParty/Name").InnerText,
                    Convert.ToInt32(root.SelectSingleNode("PoliticalParty/ID").InnerText),
                    root.SelectSingleNode("PoliticalParty/Position").InnerText,
                    Convert.ToInt32(root.SelectSingleNode("PoliticalParty/Members").InnerText));

                Newspaper = new CitizenGroup(
                    root.SelectSingleNode("Newspaper/Name").InnerText,
                    Convert.ToInt32(root.SelectSingleNode("Newspaper/ID").InnerText),
                    root.SelectSingleNode("Newspaper/Position").InnerText,
                    Convert.ToInt32(root.SelectSingleNode("Newspaper/Members").InnerText));

                MilitaryUnit = new CitizenGroup(
                    root.SelectSingleNode("MilitaryUnit/Name").InnerText,
                    Convert.ToInt32(root.SelectSingleNode("MilitaryUnit/ID").InnerText),
                    root.SelectSingleNode("MilitaryUnit/Position").InnerText,
                    Convert.ToInt32(root.SelectSingleNode("MilitaryUnit/Members").InnerText));

                TruePatriotDamage = new CitizenDamage(
                    Convert.ToInt64(root.SelectSingleNode("TruePatriotDamage/Damage").InnerText),
                    root.SelectSingleNode("TruePatriotDamage/Country").InnerText);

                TopCampaignDamage = new CitizenDamage(
                    Convert.ToInt64(root.SelectSingleNode("TopCampaignDamage/Damage").InnerText),
                    root.SelectSingleNode("TopCampaignDamage/Country").InnerText);

                BombsUsed = new CitizenBombsUsed(
                    Convert.ToInt32(root.SelectSingleNode("BombsUsed/Small").InnerText),
                    Convert.ToInt32(root.SelectSingleNode("BombsUsed/Big").InnerText));

                Medals.FreedomFighter   = Convert.ToInt16(root.SelectSingleNode("Medals/FreedomFighter").InnerText);
                Medals.HardWorker       = Convert.ToInt16(root.SelectSingleNode("Medals/HardWorker").InnerText);
                Medals.CongressMember   = Convert.ToInt16(root.SelectSingleNode("Medals/CongressMember").InnerText);
                Medals.CountryPresident = Convert.ToInt16(root.SelectSingleNode("Medals/CountryPresident").InnerText);
                Medals.MediaMogul       = Convert.ToInt16(root.SelectSingleNode("Medals/MediaMogul").InnerText);
                Medals.BattleHero       = Convert.ToInt16(root.SelectSingleNode("Medals/BattleHero").InnerText);
                Medals.CampaignHero     = Convert.ToInt16(root.SelectSingleNode("Medals/CampaignHero").InnerText);
                Medals.ResistanceHero   = Convert.ToInt16(root.SelectSingleNode("Medals/ResistanceHero").InnerText);
                Medals.SuperSoldier     = Convert.ToInt16(root.SelectSingleNode("Medals/SuperSoldier").InnerText);
                Medals.SocietyBuilder   = Convert.ToInt16(root.SelectSingleNode("Medals/SocietyBuilder").InnerText);
                Medals.Mercenary        = Convert.ToInt16(root.SelectSingleNode("Medals/Mercenary").InnerText);
                Medals.TopFighter       = Convert.ToInt16(root.SelectSingleNode("Medals/TopFighter").InnerText);
                Medals.TruePatriot      = Convert.ToInt16(root.SelectSingleNode("Medals/TruePatriot").InnerText);
            }
            catch// (Exception ex)
            {
                //Log.AppendText(DateTime.Now.ToString(LogDateFormat) + "Failed to load old data for " +ID + ", attempting to scan him" + Environment.NewLine);
                //MessageBox.Show(ID + " " + ex.ToString());
                Scan();
            }
        }