public int testPossibleNow(int VillageID, BuildingQueue Q) { var CV = TD.Villages[VillageID]; if (CV.Buildings.ContainsKey(Q.Bid) && CV.Buildings[Q.Bid].Gid == Q.Gid && CV.Buildings[Q.Bid].Level != 0) { return(Buildings.CheckLevelFull(Q.Gid, CV.Buildings[Q.Bid].Level, CV.isCapital) ? -1 : 0); } return(testPossibleNewNow(TD.Tribe, TD.Villages, CV, Q.Gid, Q.Bid)); }
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"); } }
public void Action() { BuildingQueue Q = this; var CV = UpCall.TD.Villages[VillageID]; if(Q.NextExec >= DateTime.Now) return; Q.NextExec = DateTime.Now.AddSeconds(60); int Bid = UpCall.testPossibleNow(VillageID, Q); // -1表示目前无法建造 if(Bid == -1) { Q.MarkDeleted = true; UpCall.DebugLog("Delete Queue [" + Q.Title + "] because it's impossible to build it.", DebugLevel.W); return; } // 0表示建造该建筑先要造某种别的建筑 if(Bid != 0) { UpCall.DebugLog("Queue [" + Q.Title + "] needs Bid=" + Bid.ToString() + " to be extended.", DebugLevel.I); Q = new BuildingQueue() { UpCall = UpCall, Bid = Bid, Gid = CV.Buildings[Bid].Gid }; UpCall.DebugLog("Create Queue [" + Q.Title + "] because it needs to be extended.", DebugLevel.I); } int bid = Q.Bid; int gid = Q.Gid; string result; result = UpCall.PageQuery(VillageID, "dorf1.php"); if(result == null) return; List<int> nMilitaries = new List<int> {13, 14, 19, 20, 21, 22, 29, 30, 31, 32, 33, 36, 37}; List<int> nResources = new List<int> {5, 6, 7, 8, 9}; string url = "build.php?id=" + bid.ToString(); if (nMilitaries.Contains(gid)) { url += "&category=2"; } else if (nResources.Contains(gid)) { url += "&category=3"; } else if (gid == 17) { url += "&t=0"; } result = UpCall.PageQuery(VillageID, url); if(result == null) return; // m用来解析新建建筑,n用来解析建筑升级 Match m, n; m = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + gid + "&id=" + bid + "&c=[^\']*?)';\\sreturn"); n = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + bid + "&c=[^\']*?)';\\sreturn"); if(!m.Success && !n.Success) { // check reason /* * <span class="c">已经有建筑在建造中</span> * <div class="c">资源不足</div> * <p class="c">伐木场建造完成</p> * <span class="c">建造所需资源超过仓库容量上限,请先升级你的仓库</span> * <span class="c">粮食产量不足: 需要先建造一个农场</span> * */ int RomaNeedCrop = -1; // 仓库容量不足的话,先造仓库 if(gid != 10 && UpCall.GidLang.ContainsKey(10) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(10) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 10; bid = findBuilding(VillageID, gid); } // 粮食产量不足的话,先造农场 else if (gid != 11 && UpCall.GidLang.ContainsKey(11) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(11) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 11; bid = findBuilding(VillageID, gid); } else if (gid != 4 && UpCall.GidLang.ContainsKey(4) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(4) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { if (UpCall.TD.isRomans && CV.InBuilding[0] != null && Q.Bid > 18) { if (CV.InBuilding[0].Gid != 4) RomaNeedCrop = 1; else if (CV.InBuilding[0].Gid == 4) { RomaNeedCrop = 0; return; } UpCall.DebugLog("Roma NEED Crop rule", DebugLevel.W); Q.NextExec = CV.InBuilding[0].FinishTime.AddSeconds(30); } gid = 4; bid = findBuilding(VillageID, gid); } else if (result.Contains("<p class=\"(c|none)\">")) { UpCall.DebugLog("Unexpected status! Report it on the forum! " + Q.Title, DebugLevel.W); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } else if (UpCall.GidLang.ContainsKey(gid) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(gid) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) return; else if (result.Contains("<span class=\"(c|none)\">")) { //Q.Delay = rand.Next(500, 1000); // Delay shouldn't happen. Q.NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300)); UpCall.DebugLog("Data not refreshed? Add delay for " + Q.Title, DebugLevel.I); return; } else { UpCall.PageQuery(VillageID, "dorf1.php"); UpCall.PageQuery(VillageID, "dorf2.php"); UpCall.DebugLog("Unknown status! And cause a queue been deleted! " + Q.Title, DebugLevel.W); //Q.MarkDeleted = true; //UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); Q.NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300)); return; } // 检查资源是否足够 int timecost; if(CV.Buildings.ContainsKey(bid)) timecost = CV.TimeCost(Buildings.Cost(gid, CV.Buildings[bid].Level + 1)); else timecost = CV.TimeCost(Buildings.Cost(gid, 1)); if(CV.InBuilding[UpCall.TD.isRomans && bid > 18 ? 1 : 0] != null) timecost = Math.Max(timecost, Convert.ToInt32(DateTime.Now.Subtract(CV.InBuilding[UpCall.TD.isRomans && bid > 18 ? 1 : 0].FinishTime).TotalSeconds)); if(timecost > 0 || RomaNeedCrop == 1) { UpCall.DebugLog("Need to build but resource not enough so add into queue: " + Q.Title, DebugLevel.I); CV.Queue.Insert(0, new BuildingQueue() { UpCall = UpCall, VillageID = VillageID, Bid = bid, Gid = gid }); UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } result = UpCall.PageQuery(VillageID, "build.php?id=" + bid.ToString()); if(result == null) return; m = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + gid + "&id=" + bid + "&c=[^\']*?)'"); n = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + bid + "&c=[^\']*?)'"); if(!m.Success && !n.Success) { UpCall.DebugLog("Unknown error on building " + Q.Title, DebugLevel.E); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } } // New building int qtype = bid < 19 && bid > 0 ? 0 : 1; if(CV.Buildings.ContainsKey(bid)) CV.RB[UpCall.TD.isRomans ? qtype : 0] = new TInBuilding() { ABid = bid, Gid = gid, Level = CV.Buildings[bid].Level }; else CV.RB[UpCall.TD.isRomans ? qtype : 0] = new TInBuilding() { ABid = bid, Gid = gid, Level = 1 }; // 执行建造操作 string uri; if(m.Success) { uri = m.Groups[1].Value.Replace("amp;", ""); UpCall.PageQuery(VillageID, uri); } else { uri = n.Groups[1].Value.Replace("amp;", ""); UpCall.PageQuery(VillageID, uri); } UpCall.BuildCount(); if(Q.Bid == bid) UpCall.DebugLog("Build " + Q.Title, DebugLevel.I); else UpCall.DebugLog("Build (other) " + Q.Title, DebugLevel.I); if(Q.Bid == bid) { if(Q.TargetLevel == 0 || Q.TargetLevel <= CV.Buildings[bid].Level) { Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); } } UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Buildings, VillageID = VillageID }); }
public void Action() { BuildingQueue Q = this; var CV = UpCall.TD.Villages[VillageID]; if (Q.TargetLevel != 0 && CV.Buildings.ContainsKey(Q.Bid) && CV.Buildings[Q.Bid].Gid == Q.Gid && CV.Buildings[Q.Bid].Level >= Q.TargetLevel) { Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } if(Q.NextExec >= DateTime.Now) return; Q.NextExec = DateTime.Now.AddSeconds(60); int Bid = UpCall.testPossibleNow(VillageID, Q); if(Bid == -1) { Q.MarkDeleted = true; UpCall.DebugLog("Delete Queue [" + Q.Title + "] because it's impossible to build it.", DebugLevel.W); UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } if(Bid != 0) { UpCall.DebugLog("Queue [" + Q.Title + "] needs Bid=" + Bid.ToString() + " to be extended.", DebugLevel.W); Q = new BuildingQueue() { UpCall = UpCall, Bid = Bid, Gid = CV.Buildings[Bid].Gid }; UpCall.DebugLog("Create Queue [" + Q.Title + "] because it needs to be extended.", DebugLevel.W); } int bid = Q.Bid; int gid = Q.Gid; string result; result = UpCall.PageQuery(VillageID, "dorf1.php"); if(result == null) return; result = UpCall.PageQuery(VillageID, "build.php?id=" + bid.ToString()); if(result == null) return; Match m, n; m = Regex.Match(result, "dorf(\\d)\\.php\\?a=" + gid + "&(?:amp;)?id=" + bid + "&(?:amp;)?c=[^\"]*"); n = Regex.Match(result, "dorf(\\d)\\.php\\?a=" + bid + "&(?:amp;)?c=[^\"&]*\""); if(!m.Success && !n.Success) { // check reason /* * <span class="c">已经有建筑在建造中</span> * <div class="c">资源不足</div> * <p class="c">伐木场建造完成</p> * <span class="c">建造所需资源超过仓库容量上限,请先升级你的仓库</span> * <span class="c">粮食产量不足: 需要先建造一个农场</span> * */ if(gid != 10 && UpCall.GidLang.ContainsKey(10) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(10) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 10; bid = findBuilding(VillageID, gid); } else if (gid != 11 && UpCall.GidLang.ContainsKey(11) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(11) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 11; bid = findBuilding(VillageID, gid); } else if (gid != 4 && UpCall.GidLang.ContainsKey(4) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(4) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 4; bid = findBuilding(VillageID, gid); if (UpCall.TD.isRomans && Q.Bid > 18) { UpCall.DebugLog("Romans need crop rule", DebugLevel.W); if (CV.InBuilding[0] != null) { if (CV.InBuilding[0].Gid != 4) { CV.Queue.Insert(0, new BuildingQueue() { UpCall = UpCall, VillageID = VillageID, Bid = bid, Gid = gid }); UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); UpCall.DebugLog("Create Queue BID = [" + bid + "], due to Romans need crop.", DebugLevel.W); } Q.NextExec = CV.InBuilding[0].FinishTime.AddSeconds(CV.Queue[0].CountDown + 30); return; } else if (CV.InBuilding[0] == null) { for (int i = 0; i < CV.Queue.Count; i ++) { if (CV.Queue[i] is BuildingQueue) { var L = CV.Queue[i] as BuildingQueue; if (L.Gid < 4 && !L.Paused) break; else if (L.Gid == 4 && !L.Paused) { Q.NextExec = DateTime.Now.AddSeconds(L.CountDown + 30); return; } } } } } } else if (result.Contains("<p class=\"(c|none)\">")) { UpCall.DebugLog("Unexpected status! Report it on the forum! " + Q.Title, DebugLevel.E); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } else if (UpCall.GidLang.ContainsKey(gid) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(gid) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) return; else if (result.Contains("<span class=\"(c|none)\">")) { //Q.Delay = rand.Next(500, 1000); // Delay shouldn't happen. Q.NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300)); UpCall.DebugLog("Data not refreshed? Add delay for " + Q.Title, DebugLevel.W); return; } else { if (RetryCount >= 2) { UpCall.DebugLog("Unknown status! And cause a queue been deleted! " + Q.Title, DebugLevel.E); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); } UpCall.DebugLog("Unknown status!" + Q.Title, DebugLevel.E); UpCall.PageQuery(VillageID, "dorf1.php"); UpCall.PageQuery(VillageID, "dorf2.php"); RetryCount++; Q.NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300)); return; } RetryCount = 0; // test if resource enough int timecost; if(CV.Buildings.ContainsKey(bid)) timecost = CV.TimeCost(Buildings.Cost(gid, CV.Buildings[bid].Level + 1)); else timecost = CV.TimeCost(Buildings.Cost(gid, 1)); if(CV.InBuilding[UpCall.TD.isRomans && bid > 18 ? 1 : 0] != null) timecost = Math.Max(timecost, Convert.ToInt32(DateTime.Now.Subtract(CV.InBuilding[UpCall.TD.isRomans && bid > 18 ? 1 : 0].FinishTime).TotalSeconds)); if(timecost > 0) { UpCall.DebugLog("Need to upgrade (BID= " + bid.ToString() + ")but resource not enough so add into queue: " + Q.Title, DebugLevel.W); CV.Queue.Insert(0, new BuildingQueue() { UpCall = UpCall, VillageID = VillageID, Bid = bid, Gid = gid }); UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } result = UpCall.PageQuery(VillageID, "build.php?id=" + bid.ToString()); if(result == null) return; m = Regex.Match(result, "dorf(\\d)\\.php\\?a=" + gid + "&(?:amp;)?id=" + bid + "&(?:amp;)?c=[^\"]*"); n = Regex.Match(result, "dorf(\\d)\\.php\\?a=" + bid + "&(?:amp;)?c=[^\"&]*\""); if(!m.Success && !n.Success) { UpCall.DebugLog("Unknown error on building " + Q.Title, DebugLevel.E); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } } // New building int qtype = bid < 19 && bid > 0 ? 0 : 1; if(CV.Buildings.ContainsKey(bid)) CV.RB[UpCall.TD.isRomans ? qtype : 0] = new TInBuilding() { ABid = bid, Gid = gid, Level = CV.Buildings[bid].Level }; else CV.RB[UpCall.TD.isRomans ? qtype : 0] = new TInBuilding() { ABid = bid, Gid = gid, Level = 0 }; if(m.Success) UpCall.PageQuery(VillageID, m.Groups[0].Value.Replace("&", "&")); else UpCall.PageQuery(VillageID, n.Groups[0].Value.Replace("\"", "").Replace("&", "&")); UpCall.BuildCount(); //CV.Buildings[bid].Level++; if(Q.Bid == bid) UpCall.DebugLog("Build " + Q.Title, DebugLevel.I); else UpCall.DebugLog("Build (other) " + Q.Title, DebugLevel.I); if(Q.Bid == bid) { if(Q.TargetLevel == 0 || Q.TargetLevel <= CV.Buildings[bid].Level) { Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); } } UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Buildings, VillageID = VillageID }); }
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"); } }
public int testPossibleNow(int VillageID, BuildingQueue Q) { var CV = TD.Villages[VillageID]; if (CV.Buildings.ContainsKey(Q.Bid) && CV.Buildings[Q.Bid].Gid == Q.Gid && CV.Buildings[Q.Bid].Level != 0) return Buildings.CheckLevelFull(Q.Gid, CV.Buildings[Q.Bid].Level, CV.isCapital) ? -1 : 0; return testPossibleNewNow(TD.Tribe, TD.Villages, CV, Q.Gid, Q.Bid); }
public void Action() { BuildingQueue Q = this; var CV = UpCall.TD.Villages[VillageID]; if(Q.NextExec >= DateTime.Now) return; Q.NextExec = DateTime.Now.AddSeconds(60); int Bid = UpCall.testPossibleNow(VillageID, Q); // -1表示目前无法建造 if(Bid == -1) { Q.MarkDeleted = true; UpCall.DebugLog("Delete Queue [" + Q.Title + "] because it's impossible to build it.", DebugLevel.W); return; } // 0表示建造该建筑先要造某种别的建筑 if(Bid != 0) { UpCall.DebugLog("Queue [" + Q.Title + "] needs Bid=" + Bid.ToString() + " to be extended.", DebugLevel.I); Q = new BuildingQueue() { UpCall = UpCall, Bid = Bid, Gid = CV.Buildings[Bid].Gid }; UpCall.DebugLog("Create Queue [" + Q.Title + "] because it needs to be extended.", DebugLevel.I); } int bid = Q.Bid; int gid = Q.Gid; string result; result = UpCall.PageQuery(VillageID, "dorf1.php"); if(result == null) return; List<int> nMilitaries = new List<int> {13, 14, 19, 20, 21, 22, 29, 30, 31, 32, 33, 36, 37}; List<int> nResources = new List<int> {5, 6, 7, 8, 9}; string url = "build.php?id=" + bid.ToString(); if (nMilitaries.Contains(gid)) { url += "&category=2"; } else if (nResources.Contains(gid)) { url += "&category=3"; } else if (gid == 17) { url += "&t=0"; } result = UpCall.PageQuery(VillageID, url); if(result == null) return; // m用来解析新建建筑,n用来解析建筑升级 Match m, n; m = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + gid + "&id=" + bid + "&c=[^\']*?)';\\sreturn"); n = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + bid + "&c=[^\']*?)';\\sreturn"); if(!m.Success && !n.Success) { // check reason /* * <span class="c">已经有建筑在建造中</span> * <div class="c">资源不足</div> * <p class="c">伐木场建造完成</p> * <span class="c">建造所需资源超过仓库容量上限,请先升级你的仓库</span> * <span class="c">粮食产量不足: 需要先建造一个农场</span> * */ int RomaNeedCrop = -1; // 仓库容量不足的话,先造仓库 if(gid != 10 && UpCall.GidLang.ContainsKey(10) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(10) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 10; bid = findBuilding(VillageID, gid); } // 粮食产量不足的话,先造农场 else if (gid != 11 && UpCall.GidLang.ContainsKey(11) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(11) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { gid = 11; bid = findBuilding(VillageID, gid); } else if (gid != 4 && UpCall.GidLang.ContainsKey(4) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(4) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) { if (UpCall.TD.isRomans && CV.InBuilding[0] != null && Q.Bid > 18) { if (CV.InBuilding[0].Gid != 4) RomaNeedCrop = 1; else if (CV.InBuilding[0].Gid == 4) { RomaNeedCrop = 0; return; } UpCall.DebugLog("Roma NEED Crop rule", DebugLevel.W); Q.NextExec = CV.InBuilding[0].FinishTime.AddSeconds(30); } gid = 4; bid = findBuilding(VillageID, gid); } else if (result.Contains("<p class=\"(c|none)\">")) { UpCall.DebugLog("Unexpected status! Report it on the forum! " + Q.Title, DebugLevel.W); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } else if (UpCall.GidLang.ContainsKey(gid) && Regex.Match(result, "<span class=\"(c|none)\">[^<]*?" + UpCall.GetGidLang(gid) + "[^<]*?</span>", RegexOptions.IgnoreCase).Success) return; else if (result.Contains("<span class=\"(c|none)\">")) { //Q.Delay = rand.Next(500, 1000); // Delay shouldn't happen. Q.NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300)); UpCall.DebugLog("Data not refreshed? Add delay for " + Q.Title, DebugLevel.I); return; } else { UpCall.PageQuery(VillageID, "dorf1.php"); UpCall.PageQuery(VillageID, "dorf2.php"); UpCall.DebugLog("Unknown status! And cause a queue been deleted! " + Q.Title, DebugLevel.W); //Q.MarkDeleted = true; //UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); Q.NextExec = DateTime.Now.AddSeconds(rand.Next(150, 300)); return; } // 检查资源是否足够 int timecost; if(CV.Buildings.ContainsKey(bid)) timecost = CV.TimeCost(Buildings.Cost(gid, CV.Buildings[bid].Level + 1)); else timecost = CV.TimeCost(Buildings.Cost(gid, 1)); if(CV.InBuilding[UpCall.TD.isRomans && bid > 18 ? 1 : 0] != null) timecost = Math.Max(timecost, Convert.ToInt32(DateTime.Now.Subtract(CV.InBuilding[UpCall.TD.isRomans && bid > 18 ? 1 : 0].FinishTime).TotalSeconds)); if(timecost > 0 || RomaNeedCrop == 1) { UpCall.DebugLog("Need to build but resource not enough so add into queue: " + Q.Title, DebugLevel.I); CV.Queue.Insert(0, new BuildingQueue() { UpCall = UpCall, VillageID = VillageID, Bid = bid, Gid = gid }); UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } result = UpCall.PageQuery(VillageID, "build.php?id=" + bid.ToString()); if(result == null) return; m = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + gid + "&id=" + bid + "&c=[^\']*?)'"); n = Regex.Match(result, "(dorf(\\d)\\.php\\?a=" + bid + "&c=[^\']*?)'"); if(!m.Success && !n.Success) { UpCall.DebugLog("Unknown error on building " + Q.Title, DebugLevel.E); Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); return; } } // New building int qtype = bid < 19 && bid > 0 ? 0 : 1; if(CV.Buildings.ContainsKey(bid)) CV.RB[UpCall.TD.isRomans ? qtype : 0] = new TInBuilding() { ABid = bid, Gid = gid, Level = CV.Buildings[bid].Level }; else CV.RB[UpCall.TD.isRomans ? qtype : 0] = new TInBuilding() { ABid = bid, Gid = gid, Level = 1 }; // 执行建造操作 string uri; if(m.Success) { uri = m.Groups[1].Value.Replace("amp;", ""); UpCall.PageQuery(VillageID, uri); } else { uri = n.Groups[1].Value.Replace("amp;", ""); UpCall.PageQuery(VillageID, uri); } UpCall.BuildCount(); if(Q.Bid == bid) UpCall.DebugLog("Build " + Q.Title, DebugLevel.I); else UpCall.DebugLog("Build (other) " + Q.Title, DebugLevel.I); if(Q.Bid == bid) { if(Q.TargetLevel == 0 || Q.TargetLevel <= CV.Buildings[bid].Level) { Q.MarkDeleted = true; UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Queue, VillageID = VillageID }); } } UpCall.CallStatusUpdate(this, new Travian.StatusChanged() { ChangedData = Travian.ChangedType.Buildings, VillageID = VillageID }); }
private void CMBUp_Click(object sender, EventArgs e) { if (!TravianData.Villages.ContainsKey(SelectVillage)) return; if (m_buildinglist.listViewBuilding.SelectedItems.Count == 0) return; var CV = TravianData.Villages[SelectVillage]; if (CV.isBuildingInitialized == 2) { for (int i = 0; i < m_buildinglist.listViewBuilding.SelectedItems.Count; i++) { int temp; if (!int.TryParse(m_buildinglist.listViewBuilding.SelectedItems[i].Text, out temp)) continue; int Bid = Convert.ToInt32(m_buildinglist.listViewBuilding.SelectedItems[i].Text); if (Buildings.CheckLevelFull(CV.Buildings[Bid].Gid, CV.Buildings[Bid].Level, CV.isCapital)) continue; var Q = new BuildingQueue() { UpCall = tr, VillageID = SelectVillage, Bid = Bid, Gid = CV.Buildings[Bid].Gid, }; CV.Queue.Add(Q); lvi(Q); m_buildinglist.listViewBuilding.Items[m_buildinglist.listViewBuilding.SelectedIndices[i]].SubItems[1].Text += "*"; } } }
private void CMBUpTo_Click(object sender, EventArgs e) { if (!TravianData.Villages.ContainsKey(SelectVillage)) return; if (m_buildinglist.listViewBuilding.SelectedItems.Count == 0) return; var CV = TravianData.Villages[SelectVillage]; if (TravianData.Villages[SelectVillage].isBuildingInitialized == 2) { for (int i = 0; i < m_buildinglist.listViewBuilding.SelectedItems.Count; i++) { int temp; if (!int.TryParse(m_buildinglist.listViewBuilding.SelectedItems[i].Text, out temp)) continue; int Bid = Convert.ToInt32(m_buildinglist.listViewBuilding.SelectedItems[i].Text); int Gid = CV.Buildings[Bid].Gid; int clevel = CV.Buildings[Bid].Level; int tlevel = Buildings.BuildingCost[Gid].data.Length - 1; if (Gid <= 4) { if (!CV.isCapital) tlevel = 10; } if (clevel >= tlevel) continue; BuildToLevel btl = new BuildToLevel() { BuildingName = tr.GetGidLang(Gid), DisplayName = dl.GetGidLang(Gid), CurrentLevel = clevel, TargetLevel = tlevel, mui = mui }; if (btl.ShowDialog() == DialogResult.OK) { if (btl.Return < 0) continue; var Q = new BuildingQueue() { UpCall = tr, VillageID = SelectVillage, Bid = Bid, Gid = CV.Buildings[Bid].Gid, TargetLevel = btl.Return }; CV.Queue.Add(Q); lvi(Q); if (m_buildinglist.listViewBuilding.SelectedItems.Count > i) m_buildinglist.listViewBuilding.SelectedItems[i].SubItems[1].Text += "!"; } } } }
private void CMBNew_Click(object sender, EventArgs e) { if (!TravianData.Villages.ContainsKey(SelectVillage)) return; var CV = TravianData.Villages[SelectVillage]; if (TravianData.Villages[SelectVillage].isBuildingInitialized == 2) { NewBuilding nb = new NewBuilding(TravianData, SelectVillage) { mui = mui }; if (nb.ShowDialog() == DialogResult.OK) { var Q = new BuildingQueue() { UpCall = tr, VillageID = SelectVillage, Bid = nb.OutBid, Gid = nb.OutGid, TargetLevel = nb.OutTop ? Buildings.BuildingCost[nb.OutGid].data.Length - 1 : 0 }; CV.Queue.Add(Q); lvi(Q); CV.Buildings[nb.OutBid] = new TBuilding() { Gid = nb.OutGid }; } } }
public void QPUpTop_Click(object sender, EventArgs e) { if (!TravianData.Villages.ContainsKey(SelectVillage)) return; if (m_buildinglist.listViewBuilding.SelectedItems.Count == 0) return; var CV = TravianData.Villages[SelectVillage]; if (TravianData.Villages[SelectVillage].isBuildingInitialized == 2) { for (int i = 0; i < m_buildinglist.listViewBuilding.SelectedItems.Count; i++) { int temp; if (!int.TryParse(m_buildinglist.listViewBuilding.SelectedItems[i].Text, out temp)) continue; int Bid = Convert.ToInt32(m_buildinglist.listViewBuilding.SelectedItems[i].Text); int Gid = CV.Buildings[Bid].Gid; if (CV.Buildings[Bid].Level >= Buildings.BuildingCost[Gid].data.Length - 1) continue; var Q = new BuildingQueue() { UpCall = tr, VillageID = SelectVillage, Bid = Bid, Gid = CV.Buildings[Bid].Gid, TargetLevel = Buildings.BuildingCost[Gid].data.Length - 1 }; CV.Queue.Add(Q); lvi(Q); if (m_buildinglist.listViewBuilding.SelectedItems.Count > i) m_buildinglist.listViewBuilding.SelectedItems[i].SubItems[1].Text += "!"; } } }