Пример #1
0
        bool SendMail()
        {
            msg.From = new MailAddress(From, UpCall.TD.Server, System.Text.Encoding.UTF8);
            msg.To.Add(To.Join(","));
            msg.Subject         = string.Format("{0}@{1}", UpCall.TD.Server, UpCall.TD.Username);
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body            = this.SmsBody;
            msg.BodyEncoding    = System.Text.Encoding.UTF8;
            msg.IsBodyHtml      = false;
            msg.Priority        = MailPriority.High;

            client.Credentials = new System.Net.NetworkCredential(From, Password);
            client.Host        = this.Host;
            client.Port        = this.Port;
            client.EnableSsl   = this.SSLEnable;
            //client.SendCompleted += new
            //	SendCompletedEventHandler(SendCompletedCallback);
            try
            {
                //client.SendAsync(msg, msg);
                client.Send(msg);
                UpCall.DebugLog("Message sent.", DebugLevel.II);
                return(true);
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                UpCall.DebugLog(ex);
                return(false);
            }
        }
Пример #2
0
		public void Action()
		{
			var CV = UpCall.TD.Villages[VillageID];
			UpCall.PageQuery(VillageID, "build.php?gid=24&a=" + ((int)PartyType).ToString());
			LastExec = DateTime.Now;
			if(CV.InBuilding[5] == null || CV.InBuilding[5].FinishTime < DateTime.Now)
			{
				// error occurred!
				retrycount++;
				if(retrycount > 10)
				{
					UpCall.DebugLog("Error on party for several times! Delete the queue!", DebugLevel.W);
					MarkDeleted = true;
				}
				else
				{
					UpCall.DebugLog("Error on party! Will retry...", DebugLevel.I);
					NextExec = DateTime.Now.AddSeconds(rand.Next(500 + retrycount * 20, 800 + retrycount * 30));
				}
				UpCall.Dirty = true;
			}
			else
			{
				UpCall.BuildCount();
				retrycount = 0;
			}
		}
Пример #3
0
        private bool SendMail()
        {
            MailMessage msg = new MailMessage();

            msg.From = new MailAddress(From, UpCall.TD.Server, System.Text.Encoding.UTF8);
            msg.To.Add(To.Join(","));
            msg.Subject         = string.Format("{0}@{1}", UpCall.TD.Server, UpCall.TD.Username);
            msg.SubjectEncoding = System.Text.Encoding.UTF8;
            msg.Body            = this.SmsBody;
            msg.BodyEncoding    = System.Text.Encoding.UTF8;
            msg.IsBodyHtml      = false;
            msg.Priority        = MailPriority.High;

            SmtpClient client = new SmtpClient(this.Host);

            client.Credentials = new System.Net.NetworkCredential(From, Password);
            client.Port        = this.Port;
            client.EnableSsl   = this.SSLEnable;

            try
            {
                client.Send(msg);
                UpCall.DebugLog("Message sent.", DebugLevel.II);
                return(true);
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                UpCall.DebugLog(ex);
                return(false);
            }
        }
Пример #4
0
 /// <summary>
 /// Remove a item from the village task queue
 /// </summary>
 /// <param name="villageID">Which village the task queue belongs to</param>
 /// <param name="task">The item to delete from the task queue</param>
 private void RemoveQueuedTask()
 {
     MarkDeleted = true;
     UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
     {
         ChangedData = Travian.ChangedType.Queue, VillageID = VillageID
     });
 }
Пример #5
0
        /// <summary>
        /// Wrapper of the real doTransfer function, which
        /// 1) Verify that the tranfer amount is valid (non-zero)
        /// 2) Verify that merchant dispatched for the same mission has returned.
        /// 3) Recalculate the transfer amount for dynamic resource balance
        /// 4) Verify that the transfer won't overflow the arrival village's warehouse/granary
        /// 5) Update task status after a successful merchan dispatch
        /// 6) Remove the task from the village queue when it's no longer valid/needed
        /// </summary>
        public void Action()
        {
            if (!IsValid)
            {
                UpCall.DebugLog("Invalid transfer task discarded: " + Title, DebugLevel.W);
                this.RemoveQueuedTask();
                return;
            }

            if (MinimumDelay > 0)
            {
                return;
            }

            TResAmount toTransfer = new TResAmount(ResourceAmount);

            if (TargetVillageID != 0 &&
                UpCall.TD.Villages.ContainsKey(TargetVillageID) &&
                UpCall.TD.Villages[TargetVillageID].isBuildingInitialized == 2)
            {
                UpCall.PageQuery(TargetVillageID, "build.php?gid=17&t=5");
                CalculateResourceAmount(UpCall.TD, VillageID);

                // check if it's a crop transfer, and crop is seriously needed from target village:
                if (UpCall.TD.Villages[TargetVillageID].Resource[3].Produce < 0)
                {
                    var temp = NeedCrop(UpCall.TD);
                    if (temp != null)
                    {
                        UpCall.DebugLog("NeedCrop rule on use. Force crop transfer.", DebugLevel.I);
                        toTransfer = temp;
                    }
                    else if (ExceedTargetCapacity(UpCall.TD))
                    {
                        return;
                    }
                }
            }
            else
            {
                CalculateResourceAmount(UpCall.TD, VillageID);
            }

            int timeCost = doTransfer(toTransfer, TargetPos);

            UpCall.PageQuery(VillageID, "build.php?gid=17&t=5");
            if (timeCost >= 0)
            {
                var CV = UpCall.TD.Villages[VillageID];
                MinimumDelay = Math.Max(MinimumInterval, timeCost * 2 + 30);
                Count++;
                if (MaxCount != 0 && Count >= MaxCount)
                {
                    RemoveQueuedTask();
                }
            }
        }
Пример #6
0
        private void DoTroopsBack()
        {
            string data = UpCall.PageQuery(VillageID, "build.php?gid=16&tt=1");

            if (data == null)
            {
                MinimumDelay = 0;
                return;
            }
            Match m = Regex.Match(data,
                                  "<a href=\"karte\\.php\\?d=" + tpEvadePoint.Z + "\">[^<]*?</a>"
                                  + ".*?onclick=\"window\\.location\\.href = \'([^\']*?)\'",
                                  RegexOptions.Singleline);

            if (!m.Success)
            {
                evade_status = EvadeStatus.NoAtkDetected;
                MinimumDelay = nMinInterval;
                return;
            }

            string url = m.Groups[1].Value.Replace("amp;", "");

            data = UpCall.PageQuery(VillageID, url);

            if (data == null)
            {
                MinimumDelay = 0;
                return;
            }
            MatchCollection             mc       = Regex.Matches(data, "<input type=\"hidden\" name=\"([^\"]*?)\" value=\"([^\"]*?)\">");
            Dictionary <string, string> postData = new Dictionary <string, string>();

            foreach (Match m1 in mc)
            {
                postData.Add(m1.Groups[1].Value, m1.Groups[2].Value);
            }
            for (int i = 0; i < ReinforceToop.Length; i++)
            {
                if (ReinforceToop[i] == 0)
                {
                    continue;
                }
                string troopKey    = String.Format("t[{0}]", i + 1);
                string troopNumber = ReinforceToop[i].ToString();
                postData.Add(troopKey, troopNumber);
            }
            postData.Add("s1", "ok");
            UpCall.PageQuery(VillageID, "build.php", postData);

            evade_status = EvadeStatus.TroopsBack;
            MinimumDelay = ReinforceTimeCost + RandomDelay(5, 10);
        }
Пример #7
0
 public void InitializeTroop()
 {
     isTroopInitialized = 1;
     if (GetAllTroop)
     {
         UpCall.FetchVillageTroopAll(ID);
     }
     else
     {
         UpCall.FetchVillageTroop(ID);
     }
 }
Пример #8
0
        private TimeSpan CheckDurAvail(string dur)
        {
            TimeSpan ts = UpCall.TimeSpanParse(dur);

            if (ts.TotalSeconds <= 3600 * 3)
            {
                return(ts);
            }
            else
            {
                return(TimeSpan.MinValue);
            }
        }
Пример #9
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);
        }
Пример #10
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;
            }
        }
Пример #11
0
        public void Action()
        {
            //	当前时刻还未到唤醒时刻
            if (MinimumDelay > 0)
            {
                return;
            }

            var cv = UpCall.TD.Villages[VillageID];

            if (!HasGetAll)
            {
                string data = UpCall.PageQuery(VillageID, "build.php?gid=16&tt=1");
                InitAttackers();
            }


            foreach (TTInfo tt in cv.Troop.Troops)
            {
                AddAtacker(tt);
            }

            if (BeAttacked)
            {
                AnalizeAttacker();

                if (SendMail())
                {
                    TotalCount++;
                    this.MinimumDelay = this.MinimumInterval + new Random().Next(60, 300);
                }
                else
                {
                    this.MinimumDelay = new Random().Next(300, 600);
                }
            }
            else
            {
                this.MinimumDelay = this.MinimumInterval + new Random().Next(60, 300);
            }

            //	延迟时间需要超过最小时间间隔,唤醒时刻到达后才会重新刷新集结点
            HasGetAll = !(this.MinimumDelay > this.MinimumInterval);
        }
Пример #12
0
        public void Action()
        {
            TVillage village = UpCall.TD.Villages[VillageID];

            if (!IsValid)
            {
                UpCall.DebugLog("Invalid NPC trade task discarded: " + ToString(), DebugLevel.W);
                RemoveQueuedTask();
                return;
            }

            if (CountDown > 0)
            {
                return;
            }

            NpcTradeResult returnCode = doNpcTrade();

            switch (returnCode)
            {
            case NpcTradeResult.Failure:
                UpCall.DebugLog("NPC trade task has failed: " + ToString(), DebugLevel.W);
                RemoveQueuedTask();
                return;

            case NpcTradeResult.Delay:
                // Wait at least 10 minutes before retrying
                MinimumDelay = 600;
                break;

            case NpcTradeResult.Success:
                Count++;
                if (MaxCount != 0 & Count >= MaxCount)
                {
                    RemoveQueuedTask();
                    return;
                }

                // This is an unfinished multiple NPC trade task, wait at least 1 hr
                MinimumDelay = 3600;
                break;
            }
        }
Пример #13
0
        public void Action()
        {
            if (MinimumDelay > 0)
            {
                return;
            }

            int    page = 1;
            string link, data;
            int    result    = -1;
            bool   mail_sent = false;

            ClearPMSender();
            do
            {
                link   = "nachrichten.php?&o=0&page=" + page.ToString();
                data   = UpCall.PageQuery(VillageID, link);
                result = PMParse(data);
                if (result == 1)
                {
                    page++;
                }

                if (result != -1 && SendMail() == true && mail_sent == false)
                {
                    mail_sent = true;
                }
            } while (result == 1);

            if (mail_sent)
            {
                TotalCount++;
                this.MinimumDelay = this.MinimumInterval + new Random().Next(0, 60);
            }
            else
            {
                this.MinimumDelay = new Random().Next(60, 120);
            }
        }
Пример #14
0
        public void Action()
        {
            var CV = UpCall.TD.Villages[VillageID];

            if (NextExec >= DateTime.Now)
            {
                return;
            }
            NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300));
            Dictionary <string, string> Postdata = new Dictionary <string, string>()
            {
                { "gid", "15" },
                { "a", VillageID.ToString() },
                { "abriss", Bid.ToString() },
                { "ok", "%E6%8B%86%E6%AF%81" }
            };

            UpCall.PageQuery(VillageID, "build.php", Postdata);

            int lvl = CV.InBuilding[2] != null && CV.InBuilding[2].FinishTime > DateTime.Now ? CV.InBuilding[2].Level : -1;

            if (lvl < 0)
            {
                UpCall.DebugLog("Unknown state: Destroy to -1", DebugLevel.W);
            }
            if (lvl <= 0)
            {
                MarkDeleted  = true;
                UpCall.Dirty = true;
                UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                {
                    ChangedData = Travian.ChangedType.Queue,
                    VillageID   = VillageID
                });
            }
            UpCall.BuildCount();
        }
Пример #15
0
        public void Action()
        {
            //	当前时刻还未到唤醒时刻
            if (MinimumDelay > 0)
            {
                return;
            }

            if (evade_status == EvadeStatus.NoAtkDetected ||
                evade_status == EvadeStatus.AtkDetected ||
                evade_status == EvadeStatus.TroopsBack)
            {
                CheckAttack();
            }
            else if (evade_status == EvadeStatus.ReadyForEvade)
            {
                DoEvade();
            }
            else if (evade_status == EvadeStatus.Evaded ||
                     evade_status == EvadeStatus.ReadyForBack)
            {
                evade_status = EvadeStatus.ReadyForBack;
                DoTroopsBack();
            }
            else
            {
                evade_status = EvadeStatus.NoAtkDetected;
                MinimumDelay = nMinInterval;
            }

            UpCall.TD.Dirty = true;
            UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
            {
                ChangedData = Travian.ChangedType.Queue, VillageID = VillageID
            });
        }
Пример #16
0
 public void StopFindOasis()
 {
     UpCall.StopFindOasis();
 }
Пример #17
0
        public void Action()
        {
            if (CountDown > 0)
            {
                return;
            }
            int key = (UpCall.TD.Tribe - 1) * 10 + Aid;
            int Gid;

            Gid = GRt ? AIDMapg[key] : AIDMap[key];

            if (GRt && (Aid == 7 || Aid == 8) || Gid == 0)
            {
                UpCall.DebugLog("Not appropriate kind of troop to produce, deleted.", DebugLevel.W);
                MarkDeleted = true;
                return;
            }
            string url = "build.php?gid=" + Gid;

            if (Gid == 25)
            {
                url += "&s=1";
            }
            string data = UpCall.PageQuery(VillageID, url);

            if (data == null)
            {
                return;
            }
            if (!data.Contains(string.Format("name=\"t{0}\"", Aid)))
            {
                UpCall.DebugLog("Cannot produce this kind of troop before research it.", DebugLevel.W);
                MarkDeleted = true;
                return;
            }

            /*
             * id	34
             * z	10021
             * a	2
             * t1	2000
             * t3	0
             * s1.x	60
             * s1.y	16
             * s1	ok
             * <input type="hidden" name="id" value="34">
             * <input type="hidden" name="z" value="65535">
             * <input type="hidden" name="a" value="2">
             *
             */
            string p_a, p_id, p_z;
            Match  m;

            m = Regex.Match(data, "type=\"hidden\" name=\"id\" value=\"(\\d+?)\"");
            if (m.Success)
            {
                p_id = m.Groups[1].Value;
            }
            else
            {
                UpCall.DebugLog("Parse id error!", DebugLevel.F);
                MarkDeleted = true;
                return;
            }
            m = Regex.Match(data, "type=\"hidden\" name=\"z\" value=\"(\\w+?)\"");
            if (m.Success)
            {
                p_z = m.Groups[1].Value;
            }
            else
            {
                UpCall.DebugLog("Parse z error!", DebugLevel.F);
                MarkDeleted = true;
                return;
            }
            m = Regex.Match(data, "type=\"hidden\" name=\"a\" value=\"(\\d+?)\"");
            if (m.Success)
            {
                p_a = m.Groups[1].Value;
            }
            else
            {
                UpCall.DebugLog("Parse a error!", DebugLevel.F);
                MarkDeleted = true;
                return;
            }
            Dictionary <string, string> PostData = new Dictionary <string, string>();

            PostData["id"]      = p_id;
            PostData["z"]       = p_z;
            PostData["a"]       = p_a;
            PostData["s1.x"]    = rand.Next(10, 70).ToString();
            PostData["s1.y"]    = rand.Next(3, 17).ToString();
            PostData["s1"]      = "ok";
            PostData["t" + Aid] = Amount.ToString();
            data     = UpCall.PageQuery(VillageID, "build.php", PostData);
            LastExec = DateTime.Now;
            NextExec = LastExec.AddSeconds(MinimumInterval);
            Count++;
            if (MaxCount != 0 && Count >= MaxCount)
            {
                MarkDeleted = true;
            }
        }
Пример #18
0
        public void Action()
        {
            if (CountDown > 0)
            {
                return;
            }
            if (Targets[TargetID].IsEmpty)
            {
                UpCall.DebugLog("Target Is Error!!", DebugLevel.F);
                MarkDeleted = true;
                return;
            }
            if (Settlers)
            {
                var result = UpCall.PageQuery(VillageID, "build.php?id=39&tt=2&z=" + Targets[TargetID].Z.ToString());
                if (result == null)
                {
                    return;
                }
                Match m;
                m = Regex.Match(result, "type=\"submit\" value=\"ok\" name=\"s1\"");
                if (m.Success)
                {
                    Dictionary <string, string> PostDataST = new Dictionary <string, string>();
                    PostDataST["a"]    = "1";
                    PostDataST["s"]    = Targets[TargetID].Z.ToString();
                    PostDataST["id"]   = "39";
                    PostDataST["s1.x"] = rand.Next(40, 70).ToString();
                    PostDataST["s1.y"] = rand.Next(3, 17).ToString();
                    PostDataST["s1"]   = "ok";
                    var datast = UpCall.PageQuery(VillageID, "build.php", PostDataST);
                }
                else
                {
                    UpCall.DebugLog("Unable to Settlers", DebugLevel.F);
                }
                MarkDeleted = true;
                return;
            }
            List <Dictionary <string, string> > PostDataALL = new List <Dictionary <string, string> >();

            for (int w = 0; w < wWaves.Count; w++)
            {
                for (int j = 0; j < wWaves[w]; j++)
                {
                    Dictionary <string, string> PostData = new Dictionary <string, string>();
                    var   data = UpCall.PageQuery(VillageID, "build.php?tt=2&id=39");
                    Match m10;
                    m10 = Regex.Match(data, "type=\"hidden\" name=\"timestamp\" value=\"([^>]*?)\"");
                    string p_timestamp = m10.Groups[1].Value;
                    Match  m11;
                    m11 = Regex.Match(data, "type=\"hidden\" name=\"timestamp_checksum\" value=\"([^>]*?)\"");
                    string p_timestamp_checksum = m11.Groups[1].Value;
                    PostData["timestamp"]          = p_timestamp;
                    PostData["timestamp_checksum"] = p_timestamp_checksum;
                    PostData["b"]     = "1";
                    PostData["dname"] = "";
                    PostData["x"]     = Targets[TargetID].X.ToString();
                    PostData["y"]     = Targets[TargetID].Y.ToString();
                    PostData["s1.x"]  = rand.Next(40, 70).ToString();
                    PostData["s1.y"]  = rand.Next(3, 17).ToString();
                    PostData["s1"]    = "ok";
                    if (Raidtype > 4)
                    {
                        PostData["c"] = "4";
                    }
                    else
                    {
                        PostData["c"] = Raidtype.ToString();
                    }
                    for (int i = 1; i < 12; i++)
                    {
                        PostData["t" + i] = wTroops[w].Troops[i - 1].ToString();
                    }

                    Dictionary <string, string> PostDataF = new Dictionary <string, string>();
                    var result = UpCall.PageQuery(VillageID, "build.php?tt=2&id=39", PostData);
                    if (result.Contains("<p class=\"error\">"))
                    {
                        UpCall.DebugLog("Target is Error!!", DebugLevel.W);
                        MarkDeleted = true;
                        return;
                    }
                    Match m20;
                    m20 = Regex.Match(result, "type=\"hidden\" name=\"timestamp\" value=\"([^>]*?)\"");
                    string p_timestampF = m20.Groups[1].Value;
                    Match  m21;
                    m21 = Regex.Match(result, "type=\"hidden\" name=\"timestamp_checksum\" value=\"([^>]*?)\"");
                    string p_timestamp_checksumF = m21.Groups[1].Value;
                    Match  m22;
                    m22 = Regex.Match(result, "type=\"hidden\" name=\"a\" value=\"(\\d+?)\"");
                    string p_aF = m22.Groups[1].Value;
                    PostDataF["timestamp"]          = p_timestampF;
                    PostDataF["timestamp_checksum"] = p_timestamp_checksumF;
                    PostDataF["a"] = p_aF;
                    //2 RE,3 Nor,4 Raid, 5 SPY1, 6 SPY2
                    if (Raidtype > 4)
                    {
                        PostDataF["c"] = "4";
                        int Tribe = UpCall.TD.Tribe;
                        int spy   = Raidtype - 4;
                        PostDataF["spy"] = spy.ToString();
                        if (Tribe == 3 && wTroops[w].Troops[2] != 0)
                        {
                            PostDataF["t3"] = wTroops[w].Troops[2].ToString();
                        }
                        else if ((Tribe == 1 || Tribe == 2) && wTroops[w].Troops[3] != 0)
                        {
                            PostDataF["t4"] = wTroops[w].Troops[3].ToString();
                        }
                        else
                        {
                            UpCall.DebugLog("NO SCOUT TROOPS", DebugLevel.W);
                            MarkDeleted = true;
                            return;
                        }
                    }
                    else
                    {
                        PostDataF["c"] = Raidtype.ToString();
                        for (int i = 1; i < 12; i++)
                        {
                            PostDataF["t" + i] = wTroops[w].Troops[i - 1].ToString();
                        }
                    }
                    if (Raidtype == 3 && (wTroops[w].Troops[7] != 0))
                    {
                        int RP    = UpCall.TD.Villages[VillageID].Buildings[39].Level;
                        int tkata = GIDMap[kata];
                        if (tkata == 0 || RP < 10)
                        {
                            tkata = 99;
                        }
                        PostDataF["kata"] = tkata.ToString();
                        if ((wTroops[w].Troops[7] >= 20) && (RP == 20))
                        {
                            int tkata2 = GIDMap[kata2];
                            PostDataF["kata2"] = tkata2.ToString();
                        }
                    }
                    PostDataF["kid"]  = Targets[TargetID].Z.ToString();
                    PostDataF["id"]   = "39";
                    PostDataF["s1.x"] = rand.Next(40, 70).ToString();
                    PostDataF["s1.y"] = rand.Next(3, 17).ToString();
                    PostDataF["s1"]   = "ok";

                    PostDataALL.Add(PostDataF);
                }
            }
            //POST ALL Attack
            for (int i = 0; i < PostDataALL.Count; i++)
            {
                UpCall.PageQuery(VillageID, "build.php?tt=2&id=39", PostDataALL[i]);
            }
            Wave++;
            if (TargetID == Targets.Count - 1)
            {
                MarkDeleted = true;
            }
            else
            {
                LastExec = DateTime.Now;
                NextExec = LastExec.AddSeconds(MinimumInterval);
                TargetID++;
            }
        }
Пример #19
0
 public void InitializeBuilding()
 {
     isBuildingInitialized = 1;
     UpCall.FetchVillageBuilding(ID);
 }
Пример #20
0
 public void InitializeUpgrade()
 {
     isUpgradeInitialized = 1;
     UpCall.FetchVillageUpgrade(ID);
 }
Пример #21
0
        /// <summary>
        /// Trade resource with NPC with 1:1 rate (after paying 3 gold)
        /// </summary>
        public NpcTradeResult doNpcTrade()
        {
            // Get NPC trade form
            string result = UpCall.PageQuery(VillageID, "build.php?gid=17&t=3");

            if (result == null)
            {
                return(NpcTradeResult.Failure);
            }

            // Parse capacity and sum
            Match match = Regex.Match(result, "var summe=(?<summe>\\d+);var max123=(?<max123>\\d+);var max4=(?<max4>\\d+);");

            if (!match.Success)
            {
                return(NpcTradeResult.Failure);
            }

            int sum = Int32.Parse(match.Groups["summe"].Value);

            // Parse id
            match = Regex.Match(result, "<input type=\"hidden\" name=\"id\" value=\"(?<id>\\d+)\"");
            if (!match.Success)
            {
                return(NpcTradeResult.Failure);
            }

            string id = match.Groups["id"].Value;

            // Parse c
            match = Regex.Match(result, "<input type=\"hidden\" name=\"c\" value=\"(?<c>[^>]*?)\"");
            if (!match.Success)
            {
                return(NpcTradeResult.Failure);
            }

            string c = match.Groups["c"].Value;

            // Parse m1[] and m2[]
            MatchCollection matches = Regex.Matches(result, "<input type=\"hidden\" name=\"m1\\[\\]\" value=\"(?<m1>\\d+)\"");

            if (matches.Count != 4)
            {
                return(NpcTradeResult.Failure);
            }

            TResAmount m1 = new TResAmount(new int[matches.Count]);

            for (int i = 0; i < matches.Count; i++)
            {
                m1.Resources[i] = Int32.Parse(matches[i].Groups["m1"].Value);
            }

            // Does m1 exceeds threshold?
            for (int i = 0; i < m1.Resources.Length; i++)
            {
                if (m1.Resources[i] < Threshold.Resources[i])
                {
                    return(NpcTradeResult.Delay);
                }
            }

            // Compute m2
            TResAmount m2 = RedistributeResources(UpCall.TD, VillageID, sum);

            if (m2 == null)
            {
                return(NpcTradeResult.Delay);
            }

            // Prepare data
            Dictionary <string, string> postData = new Dictionary <string, string>();

            postData["id"] = id;
            postData["t"]  = "3";
            postData["a"]  = "6";
            postData["c"]  = c;

            StringBuilder sb = new StringBuilder();

            for (int i = 0; i < m2.Resources.Length; i++)
            {
                if (i > 0)
                {
                    sb.Append("&");
                }

                sb.AppendFormat("m2[]={0}&m1[]={1}", m2.Resources[i], m1.Resources[i]);
            }

            postData["!!!RawData!!!"] = sb.ToString();

            // Post form
            result = UpCall.PageQuery(VillageID, "build.php", postData);
            if (result == null)
            {
                return(NpcTradeResult.Failure);
            }

            match = Regex.Match(result, "<b>3</b>[^<]*?</p><script language=\"JavaScript\">var summe=");
            if (!match.Success)
            {
                return(NpcTradeResult.Failure);
            }

            UpCall.DebugLog(string.Format("NPC trade {0} -> {1} ({2}) ", m1, m2, VillageID), DebugLevel.I);
            UpCall.BuildCount();
            return(NpcTradeResult.Success);
        }
Пример #22
0
 public void StopFindAnimals()
 {
     UpCall.StopFindAnimals();
 }
Пример #23
0
        private bool FetchAvailGidAndBidWithlvl(TVillage CV, out int gid, out int bid)
        {
            bid = -1;
            gid = 0;

            //	按资源田等级
            int i;
            int minlevel = 10;

            int[] buildpriority   = new int[5];
            bool  bIsCroopsAbove5 = false;

            //	以粮食的最低等级划分判定区域,避免初期粮食过少
            for (i = 1; i <= 18; i++)
            {
                if (!CV.Buildings.ContainsKey(i) || CV.Buildings[i].Gid != 4)
                {
                    continue;
                }
                var tlevel = CV.Buildings[i].Level;
                if (tlevel < minlevel)
                {
                    minlevel = tlevel;
                }
            }

            if (minlevel >= 5)
            {
                bIsCroopsAbove5 = true;
            }

            minlevel = 10;

            //	找到所有资源田的最低等级
            for (i = 1; i <= 18; i++)
            {
                if (!CV.Buildings.ContainsKey(i))
                {
                    continue;
                }

                var tlevel = 0;
                if (bIsCroopsAbove5)
                {
                    tlevel = CV.Buildings[i].Gid != 4 ? CV.Buildings[i].Level : CV.Buildings[i].Level + 1;
                }
                else
                {
                    tlevel = CV.Buildings[i].Level;
                }
                if (tlevel < minlevel)
                {
                    minlevel = tlevel;
                }
            }

            //	找到等级最低资源田的种类和坑号
            int min = 1;

            for (i = 1; i <= 18; i++)
            {
                if (!CV.Buildings.ContainsKey(i))
                {
                    continue;
                }

                var tlevel = 0;
                if (bIsCroopsAbove5)
                {
                    tlevel = CV.Buildings[i].Gid != 4 ? CV.Buildings[i].Level : CV.Buildings[i].Level + 1;
                }
                else
                {
                    tlevel = CV.Buildings[i].Level;
                }
                if (tlevel == minlevel && buildpriority[CV.Buildings[i].Gid] == 0)
                {
                    min = CV.Buildings[i].Gid - 1;
                    buildpriority[CV.Buildings[i].Gid] = i;
                }
            }

            //	如果有多种资源田同级,则按资源的评估比率确定升级的资源田
            for (i = 0; i < 4; i++)
            {
                if (CV.Resource[min].CurrAmount / Travian.resrate[min] >
                    CV.Resource[i].CurrAmount / Travian.resrate[i] &&
                    buildpriority[i + 1] != 0)
                {
                    min = i;
                }
            }
            gid = min + 1;
            bid = buildpriority[gid];

            //	如果最低等级为10级,则查找等级低于10级的粮食
            if (minlevel == 10)
            {
                bool croop = false;
                for (i = 1; i <= 18; i++)
                {
                    if (!CV.Buildings.ContainsKey(i))
                    {
                        continue;
                    }
                    var tlevel = CV.Buildings[i].Level;
                    if (tlevel < 10)
                    {
                        gid   = CV.Buildings[i].Gid;
                        bid   = i;
                        croop = true;
                        break;
                    }
                }

                int finish_cnt = 0;
                for (i = 19; i <= 40; i++)
                {
                    if (!CV.Buildings.ContainsKey(i))
                    {
                        continue;
                    }

                    for (int j = 0; j < Goal.Length; j++)
                    {
                        if (CV.Buildings[i].Gid == Goal[j].gid &&
                            CV.Buildings[i].Level == Goal[j].limit_lvl)
                        {
                            finish_cnt++;
                            break;
                        }
                    }
                }

                //	如果所有资源田都满级了,那么删除掉该任务
                if (croop == false && finish_cnt == Goal.Length && CV.Queue.Contains(this))
                {
                    MarkDeleted     = true;
                    UpCall.TD.Dirty = true;
                    UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                    {
                        ChangedData = Travian.ChangedType.Queue,
                        VillageID   = VillageID
                    });
                    return(false);
                }
            }

            return(true);
        }
Пример #24
0
 //	搜田
 public void FindOasis(int x, int y, int num)
 {
     UpCall.FindOasis(ID, x, y, num);
 }
Пример #25
0
 public void InitializeDestroy()
 {
     isDestroyInitialized = 1;
     UpCall.FetchVillageDestroy(ID);
 }
Пример #26
0
        public void Action()
        {
            var    CV = UpCall.TD.Villages[VillageID];
            int    GID;
            var    Q = this;
            string mat_str, id, c;
            Match  m;
            string result;

            switch (ResearchType)
            {
            case TResearchType.Research:
                if (!CV.Upgrades[Aid].CanResearch)
                {
                    MarkDeleted  = true;
                    UpCall.Dirty = true;
                    UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                    {
                        ChangedData = Travian.ChangedType.Queue, VillageID = VillageID
                    });
                    return;
                }
                GID    = 22;
                result = UpCall.PageQuery(VillageID, "build.php?gid=" + GID.ToString());
                if (result == null)
                {
                    return;
                }
                mat_str = "'build.php\\?id=(\\d+)&amp;a=" + Aid.ToString() + "&amp;c=([^']*?)'";
                m       = Regex.Match(result, mat_str);
                if (!m.Success)
                {
                    return;
                }
                id     = m.Groups[1].Value;
                c      = m.Groups[2].Value;
                result = UpCall.PageQuery(VillageID, "build.php?id=" + id + "&a=" + Aid.ToString() + "&c=" + c);
                break;

            case TResearchType.UpTroopLevel:
                if (TargetLevel != 0 && CV.Upgrades[Aid].troop_lvl >= TargetLevel || CV.Upgrades[Aid].troop_lvl >= CV.SmithyLevel)
                {
                    MarkDeleted  = true;
                    UpCall.Dirty = true;
                    UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                    {
                        ChangedData = Travian.ChangedType.Queue, VillageID = VillageID
                    });
                    return;
                }
                GID    = 13;
                result = UpCall.PageQuery(VillageID, "build.php?gid=" + GID.ToString());
                if (result == null)
                {
                    return;
                }
                mat_str = "'build.php\\?id=(\\d+)&amp;a=" + Aid.ToString() + "&amp;c=([^']*?)'";
                m       = Regex.Match(result, mat_str, RegexOptions.Singleline);
                if (!m.Success)
                {
                    return;
                }
                id     = m.Groups[1].Value;
                c      = m.Groups[2].Value;
                result = UpCall.PageQuery(VillageID, "build.php?id=" + id + "&a=" + Aid.ToString() + "&c=" + c);
                break;

            default:
                return;
            }
            UpCall.BuildCount();

            if (TargetLevel == 0 || ResearchType == TResearchType.Research)
            {
                MarkDeleted  = true;
                UpCall.Dirty = true;
                UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                {
                    ChangedData = Travian.ChangedType.Queue, VillageID = VillageID
                });
            }
            else if (ResearchType == TResearchType.UpTroopLevel)
            {
                if (CV.Upgrades[Aid].troop_lvl >= TargetLevel || CV.Upgrades[Aid].troop_lvl >= CV.SmithyLevel)
                {
                    MarkDeleted  = true;
                    UpCall.Dirty = true;
                    UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
                    {
                        ChangedData = Travian.ChangedType.Queue, VillageID = VillageID
                    });
                }
            }

            UpCall.CallStatusUpdate(this, new Travian.StatusChanged()
            {
                ChangedData = Travian.ChangedType.Research, VillageID = VillageID
            });
        }
Пример #27
0
        public void Action()
        {
            TVillage CV = this.UpCall.TD.Villages[VillageID];

            if (this.NextExec >= DateTime.Now)
            {
                return;
            }

            this.NextExec = DateTime.Now.AddSeconds(50);

            if (CV.isBuildingInitialized != 2)
            {
                return;
            }

            int gid, bid;

            if (AIType == TAIType.Resource)
            {
                if (!FetchAvailGidAndBidWithRes(CV, out gid, out bid))
                {
                    return;
                }
            }
            else
            {
                if (!FetchAvailGidAndBidWithlvl(CV, out gid, out bid))
                {
                    return;
                }
            }

            if (!CV.Buildings.ContainsKey(bid))
            {
                return;
            }
            int[] costs = Buildings.Cost(gid, CV.Buildings[bid].Level + 1).Resources;
            int   inside_gid, insid_bid;

            if (FetchAvailInsideBuilding(CV, costs, out inside_gid, out insid_bid))
            {
                gid = inside_gid;
                bid = insid_bid;
            }

            UpCall.DebugLog("AIQueue准备建造 " + DisplayLang.Instance.GetGidLang(gid)
                            + " @" + bid, DebugLevel.II);
            var BQ = new BuildingQueue()
            {
                Bid       = bid,
                Gid       = gid,
                UpCall    = UpCall,
                VillageID = VillageID
            };

            Gid = gid;

            int cd = BQ.CountDown;

            if (cd <= 0)
            {
                UpCall.DebugLog("AIQueue建筑队列启动!", DebugLevel.II);
                BQ.Action();
            }
            else
            {
                int delay = Math.Min(15 * 60, cd);
                UpCall.DebugLog("AIQueue建筑队列未能启动,建造该单位尚需等待" + cd
                                + "秒;将于" + delay + "秒后再检查一次。"
                                , DebugLevel.II);
                this.NextExec = DateTime.Now.AddSeconds(delay);
                //	为了防止资源未刷新而引起的问题
                UpCall.PageQuery(VillageID, "dorf1.php");
            }
        }
Пример #28
0
 //	找野兽
 public void FindAnimals(FindAnimalsOption option)
 {
     option.VillageID = ID;
     UpCall.FindAnimals(option);
 }
Пример #29
0
        private DoRaidResult DoRaid()
        {
            if (this.MinimumDelay > 0)
            {
                return(DoRaidResult.Postpone);
            }

            string sendTroopsUrl = String.Format("build.php?id=39&tt=2&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=\"build.php?id=39&amp;tt=2\">"))
            {
                return(DoRaidResult.SkipVillage);
            }

            if (!UpCall.NoAnimals(VillageID, Targets[this.TargetID].X, Targets[this.TargetID].Y))
            {
                UpCall.DebugLog("跳过有野怪的绿洲", DebugLevel.II);
                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  = "build.php?id=39&tt=2";
            string confirmForm = UpCall.PageQuery(this.VillageID, confirmUrl, postData);

            if (confirmForm == null)
            {
                return(DoRaidResult.SkipVillage);
            }

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

            if (errorMatch.Success)
            {
                string err_msg = errorMatch.Groups[1].Value;
                err_msg = err_msg.Replace("<span>", "");
                err_msg = err_msg.Replace("</span>", "");
                string error = String.Format(
                    "Delete village {0}. Error: {1}",
                    this.Targets[this.TargetID], err_msg);
                this.UpCall.DebugLog(error, DebugLevel.W);
                return(DoRaidResult.DeleteVillage);
            }

            if (!confirmForm.Contains("<form method=\"post\" action=\"build.php?id=39&amp;tt=2\">"))
            {
                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(30, 180);
            }

            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);
        }
Пример #30
0
 public void InitializeMarket()
 {
     isMarketInitialized = 1;
     UpCall.FetchVillageMarket(ID);
 }