예제 #1
0
        private bool IsAttackType(TTInfo troop, string attType)
        {
            if (troop.TroopType != TTroopType.Incoming)
                return false;

            var CV = UpCall.TD.Villages[VillageID];
            int index = troop.VillageName.IndexOf(CV.Name);
            if (index > 0 && dl.Tags.ContainsKey(attType))
            {
                return troop.VillageName.Remove(index, CV.Name.Length).Contains(dl.Tags[attType]);
            }

            return false;
        }
예제 #2
0
        private void AddAtacker(TTInfo troop)
        {
            if (!IsAttack(troop) && !IsRaid(troop))
                return;

            if (!attackers.ContainsKey(troop.OwnerVillageZ))
            {
                TAttacker att = ParseAttacker(troop);
                if (att != null)
                    attackers.Add(troop.OwnerVillageZ, att);
                else
                    return;
            }

            if (IsTrustful(attackers[troop.OwnerVillageZ].Name))
            {
                return;
            }

            attackers[troop.OwnerVillageZ].troops.Add(troop);
            if (LatestIncoming == null || troop.FinishTime < LatestIncoming.FinishTime)
                LatestIncoming = troop;
        }
예제 #3
0
 private bool IsAttack(TTInfo troop)
 {
     return IsAttackType(troop, "attack");
 }
예제 #4
0
        TAttacker ParseAttacker(TTInfo troop)
        {
            string data = UpCall.PageQuery(VillageID, troop.OwnerVillageUrl, null, true, true);
            if (string.IsNullOrEmpty(data))
                return null;

            string name = "", ally = "";
            int uid = 0, popu = 0;

            string pattern = "allianz\\.php\\?aid=\\d+\">(.*?)</a></td>"+
                "[^<]*?</tr>[^<]*?<tr>[^<]*?<th>[^<]*?</th>[^<]*?<td><a href=\"spieler\\.php\\?uid=(\\d+)\">(.*?)</a></td>"+
                "[^<]*?</tr>[^<]*?<tr>[^<]*?<th>[^<]*?</th>[^<]*?<td>(\\d+)</td>";
            Regex reg = new Regex(pattern);
            Match m = reg.Match(data);
            if (m.Success)
            {
                ally = m.Groups[1].Value;
                uid = int.Parse(m.Groups[2].Value);
                name = m.Groups[3].Value;
                popu = int.Parse(m.Groups[4].Value);
            }
            else
                return null;

            TPoint point = new TPoint();
            point.Z = troop.OwnerVillageZ;
            TAttacker attacker = new TAttacker
            {
                Point = point,
                Tribe = troop.Tribe,
                troops = new List<TTInfo>(),
                VileageName = troop.Owner,
                Ally = ally,
                Name = name,
                Uid = uid,
                Population = popu,
            };
            return attacker;
        }
예제 #5
0
        private void button1_Click(object sender, EventArgs e)
        {
            //	解析攻击目标的坐标
            if (this.txtX.Text == "" && this.txtY.Text == "" && this.textCoord.Text == "")
                return;
            else if(this.txtX.Text != "" || this.txtY.Text != "")
            {
                //	单目标情况
                int x = 0, y = 0;
                Int32.TryParse(this.txtX.Text, out x);
                Int32.TryParse(this.txtY.Text, out y);
                var aTargets = new TPoint(x, y);
                iTargets.Add(aTargets);
            }
            else
            {
                //	多目标情况,格式:"xxx|yyy,xxx|yyy"
                if (!this.textCoord.Text.Contains(","))
                    return;
                string[] multipletargets = this.textCoord.Text.Split(',');
                for (int i = 0; i < multipletargets.Length; i++)
                {
                    if (!multipletargets[i].Contains("|"))
                        continue;
                    string[] id = multipletargets[i].Split('|');
                    int x1 = 0, y1 = 0;
                    Int32.TryParse(id[0], out x1);
                    Int32.TryParse(id[1], out y1);
                    TPoint tid = new TPoint(x1, y1);
                    if (!tid.IsEmpty)
                    iTargets.Add(tid);
                }
            }

            //	检查部队设置的数量是否超过现有的数量
            for (int i = 0; i < 11; i++)
            {
                int totalattack = Convert.ToInt32(this.numericUpDown1.Value) * iTargets.Count;
                int[] totalraidtroops = new int[11];
                int totaltroops = 0;
                int[] raidtroops = new int[11];
                for (int j = 0; j < 5; j++)
                {
                    int wv = Convert.ToInt32(Waves[j].Value);
                    raidtroops[i] = Convert.ToInt32(Nums[j, i].Value);
                    totaltroops = totaltroops + (raidtroops[i] * wv);
                }
                totalraidtroops[i] = totaltroops;
                if (totalraidtroops[i] * totalattack > Troops[i])
                {
                    var Nt = MessageBox.Show("No Enough Troop");
                    return;
                }
            }

            for (int j = 0; j < 5; j++)
            {
                int wv = Convert.ToInt32(Waves[j].Value);
                int[] raidtroops = new int[11];
                int totaltroops = 0;
                for (int i = 0; i < 11; i++)
                {
                    raidtroops[i] = Convert.ToInt32(Nums[j, i].Value);
                    totaltroops = totaltroops + raidtroops[i];
                }

                if (wv != 0 && totaltroops != 0)
                {
                    TTInfo mTargets = new TTInfo
                    {
                        Troops = raidtroops
                    };
                    nWaves.Add(wv);
                    nTargets.Add(mTargets);
                }
            }

            if (nWaves.Count == 0 || nTargets.Count == 0 || iTargets.Count == 0)
            {
                if (!this.checkBox2.Checked)
                    return;
            }

            Return = new AttackQueue
            {
                Raidtype = this.checkBox2.Checked ? 1 : this.comboBox3.SelectedIndex + 2,
                Targets = iTargets,
                wTroops = nTargets,
                wWaves = nWaves,
                VillageID = VillageID,
                kata = this.comboBox1.SelectedIndex,
                kata2 = this.comboBox2.SelectedIndex,
                Settlers = this.checkBox2.Checked,
                MinimumInterval = minimumInterval,
                NextExec = actionAt,
            };
        }
예제 #6
0
 bool IsAttack(TTInfo troop)
 {
     return(IsAttackType(troop, "attack"));
 }
예제 #7
0
        bool IsAttackType(TTInfo troop, string attType)
        {
            if (troop.TroopType != TTroopType.Incoming)
                return false;

            bool result = false;
            var CV = UpCall.TD.Villages[VillageID];
            int index = troop.VillageName.IndexOf(CV.Name);

            if (index > 0)
            {
                string test_str = troop.VillageName.Remove(index, CV.Name.Length);
                if (attType == "attack")
                {
                    foreach (string atk_lang in dl.AtkLang)
                    {
                        if (test_str.Contains(atk_lang))
                        {
                            result = true;
                            break;
                        }
                    }
                }
                else if (attType == "raid")
                {
                    foreach (string raid_lang in dl.RaidLang)
                    {
                        if (test_str.Contains(raid_lang))
                        {
                            result = true;
                            break;
                        }
                    }
                }
            }

            return result;
        }
예제 #8
0
        private void DoEvade()
        {
            string sendTroopsUrl = String.Format("build.php?id=39&tt=2&z={0}", tpEvadePoint.Z);
            string sendTroopForm = UpCall.PageQuery(VillageID, sendTroopsUrl);
            if (sendTroopForm == null
               || !sendTroopForm.Contains("<form method=\"POST\" name=\"snd\" action=\"build.php?id=39&tt=2\">"))
            {
                MinimumDelay = 0;
                return;
            }

            Dictionary<string, string> postData = RaidQueue.GetHiddenInputValues(sendTroopForm);
            postData.Add("c", "2");
            postData.Add("x", tpEvadePoint.X.ToString());
            postData.Add("y", tpEvadePoint.Y.ToString());
            ReinforceToop = RaidQueue.GetMaxTroops(sendTroopForm);
            for (int i = 0; i < this.bTroopFilter.Length; i++)
            {
                if (bTroopFilter[i])
                    continue;

                ReinforceToop[i] = 0;
            }
            for (int i = 0; i < ReinforceToop.Length; i++)
            {
                string troopKey = String.Format("t{0}", i + 1);
                string troopNumber = ReinforceToop[i] == 0 ? "" : ReinforceToop[i].ToString();
                postData.Add(troopKey, troopNumber);
            }

            string confirmUrl = "build.php?id=39&tt=2";
            string confirmForm = UpCall.PageQuery(this.VillageID, confirmUrl, postData);
            if (confirmForm == null)
            {
                MinimumDelay = 0;
                return;
            }

            Match errorMatch = Regex.Match(confirmForm, "<p class=\"error\">(.+)</span>");
            if (errorMatch.Success)
            {
                string error = String.Format(
                    "Delete village {0}. Error: {1}",
                    tpEvadePoint,
                    errorMatch.Groups[1].Value);
                UpCall.DebugLog("部队未能发出,因为:" + error, DebugLevel.W);
                MinimumDelay = nMinInterval;
                return;
            }

            if (!confirmForm.Contains("<form method=\"post\" action=\"build.php?id=39&tt=2\">"))
            {
                MinimumDelay = 0;
                return;
            }

            TimeSpan timeCost = RaidQueue.GetOneWayTimeCost(confirmForm);
            if (timeCost == TimeSpan.MinValue)
            {
                MinimumDelay = nMinInterval;
                evade_status = EvadeStatus.NoAtkDetected;
                return;
            }

            postData = RaidQueue.GetHiddenInputValues(confirmForm);

            string result = this.UpCall.PageQuery(this.VillageID, confirmUrl, postData);
            if (result == null)
            {
                MinimumDelay = 0;
                return;
            }

            evade_status = EvadeStatus.Evaded;
            ReinforceTimeCost = (int)timeCost.TotalSeconds;
            MinimumDelay = ReinforceTimeCost + RandomDelay(5, 10);

            TTInfo troopInfo = new TTInfo()
            {
                Tribe = UpCall.TD.Tribe,
                Troops = ReinforceToop
            };
            string message = String.Format(
                "部队回避 {0} ({1}) => {2} {3}",
                this.UpCall.TD.Villages[this.VillageID].Coord,
                this.VillageID,
                this.tpEvadePoint,
                troopInfo.FriendlyName);

            this.UpCall.DebugLog(message, DebugLevel.I);
        }
예제 #9
0
        private DoRaidResult DoRaid()
        {
            try
            {
                if (this.MinimumDelay > 0)
                {
                    return DoRaidResult.Postpone;
                }

                string sendTroopsUrl = String.Format("a2b.php?z={0}", this.Targets[this.TargetID].Z);
                string sendTroopForm = UpCall.PageQuery(this.VillageID, sendTroopsUrl);
                if (sendTroopForm == null)
                {
                    return DoRaidResult.SkipVillage;
                }

                if (!sendTroopForm.Contains("<form method=\"POST\" name=\"snd\" action=\"a2b.php\">"))
                {
                    return DoRaidResult.SkipVillage;
                }

                Dictionary<string, string> postData = RaidQueue.GetHiddenInputValues(sendTroopForm);
                postData.Add("c", ((int)this.RaidType).ToString());
                postData.Add("x", this.Targets[this.TargetID].X.ToString());
                postData.Add("y", this.Targets[this.TargetID].Y.ToString());
                int[] maxTroops = RaidQueue.GetMaxTroops(sendTroopForm);
                for (int i = 0; i < this.Troops.Length; i++)
                {
                    if (this.Troops[i] > maxTroops[i])
                    {
                        return DoRaidResult.SkipVillage;
                    }

                    string troopKey = String.Format("t{0}", i + 1);
                    string troopNumber = this.Troops[i] == 0 ? "" : this.Troops[i].ToString();
                    postData.Add(troopKey, troopNumber);
                }

                string confirmUrl = "a2b.php";
                string confirmForm = UpCall.PageQuery(this.VillageID, confirmUrl, postData);
                if (confirmForm == null)
                {
                    return DoRaidResult.SkipVillage;
                }

                MatchCollection maxraidMatch = Regex.Matches(confirmForm, "<span class=\"b\">" + this.MaxSlots.ToString() + "</span>");

                Match errorMatch = Regex.Match(confirmForm, "<p class=\"error\">(.+)</p>");
                if (errorMatch.Success && maxraidMatch.Count < 2)
                {
                    string error = String.Format(
                        "Delete village {0}. Error: {1}",
                        this.Targets[this.TargetID],
                        errorMatch.Groups[1].Value);
                    this.UpCall.DebugLog(error, DebugLevel.W);
                    return DoRaidResult.DeleteVillage;
                }

                if (!confirmForm.ToLower().Contains("<form method=\"post\" action=\"a2b.php\">"))
                {
                    return DoRaidResult.SkipVillage;
                }

                TimeSpan timeCost = RaidQueue.GetOneWayTimeCost(confirmForm);
                if (timeCost == TimeSpan.MinValue)
                {
                    return DoRaidResult.SkipVillage;
                }

                postData = RaidQueue.GetHiddenInputValues(confirmForm);
                if (RaidQueue.HasRadioInput("spy", confirmForm))
                {
                    postData.Add("spy", ((int)this.SpyOption).ToString());
                }

                string result = this.UpCall.PageQuery(this.VillageID, confirmUrl, postData);
                if (result == null)
                {
                    return DoRaidResult.SkipVillage;
                }

                if (!this.MultipeRaids)
                {
                    this.MinimumDelay = (int)timeCost.TotalSeconds * 2 + this.RandomDelay(10, 15);
                }

                TTInfo troopInfo = new TTInfo()
                {
                    Tribe = this.UpCall.TD.Tribe,
                    Troops = this.Troops
                };
                string message = String.Format(
                    "{0} {1} ({2}) => {3} {4}",
                    this.RaidType,
                    this.UpCall.TD.Villages[this.VillageID].Coord,
                    this.VillageID,
                    this.Targets[this.TargetID],
                    troopInfo.FriendlyName);

                this.UpCall.DebugLog(message, DebugLevel.I);
                return DoRaidResult.Success;
            }

            catch (Exception ex)
            {
                UpCall.DebugLog(ex);
                return DoRaidResult.SkipVillage;
            }
        }
예제 #10
0
        void AnalizeAttacker(TTInfo troop)
        {
            if (!IsAttack(troop) && !IsRaid(troop))
                return;

            if (latest_toop == null || troop.FinishTime < latest_toop.FinishTime)
                latest_toop = troop;
        }
예제 #11
0
        private void CheckAttack()
        {
            var CV = UpCall.TD.Villages[VillageID];

            UpCall.PageQuery(VillageID, "build.php?gid=16&tt=1");
            latest_toop = null;
            foreach (TTInfo tt in CV.Troop.Troops)
            {
                AnalizeAttacker(tt);
            }

            if (latest_toop != null)
            {
                int latest_atk_delay =
                    (int)latest_toop.FinishTime.Subtract(DateTime.Now).TotalSeconds;
                if (latest_atk_delay > nMinInterval + nLeadTime)
                {
                    MinimumDelay = nMinInterval;
                    evade_status = EvadeStatus.AtkDetected;
                }
                else if (latest_atk_delay > nLeadTime
                         && latest_atk_delay <= nMinInterval + nLeadTime)
                {
                    MinimumDelay = latest_atk_delay - nLeadTime;
                    evade_status = EvadeStatus.ReadyForEvade;
                }
                else if (latest_atk_delay > 0
                         && latest_atk_delay <= nLeadTime)
                {
                    MinimumDelay = 0;
                    evade_status = EvadeStatus.ReadyForEvade;
                }
                else
                {
                    UpCall.DebugLog("由于出现异常,重置回避攻击检查队列。", DebugLevel.II);
                    latest_toop = null;
                    MinimumDelay = nMinInterval;
                    evade_status = EvadeStatus.NoAtkDetected;
                }

            }
            else
            {
                MinimumDelay = nMinInterval;
                evade_status = EvadeStatus.NoAtkDetected;
            }
        }
예제 #12
0
        private void buttonOK_Click(object sender, EventArgs e)
        {
            if (this.txtX.Text == "" && this.txtY.Text == "" && this.textCoord.Text == "")
                return;
            else if(this.textCoord.Text != "")
            {
                string multicoord = this.textCoord.Text.Replace(" ","").Replace("(","").Replace(")","");
                string[] multipletargets = multicoord.Split(',');
                for (int i = 0; i < multipletargets.Length; i++)
                {
                    if (!multipletargets[i].Contains("|"))
                        continue;
                    string[] id = multipletargets[i].Split('|');
                    int x1 = 0, y1 = 0;
                    Int32.TryParse(id[0], out x1);
                    Int32.TryParse(id[1], out y1);
                    TPoint tid = new TPoint(x1, y1);
                    if (!tid.IsEmpty)
                        iTargets.Add(tid);
                }
            }
            else if(this.txtX.Text != "" || this.txtY.Text != "")
            {
                int x = 0, y = 0;
                Int32.TryParse(this.txtX.Text, out x);
                Int32.TryParse(this.txtY.Text, out y);
                var aTargets = new TPoint(x, y);
                if (!aTargets.IsEmpty)
                    iTargets.Add(aTargets);
            }
            else
            {
                UpCall.DebugLog("No Attack Target!", DebugLevel.W);
                return;
            }
            if (iTargets == null || iTargets.Count == 0)
            {
                UpCall.DebugLog("Attack Coord is Error!", DebugLevel.W);
                return;
            }
            for (int i = 0; i < 11; i++)
            {
                int totalattack = Convert.ToInt32(this.numericUpDown1.Value) * iTargets.Count;
                int[] totalraidtroops = new int[11];
                int totaltroops = 0;
                int[] raidtroops = new int[11];
                for (int j = 0; j < 5; j++)
                {
                    int wv = Convert.ToInt32(Waves[j].Value);
                    raidtroops[i] = Convert.ToInt32(Nums[j, i].Value);
                    totaltroops = totaltroops + (raidtroops[i] * wv);
                }
                totalraidtroops[i] = totaltroops;
                if ((totalraidtroops[i] * totalattack) > Troops[i])
                    {
                        var Nt = MessageBox.Show("没有足够的军队");
                        return;
                    }
            }
            for (int j = 0; j < 5; j++)
            {
                int wv = Convert.ToInt32(Waves[j].Value);
                int[] raidtroops = new int[11];
                int totaltroops = 0;
                for (int i = 0; i < 11; i++)
                {
                    raidtroops[i] = Convert.ToInt32(Nums[j, i].Value);
                    totaltroops = totaltroops + raidtroops[i];
                }
                if (wv != 0 && totaltroops != 0)
                {
                    TTInfo mTargets = new TTInfo
                    {
                        Troops = raidtroops
                    };
                    nWaves.Add(wv);
                    nTargets.Add(mTargets);
                }
            }
            if (nWaves.Count == 0 || nTargets.Count == 0 || iTargets.Count == 0)
            {
                if (!this.checkBox2.Checked)
                    return;
            }

            Return = new AttackQueue
            {
                Raidtype = this.checkBox2.Checked ? 1 : this.comboBox3.SelectedIndex + 2,
                Targets = iTargets,
                wTroops = nTargets,
                wWaves = nWaves,
                VillageID = VillageID,
            //                MaxCount = Convert.ToInt32(this.numericUpDown1.Value),
                kata = this.comboBox1.SelectedIndex,
                kata2 = this.comboBox2.SelectedIndex,
                Settlers = this.checkBox2.Checked,
                MinimumInterval = minimumInterval,
                StartAt = actionAt,
            };
        }
예제 #13
0
        public void TestInitialize()
        {
            this.travianData = new Data()
            {
                Server = "none",
                Username = "******"
            };

            Dictionary<string, string> Options = new Dictionary<string, string>();
            this.travian = new Travian(travianData, Options, "cn");

            this.villageID = 1;
            this.village = new TVillage();
            this.travianData.Villages[villageID] = village;

            this.village.Name = "Home";
            this.village.isTroopInitialized = 2;
            this.village.Troop = this.troop = new TTroop();
            int[] troopsAtHome = new int[11];
            troopsAtHome[0] = 8;
            TTInfo troopAtHome = new TTInfo
            {
                Troops = troopsAtHome,
                Owner = this.village.Name,
                TroopType = TTroopType.InVillage,
                VillageName = "Own troops"
            };
            this.troop.Troops.Add(troopAtHome);

            int[] troopsOnTheRood = new int[11];
            troopsOnTheRood[0] = 5;
            TTInfo troopOnTheRoad = new TTInfo
            {
                Troops = troopsAtHome,
                TroopType = TTroopType.MyReturnWay,
                FinishTime = DateTime.Now.AddSeconds(100),
                VillageName = "Raid on abc Village"
            };
            this.troop.Troops.Add(troopOnTheRoad);

            this.troops = new int[11];
            this.troops[0] = 5;

            this.targets = new List<TPoint>();
            this.targets.Add(new TPoint(1, 2));
            this.targets.Add(new TPoint(0, 0));

            this.target = new RaidQueue()
            {
                UpCall = this.travian,
                VillageID = this.villageID,
                Troops = this.troops,
                Targets = this.targets,
                RaidType = RaidType.AttackRaid,
            };

            this.pageQuerier = new MockPageQuerier(this.villageID);
            this.travian.pageQuerier = pageQuerier;
        }
예제 #14
0
        private void DoEvade()
        {
            string sendTroopsUrl = String.Format("build.php?id=39&tt=2&z={0}", tpEvadePoint.Z);
            string sendTroopForm = UpCall.PageQuery(VillageID, sendTroopsUrl);

            if (sendTroopForm == null ||
                !sendTroopForm.Contains("<form method=\"POST\" name=\"snd\" action=\"build.php?id=39&tt=2\">"))
            {
                MinimumDelay = 0;
                return;
            }

            Dictionary <string, string> postData = RaidQueue.GetHiddenInputValues(sendTroopForm);

            postData.Add("c", "2");
            postData.Add("x", tpEvadePoint.X.ToString());
            postData.Add("y", tpEvadePoint.Y.ToString());
            ReinforceToop = RaidQueue.GetMaxTroops(sendTroopForm);
            for (int i = 0; i < this.bTroopFilter.Length; i++)
            {
                if (bTroopFilter[i])
                {
                    continue;
                }

                ReinforceToop[i] = 0;
            }
            for (int i = 0; i < ReinforceToop.Length; i++)
            {
                string troopKey    = String.Format("t{0}", i + 1);
                string troopNumber = ReinforceToop[i] == 0 ? "" : ReinforceToop[i].ToString();
                postData.Add(troopKey, troopNumber);
            }

            string confirmUrl  = "build.php?id=39&tt=2";
            string confirmForm = UpCall.PageQuery(this.VillageID, confirmUrl, postData);

            if (confirmForm == null)
            {
                MinimumDelay = 0;
                return;
            }

            Match errorMatch = Regex.Match(confirmForm, "<p class=\"error\">(.+)</span>");

            if (errorMatch.Success)
            {
                string error = String.Format(
                    "Delete village {0}. Error: {1}",
                    tpEvadePoint,
                    errorMatch.Groups[1].Value);
                UpCall.DebugLog("部队未能发出,因为:" + error, DebugLevel.W);
                MinimumDelay = nMinInterval;
                return;
            }

            if (!confirmForm.Contains("<form method=\"post\" action=\"build.php?id=39&tt=2\">"))
            {
                MinimumDelay = 0;
                return;
            }

            TimeSpan timeCost = RaidQueue.GetOneWayTimeCost(confirmForm);

            if (timeCost == TimeSpan.MinValue)
            {
                MinimumDelay = nMinInterval;
                evade_status = EvadeStatus.NoAtkDetected;
                return;
            }

            postData = RaidQueue.GetHiddenInputValues(confirmForm);

            string result = this.UpCall.PageQuery(this.VillageID, confirmUrl, postData);

            if (result == null)
            {
                MinimumDelay = 0;
                return;
            }

            evade_status      = EvadeStatus.Evaded;
            ReinforceTimeCost = (int)timeCost.TotalSeconds;
            MinimumDelay      = ReinforceTimeCost + RandomDelay(5, 10);

            TTInfo troopInfo = new TTInfo()
            {
                Tribe  = UpCall.TD.Tribe,
                Troops = ReinforceToop
            };
            string message = String.Format(
                "部队回避 {0} ({1}) => {2} {3}",
                this.UpCall.TD.Villages[this.VillageID].Coord,
                this.VillageID,
                this.tpEvadePoint,
                troopInfo.FriendlyName);

            this.UpCall.DebugLog(message, DebugLevel.I);
        }
예제 #15
0
 private bool IsRaid(TTInfo troop)
 {
     return IsAttackType(troop, "raid");
 }
예제 #16
0
        private void ParseTroops(int VillageID, string data)
        {
            if (GetBuildingLevel(16, data) < 0 && !data.Contains("<h1>Rally point"))
                return;
            var CV = TD.Villages[VillageID];
            CV.Troop.Troops.Clear();
            var items = data.Split(new string[] { "<table class=" }, StringSplitOptions.None);
            foreach (var item in items)
            {
                var m = Regex.Match(item, "<td\\sclass=\"role\"><a\\shref=\".*?\">(.*?)</a></td><td colspan=\"1[01]\">(.*?)</a></td>.*?class=\"unit\\s\\w(\\d+)\".*?(?:<td[^>]*>(\\d+|\\?)</td>){10,11}.*?(?:>(\\d+)<img\\sclass=\"r4|.*?<span\\sid=\"?timer\\d+\"?>(.*?)</span>)", RegexOptions.Singleline);
                //                var m = Regex.Match(item, "<td\\sclass=\"role\"><a\\shref=\".*?\">(.*?)</a></td><td colspan=\"1[01]\"><a\\shref=\".*?\">(.*?)</a></td>.*?class=\"unit\\s\\w(\\d+)\".*?(?:<td[^>]*>(\\d+|\\?)</td>){10,11}.*?(?:>(\\d+)<img\\sclass=\"r4|.*?<span\\sid=\"?timer\\d+\"?>(.*?)</span>)", RegexOptions.Singleline);
                /*
                 * @@1 from vname
                 * @@2 to vname
                 * @@3 gif index for tribe
                 * @@4 troopcount
                 * @@5 cropcost
                 * @@6 time on way
                 */
                var r = Regex.Match(item, "(a2b.php\\?d=.*?&c=.*?)\"", RegexOptions.Singleline);
                string returnlink = r.Groups[1].Value;
                if (!m.Success)
                    continue;
                int[] tro = new int[11];
                for (int i = 0; i < m.Groups[4].Captures.Count; i++)
                {
                    if (m.Groups[4].Captures[i].Value == "?")
                        tro[i] = -1;
                    else
                        tro[i] = Convert.ToInt32(m.Groups[4].Captures[i].Value);
                }
                /*
               uid  time  	mark	troopcount  cropcost	returnlink
                -     O      R		 	O      	-			-		MyReturnWay
                -     O      			O      	-			-		MyAttackWay
                -     O      S			O      	-			-		MySupportWay // MyOtherSupportMeWay
                -     -      S			O      	O			O		MySupportOther
                -     O    			    -      	-			-		BeAttackedWay
                -     O    	 S		    -      	-			-		BeSupportedWay
                O     -    	 		    O      	O			-		MySelf // MyOtherSupportMe
                O     -    	 		    O       O       	O		BeSupportMe
                 */
                bool hasuid = m.Groups[2].Value.Contains("uid");
                bool hassupport = Regex.Match(m.Groups[2].Value, RegexLang["newparser_hassupport"]).Success;
                bool hasretrun = Regex.Match(m.Groups[2].Value, RegexLang["newparser_hasretrun"]).Success;
                bool hasspy = Regex.Match(m.Groups[2].Value, RegexLang["newparser_hasspy"]).Success;
                bool hasraid = Regex.Match(m.Groups[2].Value, RegexLang["newparser_hasraid"]).Success;
                bool hasattack = Regex.Match(m.Groups[2].Value, RegexLang["newparser_hasattack"]).Success;
                bool hasTime = m.Groups[6].Success;
                bool hasCount = tro[0] != -1;
                bool hasCrop = m.Groups[5].Success;
                string vvname = CV.Name;
                string vname;
                TTroopType trooptype = hasuid ?
                    TTroopType.BeSupportMe :
                    (hasTime ?
                    (hasCount ?
                    (hasretrun ? TTroopType.MyReturnWay : (hassupport ? TTroopType.MySupportWay : TTroopType.MyAttackWay)) :
                    (hassupport ? TTroopType.BeSupportedWay : TTroopType.BeAttackedWay)) :
                     TTroopType.MySupportOther);
                if (trooptype == TTroopType.BeAttackedWay || trooptype == TTroopType.BeSupportedWay || trooptype == TTroopType.BeSupportMe)
                    vname = m.Groups[1].Value;
                else
                    vname = Regex.Replace(m.Groups[2].Value, "<[^>]+>", "");
                if (trooptype == TTroopType.MySupportWay && vname.Contains(vvname))
                {
                    trooptype = TTroopType.MyOtherSupportMeWay;
                    vname = m.Groups[1].Value;
                }
                if (trooptype == TTroopType.BeSupportMe)
                {
                    if (vvname == vname && !r.Success)
                        trooptype = TTroopType.MySelf;
                    else if (m.Groups[2].Value.Contains(TD.Username))
                        trooptype = TTroopType.MyOtherSupportMe;
                }

                DateTime finishTime = DateTime.MinValue;
                int tribe = Convert.ToInt32(m.Groups[3].Value) / 10 + 1;
                if (hasTime)
                    finishTime = DateTime.Now.Add(TimeSpanParse(m.Groups[6].Value)).AddSeconds(20);
                TTInfo ttro = new TTInfo
                {
                    Tribe = tribe,
                    Troops = tro,
                    TroopType = trooptype,
                    FinishTime = finishTime,
                    VillageName = vname
                };
                CV.Troop.Troops.Add(ttro);
                Console.WriteLine(ttro.VillageName);
            }
            StatusUpdate(this, new StatusChanged() { ChangedData = ChangedType.Villages });
        }
예제 #17
0
        private TAttacker ParseAttacker(TTInfo troop)
        {
            string data = UpCall.PageQuery(VillageID, troop.OwnerVillageUrl, null, true, true);
            if (string.IsNullOrEmpty(data))
                return null;

            string name = "", ally = "";
            int uid = 0, popu = 0;

            string pattern = @"<table.*id=""village_info"".*allianz\.php\?aid=\d+"">(.*)</a>.*spieler\.php\?uid=(\d+)"">(.*)</a>.*<td>(\d+)</td>.*</table>";
            Regex reg = new Regex(pattern, RegexOptions.Singleline);
            Match m = reg.Match(data);
            if (m.Success)
            {
                ally = m.Groups[1].Value;
                uid = int.Parse(m.Groups[2].Value);
                name = m.Groups[3].Value;
                popu = int.Parse(m.Groups[4].Value);
            }
            else
                return null;

            TPoint point = new TPoint();
            point.Z = troop.OwnerVillageZ;
            TAttacker attacker = new TAttacker
            {
                Point = point,
                Tribe = troop.Tribe,
                troops = new List<TTInfo>(),
                VileageName = troop.Owner,
                Ally = ally,
                Name = name,
                Uid = uid,
                Population = popu,
            };
            return attacker;
        }
예제 #18
0
 bool IsRaid(TTInfo troop)
 {
     return(IsAttackType(troop, "raid"));
 }