Ejemplo n.º 1
0
        private void doHeroAdventure(object o)
        {
            lock (Level2Lock)
            {
                int HeroLoc = TD.Adv_Sta.HeroLocate;
                int Key     = (int)o;

                if (Key < 0 || Key >= TD.Adv_Sta.HeroAdventures.Count)
                {
                    return;
                }
                TPoint tp   = new TPoint(TD.Adv_Sta.HeroAdventures[Key].axis_x, TD.Adv_Sta.HeroAdventures[Key].axis_y);
                string data = PageQuery(HeroLoc, "start_adventure.php?from=list&kid=" + tp.Z.ToString());

                if (string.IsNullOrEmpty(data))
                {
                    return;
                }
                Match m_test = Regex.Match(data, "type=\"submit\" value=\".*?\" name=\"start\"");
                if (!m_test.Success)
                {
                    DebugLog("英雄目前还无法进行探险!", DebugLevel.II);
                    return;
                }
                Dictionary <string, string> PostData = new Dictionary <string, string>();
                MatchCollection             mc       = Regex.Matches(
                    data, "<input type=\"hidden\" name=\"([^\"]*?)\" value=\"([^\"]*?)\" />");
                string key, val;
                foreach (Match m in mc)
                {
                    key           = m.Groups[1].Value;
                    val           = m.Groups[2].Value;
                    PostData[key] = val;
                }
                PageQuery(HeroLoc, "start_adventure.php", PostData);
                PageQuery(HeroLoc, "build.php?gid=16&tt=1");
            }
        }
Ejemplo n.º 2
0
        private void btnAdd_Click(object sender, EventArgs e)
        {
            int x, y;
            if (!Int32.TryParse(this.txtX.Text, out x))
            {
                return;
            }

            if (!Int32.TryParse(this.txtY.Text, out y))
            {
                return;
            }

            TPoint village = new TPoint(x, y);
            if (this.lstTargets.SelectedIndex < 0)
            {
                this.lstTargets.Items.Add(village);
            }
            else
            {
                this.lstTargets.Items.Insert(this.lstTargets.SelectedIndex, village);
            }
        }
Ejemplo n.º 3
0
        public void Action()
        {
            if (MinimumDelay > 0)
                return;

            string data = UpCall.CheckBuildingExistAndQuery(VillageID, 16);
            if (data == null)
            {
                MinimumDelay = 60;
                return;
            }

            hero_status = CheckIfHeroHome();
            if (hero_status == -1)
            {
                UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                                    {
                                        ChangedData = Travian.ChangedType.Queue,
                                        VillageID = VillageID
                                    });
                UpCall.DebugLog("英雄不属于该村,无法探险!", DebugLevel.II);
                MarkDeleted = true;
                return;
            }
            else if (hero_status == 1)
            {
                UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                                    {
                                        ChangedData = Travian.ChangedType.Queue,
                                        VillageID = VillageID
                                    });
                UpCall.DebugLog("英雄目前不在家,等待英雄返回!", DebugLevel.II);
                return;
            }

            bool bAvail = false;
            List<HeroAdventureInfo> InfoList = UpCall.TD.Adv_Sta.HeroAdventures;
            for (int i = 0; i < InfoList.Count; i++)
            {
                TimeSpan ts = CheckDurAvail(InfoList[i].duration);
                if (ts == TimeSpan.MinValue)
                    continue;
                bAvail = true;
                break;
            }

            //	如果当前的探险地方尚未初始化或全部都不合适,则尝试重新抓取
            if (!UpCall.TD.Adv_Sta.bIsHeroAdventureInitialize || !bAvail)
            {
                UpCall.doFetchHeroAdventures(VillageID);
            }

            cur_adv_pt = new TPoint(0, 0);
            int HeroLoc = UpCall.TD.Adv_Sta.HeroLocate;

            for (int i = 0; i < InfoList.Count; i++)
            {
                TimeSpan ts = CheckDurAvail(InfoList[i].duration);
                if (ts == TimeSpan.MinValue)
                {
                    UpCall.DebugLog(
                        "跳过(" + InfoList[i].axis_x + "|" + InfoList[i].axis_y + ")的探险",
                        DebugLevel.II);
                    continue;
                }

                TPoint tp = new TPoint(InfoList[i].axis_x, InfoList[i].axis_y);
                data = UpCall.PageQuery(HeroLoc, "start_adventure.php?from=list&kid=" + tp.Z.ToString());
                if (data == null)
                    continue;
                Match m_test = Regex.Match(data, "type=\"submit\" value=\".*?\" name=\"start\"");
                if (!m_test.Success)
                    continue;

                Dictionary<string, string> PostData = new Dictionary<string, string>();
                MatchCollection mc = Regex.Matches(
                    data, "<input type=\"hidden\" name=\"([^\"]*?)\" value=\"([^\"]*?)\" />");
                string key, val;
                foreach (Match m in mc)
                {
                    key = m.Groups[1].Value;
                    val = m.Groups[2].Value;
                    PostData[key] = val;
                }
                UpCall.PageQuery(HeroLoc, "start_adventure.php", PostData);
                UpCall.PageQuery(HeroLoc, "build.php?gid=16&tt=1");

                MinimumDelay = Convert.ToInt32(ts.TotalSeconds);
                cur_adv_pt = tp;
                break;
            }

            if (cur_adv_pt.IsEmpty)
            {
                MinimumDelay = 3600;
                UpCall.DebugLog("探险位置不存在或行程过长", DebugLevel.II);
            }
            else
            {
                UpCall.DebugLog("前往(" + cur_adv_pt.X + "|" + cur_adv_pt.Y + ")探险", DebugLevel.II);
            }
            hero_status = 2;
            UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                    {
                        ChangedData = Travian.ChangedType.Queue,
                        VillageID = VillageID
                    });
        }
Ejemplo n.º 4
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;
        }
Ejemplo n.º 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,
            };
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Dispatch a transportation of a given amount of resource from one village to a given destiantion
        /// </summary>
        /// <param name="VillageID">Unique ID of the departure village</param>
        /// <param name="Amount">Amounts of resources to transport</param>
        /// <param name="TargetPos">Position of the arrival village</param>
        /// <returns>Error return minus number. Succeed return single way transfer time cost.</returns>
        public int doTransfer(TResAmount Amount, TPoint TargetPos)
        {
            string result = UpCall.PageQuery(VillageID, "build.php?gid=17&t=5");
            if(result == null)
                return -1;
            var CV = UpCall.TD.Villages[VillageID];
            Dictionary<string, string> PostData = new Dictionary<string, string>();
            var m = Regex.Match(result, "name=\"id\" id=\"id\" value=\"(\\d+)\"", RegexOptions.Singleline);
            if(!m.Success)
                return -1;
            PostData["cmd"] = "prepareMarketplace";
            PostData["id"] = m.Groups[1].Value;

            if(result.Contains("Popup(2,5)") && Amount.TotalAmount > CV.Market.SingleCarry * CV.Market.ActiveMerchant)
            {
                resumeTime = DateTime.Now.AddSeconds(rand.Next(200 + retrycount * 20, 300 + retrycount * 30));
                UpCall.DebugLog("0:00:0?, Will retry...", DebugLevel.I);
                return -2;
            }
            if(Amount.TotalAmount > CV.Market.SingleCarry * CV.Market.ActiveMerchant)
            {
                retrycount++;
                if(retrycount > 5)
                {
                    UpCall.DebugLog(string.Format("Transfer cannot go on: MCarry({0}) * MCount({1}) < Amount({2})", CV.Market.SingleCarry, CV.Market.ActiveMerchant, Amount.TotalAmount), DebugLevel.W);
                    return -2; // Beyond transfer ability
                }
                else
                {
                    UpCall.DebugLog("Error on 'ActiveMerchant'! Will retry...", DebugLevel.I);
                    resumeTime = DateTime.Now.AddSeconds(rand.Next(500 + retrycount * 20, 800 + retrycount * 30));
                    CV.Market.ActiveMerchant = Math.Min(Amount.TotalAmount / CV.Market.SingleCarry + 1, CV.Market.MaxMerchant);
                    return -2;
                }
            }
            retrycount = 0;
            for(int i = 0; i < 4; i++)
            {
                PostData["r" + (i + 1).ToString()] = Amount.Resources[i].ToString();
            }

            //cmd=prepareMarketplace&r1=3000&r2=3000&r3=3000&r4=&dname=&x=50&y=105&id=27&t=5&x2=1
            PostData["dname"] = "";
            PostData["x"] = TargetPos.X.ToString();
            PostData["y"] = TargetPos.Y.ToString();
            PostData["t"] = "5";
            PostData["x2"] = "1";

            result = UpCall.PageQuery(VillageID, "ajax.php?cmd=prepareMarketplace", PostData);

            //cmd=prepareMarketplace&t=5&id=27&a=64846&sz=2788&kid=236746&c=aaa02a&x2=1&r1=3000&r2=3000&r3=3000&r4=
            if(result == null)
                return -1;
            PostData.Clear();
            result = result.Replace("\\\"", "\"");
            result = result.Replace("\\/", "/");
            PostData["cmd"] = "prepareMarketplace";
            MatchCollection matches = Regex.Matches(result, "name=\"(\\w+)\" id=\"\\w+\" value=\"(\\w+)\"");
            for (int i = 0; i < matches.Count; i ++)
            {
                PostData[matches[i].Groups[1].Value] = matches[i].Groups[2].Value;
            }
            for(int i = 0; i < 4; i++)
            {
                PostData["r" + (i + 1).ToString()] = Amount.Resources[i].ToString();
            }
            m = Regex.Match(result, "<td>([0-9:]{6,})</td>");
            if(!m.Success)
                return -1; // Parse error!
            int TimeCost = Convert.ToInt32(UpCall.TimeSpanParse(m.Groups[1].Value).TotalSeconds);
            if(UpCall.TD.MarketSpeed != 0)
            {
                // calc market speed
                var distance = CV.Coord * TargetPos;
                UpCall.TD.Dirty = true;
                UpCall.TD.MarketSpeed = Convert.ToInt32(Math.Round(distance * 3600 / TimeCost));
            }

            UpCall.PageQuery(VillageID, "ajax.php?cmd=prepareMarketplace", PostData);
            UpCall.BuildCount();

            // write data into target village if it's my village.
            foreach(var x in UpCall.TD.Villages)
            {
                if(x.Value == CV)
                    continue;
                if(x.Value.Coord == TargetPos)
                {
                    if(x.Value.isBuildingInitialized == 2)
                        x.Value.Market.MarketInfo.Add(new TMInfo()
                        {
                            CarryAmount = Amount.Clone(),
                            Coord = CV.Coord,
                            FinishTime = DateTime.Now.AddSeconds(TimeCost),
                            MType = TMType.OtherCome,
                            VillageName = CV.Name
                        });
                    break;
                }
            }
            UpCall.DebugLog(string.Format("Transfer {0}({1}) => {2} {3}", CV.Coord.ToString(), VillageID, TargetPos.ToString(),
                Amount.ToString()), DebugLevel.I);
            return TimeCost;
        }
Ejemplo n.º 7
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;
        }
Ejemplo n.º 8
0
        private void doHeroAdventure(object o)
        {
            lock (Level2Lock)
            {
                int HeroLoc = TD.Adv_Sta.HeroLocate;
                int Key = (int)o;

                if (Key <  0 || Key >= TD.Adv_Sta.HeroAdventures.Count)
                {
                    return;
                }
                TPoint tp = new TPoint(TD.Adv_Sta.HeroAdventures[Key].axis_x, TD.Adv_Sta.HeroAdventures[Key].axis_y);
                string data = PageQuery(HeroLoc, "start_adventure.php?from=list&kid=" + tp.Z.ToString());

                if (string.IsNullOrEmpty(data))
                    return;
                Match m_test = Regex.Match(data, "type=\"submit\" value=\".*?\" name=\"start\"");
                if (!m_test.Success)
                {
                    DebugLog("英雄目前还无法进行探险!", DebugLevel.II);
                    return;
                }
                Dictionary<string, string> PostData = new Dictionary<string, string>();
                MatchCollection mc = Regex.Matches(
                    data, "<input type=\"hidden\" name=\"([^\"]*?)\" value=\"([^\"]*?)\" />");
                string key, val;
                foreach (Match m in mc)
                {
                    key = m.Groups[1].Value;
                    val = m.Groups[2].Value;
                    PostData[key] = val;
                }
                PageQuery(HeroLoc, "start_adventure.php", PostData);
                PageQuery(HeroLoc, "build.php?gid=16&tt=1");
            }
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Dispatch a transportation of a given amount of resource from one village to a given destiantion
        /// </summary>
        /// <param name="VillageID">Unique ID of the departure village</param>
        /// <param name="Amount">Amounts of resources to transport</param>
        /// <param name="TargetPos">Position of the arrival village</param>
        /// <returns>Error return minus number. Succeed return single way transfer time cost.</returns>
        public int doTransfer(TResAmount Amount, TPoint TargetPos)
        {
            string result = UpCall.PageQuery(VillageID, "build.php?gid=17&t=5");

            if (result == null)
            {
                return(-1);
            }
            var CV = UpCall.TD.Villages[VillageID];
            Dictionary <string, string> PostData = new Dictionary <string, string>();
            var m = Regex.Match(result, "name=\"id\" id=\"id\" value=\"(\\d+)\"", RegexOptions.Singleline);

            if (!m.Success)
            {
                return(-1);
            }
            PostData["cmd"] = "prepareMarketplace";
            PostData["id"]  = m.Groups[1].Value;

            if (result.Contains("Popup(2,5)") && Amount.TotalAmount > CV.Market.SingleCarry * CV.Market.ActiveMerchant)
            {
                resumeTime = DateTime.Now.AddSeconds(rand.Next(200 + retrycount * 20, 300 + retrycount * 30));
                UpCall.DebugLog("0:00:0?, Will retry...", DebugLevel.I);
                return(-2);
            }
            if (Amount.TotalAmount > CV.Market.SingleCarry * CV.Market.ActiveMerchant)
            {
                retrycount++;
                if (retrycount > 5)
                {
                    UpCall.DebugLog(string.Format("Transfer cannot go on: MCarry({0}) * MCount({1}) < Amount({2})", CV.Market.SingleCarry, CV.Market.ActiveMerchant, Amount.TotalAmount), DebugLevel.W);
                    return(-2);                    // Beyond transfer ability
                }
                else
                {
                    UpCall.DebugLog("Error on 'ActiveMerchant'! Will retry...", DebugLevel.I);
                    resumeTime = DateTime.Now.AddSeconds(rand.Next(500 + retrycount * 20, 800 + retrycount * 30));
                    CV.Market.ActiveMerchant = Math.Min(Amount.TotalAmount / CV.Market.SingleCarry + 1, CV.Market.MaxMerchant);
                    return(-2);
                }
            }
            retrycount = 0;
            for (int i = 0; i < 4; i++)
            {
                PostData["r" + (i + 1).ToString()] = Amount.Resources[i].ToString();
            }

            //cmd=prepareMarketplace&r1=3000&r2=3000&r3=3000&r4=&dname=&x=50&y=105&id=27&t=5&x2=1
            PostData["dname"] = "";
            PostData["x"]     = TargetPos.X.ToString();
            PostData["y"]     = TargetPos.Y.ToString();
            PostData["t"]     = "5";
            PostData["x2"]    = "1";

            result = UpCall.PageQuery(VillageID, "ajax.php?cmd=prepareMarketplace", PostData);

            //cmd=prepareMarketplace&t=5&id=27&a=64846&sz=2788&kid=236746&c=aaa02a&x2=1&r1=3000&r2=3000&r3=3000&r4=
            if (result == null)
            {
                return(-1);
            }
            PostData.Clear();
            result          = result.Replace("\\\"", "\"");
            result          = result.Replace("\\/", "/");
            PostData["cmd"] = "prepareMarketplace";
            MatchCollection matches = Regex.Matches(result, "name=\"(\\w+)\" id=\"\\w+\" value=\"(\\w+)\"");

            for (int i = 0; i < matches.Count; i++)
            {
                PostData[matches[i].Groups[1].Value] = matches[i].Groups[2].Value;
            }
            for (int i = 0; i < 4; i++)
            {
                PostData["r" + (i + 1).ToString()] = Amount.Resources[i].ToString();
            }
            m = Regex.Match(result, "<td>([0-9:]{6,})</td>");
            if (!m.Success)
            {
                return(-1);                // Parse error!
            }
            int TimeCost = Convert.ToInt32(UpCall.TimeSpanParse(m.Groups[1].Value).TotalSeconds);

            if (UpCall.TD.MarketSpeed != 0)
            {
                // calc market speed
                var distance = CV.Coord * TargetPos;
                UpCall.TD.Dirty       = true;
                UpCall.TD.MarketSpeed = Convert.ToInt32(Math.Round(distance * 3600 / TimeCost));
            }

            UpCall.PageQuery(VillageID, "ajax.php?cmd=prepareMarketplace", PostData);
            UpCall.BuildCount();

            // write data into target village if it's my village.
            foreach (var x in UpCall.TD.Villages)
            {
                if (x.Value == CV)
                {
                    continue;
                }
                if (x.Value.Coord == TargetPos)
                {
                    if (x.Value.isBuildingInitialized == 2)
                    {
                        x.Value.Market.MarketInfo.Add(new TMInfo()
                        {
                            CarryAmount = Amount.Clone(),
                            Coord       = CV.Coord,
                            FinishTime  = DateTime.Now.AddSeconds(TimeCost),
                            MType       = TMType.OtherCome,
                            VillageName = CV.Name
                        });
                    }
                    break;
                }
            }
            UpCall.DebugLog(string.Format("Transfer {0}({1}) => {2} {3}", CV.Coord.ToString(), VillageID, TargetPos.ToString(),
                                          Amount.ToString()), DebugLevel.I);
            return(TimeCost);
        }
Ejemplo n.º 10
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,
            };
        }
Ejemplo n.º 11
0
        /// <summary>
        /// Dispatch a transportation of a given amount of resource from one village to a given destiantion
        /// </summary>
        /// <param name="VillageID">Unique ID of the departure village</param>
        /// <param name="Amount">Amounts of resources to transport</param>
        /// <param name="Target">Position of the arrival village</param>
        /// <returns>Error return minus number. Succeed return single way transfer time cost.</returns>
        public int doTransfer(TResAmount Amount, TPoint Target)
        {
            string result = UpCall.PageQuery(VillageID, "build.php?gid=17");
            if(result == null)
                return -1;
            var CV = UpCall.TD.Villages[VillageID];
            Dictionary<string, string> PostData = new Dictionary<string, string>();
            var m = Regex.Match(result, "name=\"id\" value=\"(\\d+)\"");
            if(!m.Success)
                return -1; // Parse error!
            PostData["id"] = m.Groups[1].Value;
            /*
            m = Regex.Match(result, "var haendler = (\\d+);");
            if (!m.Success)
                return -1;
            var MCount = Convert.ToInt32(m.Groups[1].Value);
            m = Regex.Match(result, "var carry = (\\d+);");
            if (!m.Success)
                return -1;
            var MCarry = Convert.ToInt32(m.Groups[1].Value);
            */

            //if (Amount.TotalAmount > MCarry * MCount)
            if(result.Contains("Popup(2,5)") && Amount.TotalAmount > CV.Market.SingleCarry * CV.Market.ActiveMerchant)
            {
                resumeTime = DateTime.Now.AddSeconds(rand.Next(200 + retrycount * 20, 300 + retrycount * 30));
                UpCall.DebugLog("0:00:0?, Will retry...", DebugLevel.W);
                return -2;
            }
            if(Amount.TotalAmount > CV.Market.SingleCarry * CV.Market.ActiveMerchant)
            {
                retrycount++;
                if(retrycount > 5)
                {
                    UpCall.DebugLog(string.Format("Transfer cannot go on: MCarry({0}) * MCount({1}) < Amount({2})", CV.Market.SingleCarry, CV.Market.ActiveMerchant, Amount.TotalAmount), DebugLevel.W);
                    return -5; // Beyond transfer ability
                }
                else
                {
                    UpCall.DebugLog("Error on 'ActiveMerchant'! Will retry...", DebugLevel.W);
                    resumeTime = DateTime.Now.AddSeconds(rand.Next(500 + retrycount * 20, 800 + retrycount * 30));
                    CV.Market.ActiveMerchant = Math.Min(Amount.TotalAmount / CV.Market.SingleCarry + 1, CV.Market.MaxMerchant);
                    return -2;
                }
            }
            retrycount = 0;
            for(int i = 0; i < 4; i++)
            {
                PostData["r" + (i + 1).ToString()] = Amount.Resources[i].ToString();
            }

            PostData["dname"] = "";
            PostData["x"] = Target.X.ToString();
            PostData["y"] = Target.Y.ToString();
            PostData["s1"] = "ok";

            result = UpCall.PageQuery(VillageID, "build.php", PostData);
            if(result == null)
                return -1;

            m = Regex.Match(result, "<p class=\"error\">([^<]*?)</p>");
            if (m.Success)
            {
                refreshcount++;
                if (refreshcount > 2)
                {
                    UpCall.DebugLog("Error:" + m.Groups[1].Value, DebugLevel.E);
                    return -5;
                }
                else
                {
                    UpCall.DebugLog("Data isn't refreshed?! Will retry...", DebugLevel.W);
                    return -2;
                }
            }
            refreshcount = 0;

            m = Regex.Match(result, "name=\"sz\" value=\"(\\d+)\"");
            if(!m.Success)
                return -1; // Parse error!
            PostData["sz"] = m.Groups[1].Value;
            PostData["kid"] = Target.Z.ToString();
            PostData["a"] = VillageID.ToString();
            m = Regex.Match(result, "name=\"c\" value=\"(.*?)\"");
            if (m.Success)
                PostData["c"] = m.Groups[1].Value;

            m = Regex.Match(result, "<td>([0-9:]{6,})</td>");
            if(!m.Success)
                return -1; // Parse error!
            int TimeCost = Convert.ToInt32(UpCall.TimeSpanParse(m.Groups[1].Value).TotalSeconds);

            if(UpCall.TD.MarketSpeed != 0)
            {
                // calc market speed
                var distance = CV.Coord * TargetPos;
                UpCall.TD.MarketSpeed = Convert.ToInt32(Math.Round(distance * 3600 / TimeCost));
                UpCall.TD.Dirty = true;
                if (UpCall.TD.MarketSpeed == 0)
                {
                    int StdSpeed = 24;
                    if (UpCall.TD.Tribe != 0)
                    {
                        StdSpeed = Buildings.BaseSpeed[UpCall.TD.Tribe][10];
                    }
                    //判断如果是speed服则商人速度×2
                    if (UpCall.TD.Server.Substring(0, 5) == "speed")
                        StdSpeed *= 2;
                    UpCall.TD.MarketSpeed = StdSpeed;
                    UpCall.TD.Dirty = true;
                }
            }

            UpCall.JustTransferredData = Amount;
            result = UpCall.PageQuery(VillageID, "build.php", PostData);
            if (result == null)
                return -1;
            UpCall.BuildCount();

            // write data into target village if it's my village.
            foreach(var x in UpCall.TD.Villages)
            {
                if(x.Value == CV)
                    continue;
                if(x.Value.Coord == Target)
                {
                    if(x.Value.isBuildingInitialized == 2)
                        x.Value.Market.MarketInfo.Add(new TMInfo()
                        {
                            CarryAmount = Amount.Clone(),
                            Coord = CV.Coord,
                            FinishTime = DateTime.Now.AddSeconds(TimeCost),
                            MType = TMType.OtherCome,
                            VillageName = CV.Name
                        });
                    break;
                }
            }
            UpCall.DebugLog(string.Format("Transfer {0}({1}) => {2} {3}", CV.Coord.ToString(), VillageID, Target.ToString(),
                Amount.ToString()), DebugLevel.I);
            return TimeCost;
        }
Ejemplo n.º 12
0
        public void Action()
        {
            if (MinimumDelay > 0)
            {
                return;
            }

            string data = UpCall.CheckBuildingExistAndQuery(VillageID, 16);

            if (data == null)
            {
                MinimumDelay = 60;
                return;
            }

            hero_status = CheckIfHeroHome();
            if (hero_status == -1)
            {
                UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                {
                    ChangedData = Travian.ChangedType.Queue,
                    VillageID   = VillageID
                });
                UpCall.DebugLog("英雄不属于该村,无法探险!", DebugLevel.II);
                MarkDeleted = true;
                return;
            }
            else if (hero_status == 1)
            {
                UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                {
                    ChangedData = Travian.ChangedType.Queue,
                    VillageID   = VillageID
                });
                UpCall.DebugLog("英雄目前不在家,等待英雄返回!", DebugLevel.II);
                return;
            }

            bool bAvail = false;
            List <HeroAdventureInfo> InfoList = UpCall.TD.Adv_Sta.HeroAdventures;

            for (int i = 0; i < InfoList.Count; i++)
            {
                TimeSpan ts = CheckDurAvail(InfoList[i].duration);
                if (ts == TimeSpan.MinValue)
                {
                    continue;
                }
                bAvail = true;
                break;
            }

            //	如果当前的探险地方尚未初始化或全部都不合适,则尝试重新抓取
            if (!UpCall.TD.Adv_Sta.bIsHeroAdventureInitialize || !bAvail)
            {
                UpCall.doFetchHeroAdventures(VillageID);
            }

            cur_adv_pt = new TPoint(0, 0);
            int HeroLoc = UpCall.TD.Adv_Sta.HeroLocate;

            for (int i = 0; i < InfoList.Count; i++)
            {
                TimeSpan ts = CheckDurAvail(InfoList[i].duration);
                if (ts == TimeSpan.MinValue)
                {
                    UpCall.DebugLog(
                        "跳过(" + InfoList[i].axis_x + "|" + InfoList[i].axis_y + ")的探险",
                        DebugLevel.II);
                    continue;
                }

                TPoint tp = new TPoint(InfoList[i].axis_x, InfoList[i].axis_y);
                data = UpCall.PageQuery(HeroLoc, "start_adventure.php?from=list&kid=" + tp.Z.ToString());
                if (data == null)
                {
                    continue;
                }
                Match m_test = Regex.Match(data, "type=\"submit\" value=\".*?\" name=\"start\"");
                if (!m_test.Success)
                {
                    continue;
                }

                Dictionary <string, string> PostData = new Dictionary <string, string>();
                MatchCollection             mc       = Regex.Matches(
                    data, "<input type=\"hidden\" name=\"([^\"]*?)\" value=\"([^\"]*?)\" />");
                string key, val;
                foreach (Match m in mc)
                {
                    key           = m.Groups[1].Value;
                    val           = m.Groups[2].Value;
                    PostData[key] = val;
                }
                UpCall.PageQuery(HeroLoc, "start_adventure.php", PostData);
                UpCall.PageQuery(HeroLoc, "build.php?gid=16&tt=1");

                MinimumDelay = Convert.ToInt32(ts.TotalSeconds);
                cur_adv_pt   = tp;
                break;
            }

            if (cur_adv_pt.IsEmpty)
            {
                MinimumDelay = 3600;
                UpCall.DebugLog("探险位置不存在或行程过长", DebugLevel.II);
            }
            else
            {
                UpCall.DebugLog("前往(" + cur_adv_pt.X + "|" + cur_adv_pt.Y + ")探险", DebugLevel.II);
            }
            hero_status = 2;
            UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
            {
                ChangedData = Travian.ChangedType.Queue,
                VillageID   = VillageID
            });
        }