public void CopySettings(RaidQueue settings) { this.UpCall.TD.Dirty = true; this.Troops = settings.Troops; this.Targets = settings.Targets; this.RaidType = settings.RaidType; this.SpyOption = settings.SpyOption; this.MaxCount = settings.MaxCount; this.MaxSlots = settings.MaxSlots; this.MultipeRaids = settings.MultipeRaids; this.Description = settings.Description; if (this.TargetID >= this.Targets.Count) { this.NextTarget(); } }
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&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&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); }
public void CopySettings(RaidQueue settings) { this.UpCall.TD.Dirty = true; this.Troops = settings.Troops; this.Targets = settings.Targets; this.RaidType = settings.RaidType; this.SpyOption = settings.SpyOption; this.MaxCount = settings.MaxCount; this.MaxSlots = settings.MaxSlots; this.MultipeRaids = settings.MultipeRaids; this.Description = settings.Description; this.resumeTime = settings.resumeTime; this.MinimumInterval = settings.MinimumInterval; this.RandomRaid = settings.RandomRaid; if (this.TargetID >= this.Targets.Count) { this.NextTarget(); } }
private void btnOk_Click(object sender, EventArgs e) { RaidQueue task = new RaidQueue(); task.Troops = new int[11]; for (int i = 0; i < 11; i++) { Int32.TryParse(this.txtTroops[i].Text, out task.Troops[i]); } task.Targets = new List<TPoint>(); foreach (object village in this.lstTargets.Items) { task.Targets.Add((TPoint)village); } task.RaidType = RaidType.Reinforce + this.SelectedRadioButtonIndex(this.rdbRaidTypes); task.SpyOption = SpyOption.Resource + this.SelectedRadioButtonIndex(this.rdbSpyOptions); task.MaxCount = Convert.ToInt32(this.nudCount.Value); task.MaxSlots = Convert.ToInt32(this.nudMaxSlots.Value); task.MultipeRaids = this.ckbMultipleRaids.Checked; task.Description = tbDesc.Text; task.resumeTime = actionAt; task.MinimumInterval = minimumInterval; task.RandomRaid = this.ckbRandom.Checked; this.Return = task; }
public void TestInitialize() { this.travianData = new Data() { Server = "none", Username = "******" }; Dictionary<string, string> Options = new Dictionary<string, string>(); this.travian = new Travian(travianData, Options, "cn"); this.villageID = 1; this.village = new TVillage(); this.travianData.Villages[villageID] = village; this.village.Name = "Home"; this.village.isTroopInitialized = 2; this.village.Troop = this.troop = new TTroop(); int[] troopsAtHome = new int[11]; troopsAtHome[0] = 8; TTInfo troopAtHome = new TTInfo { Troops = troopsAtHome, Owner = this.village.Name, TroopType = TTroopType.InVillage, VillageName = "Own troops" }; this.troop.Troops.Add(troopAtHome); int[] troopsOnTheRood = new int[11]; troopsOnTheRood[0] = 5; TTInfo troopOnTheRoad = new TTInfo { Troops = troopsAtHome, TroopType = TTroopType.MyReturnWay, FinishTime = DateTime.Now.AddSeconds(100), VillageName = "Raid on abc Village" }; this.troop.Troops.Add(troopOnTheRoad); this.troops = new int[11]; this.troops[0] = 5; this.targets = new List<TPoint>(); this.targets.Add(new TPoint(1, 2)); this.targets.Add(new TPoint(0, 0)); this.target = new RaidQueue() { UpCall = this.travian, VillageID = this.villageID, Troops = this.troops, Targets = this.targets, RaidType = RaidType.AttackRaid, }; this.pageQuerier = new MockPageQuerier(this.villageID); this.travian.pageQuerier = pageQuerier; }
private void DoEvade() { string sendTroopsUrl = String.Format("build.php?id=39&tt=2&z={0}", tpEvadePoint.Z); string sendTroopForm = UpCall.PageQuery(VillageID, sendTroopsUrl); if (sendTroopForm == null || !sendTroopForm.Contains("<form method=\"POST\" name=\"snd\" action=\"build.php?id=39&tt=2\">")) { MinimumDelay = 0; return; } Dictionary <string, string> postData = RaidQueue.GetHiddenInputValues(sendTroopForm); postData.Add("c", "2"); postData.Add("x", tpEvadePoint.X.ToString()); postData.Add("y", tpEvadePoint.Y.ToString()); ReinforceToop = RaidQueue.GetMaxTroops(sendTroopForm); for (int i = 0; i < this.bTroopFilter.Length; i++) { if (bTroopFilter[i]) { continue; } ReinforceToop[i] = 0; } for (int i = 0; i < ReinforceToop.Length; i++) { string troopKey = String.Format("t{0}", i + 1); string troopNumber = ReinforceToop[i] == 0 ? "" : ReinforceToop[i].ToString(); postData.Add(troopKey, troopNumber); } string confirmUrl = "build.php?id=39&tt=2"; string confirmForm = UpCall.PageQuery(this.VillageID, confirmUrl, postData); if (confirmForm == null) { MinimumDelay = 0; return; } Match errorMatch = Regex.Match(confirmForm, "<p class=\"error\">(.+)</span>"); if (errorMatch.Success) { string error = String.Format( "Delete village {0}. Error: {1}", tpEvadePoint, errorMatch.Groups[1].Value); UpCall.DebugLog("部队未能发出,因为:" + error, DebugLevel.W); MinimumDelay = nMinInterval; return; } if (!confirmForm.Contains("<form method=\"post\" action=\"build.php?id=39&tt=2\">")) { MinimumDelay = 0; return; } TimeSpan timeCost = RaidQueue.GetOneWayTimeCost(confirmForm); if (timeCost == TimeSpan.MinValue) { MinimumDelay = nMinInterval; evade_status = EvadeStatus.NoAtkDetected; return; } postData = RaidQueue.GetHiddenInputValues(confirmForm); string result = this.UpCall.PageQuery(this.VillageID, confirmUrl, postData); if (result == null) { MinimumDelay = 0; return; } evade_status = EvadeStatus.Evaded; ReinforceTimeCost = (int)timeCost.TotalSeconds; MinimumDelay = ReinforceTimeCost + RandomDelay(5, 10); TTInfo troopInfo = new TTInfo() { Tribe = UpCall.TD.Tribe, Troops = ReinforceToop }; string message = String.Format( "部队回避 {0} ({1}) => {2} {3}", this.UpCall.TD.Villages[this.VillageID].Coord, this.VillageID, this.tpEvadePoint, troopInfo.FriendlyName); this.UpCall.DebugLog(message, DebugLevel.I); }
private void CMBRaid_Click(object sender, EventArgs e) { MessageBox.Show("尚未完成此功能"); return; TVillage CV = this.GetSelectedVillage(); if (CV == null) { return; } if (CV.isTroopInitialized != 2) { CV.InitializeTroop(); MessageBox.Show("读取军队信息,重新操作一次"); return; } TTInfo Troop = CV.Troop.GetTroopsAtHome(CV); if (Troop == null) { MessageBox.Show("目前此村庄中无军队!"); return; } RaidQueue task = new RaidQueue() { UpCall = this.tr, Tribe = TravianData.Tribe, VillageID = this.SelectVillage, RaidType = RaidType.AttackRaid, SpyOption = SpyOption.Resource, MaxCount = 1, }; if (this.EditRaidQueue(CV, task)) { CV.Queue.Add(task); this.lvi(task); } }
private bool EditRaidQueue(TVillage village, RaidQueue task) { if (village.isTroopInitialized != 2) { village.InitializeTroop(); return false; } RaidOptForm rof = new RaidOptForm() { mui = this.mui, dl = this.dl, TroopsAtHome = village.Troop.GetTroopsAtHome(village), Village = village, Return = task, }; if (rof.ShowDialog() != DialogResult.OK) { return false; } if (rof.Return == null || !rof.Return.IsValid) { return false; } task.CopySettings(rof.Return); return true; }
private void CMBRaid_Click(object sender, EventArgs e) { // MessageBox.Show("尚未完成此功能"); // return; TVillage village = this.GetSelectedVillage(); if (village == null) { return; } RaidQueue task = new RaidQueue() { UpCall = this.tr, Tribe = TravianData.Tribe, VillageID = this.SelectVillage, RaidType = RaidType.AttackRaid, SpyOption = SpyOption.Resource, MaxCount = 1, MultipeRaids = true }; if (this.EditRaidQueue(village, task)) { village.Queue.Add(task); this.lvi(task); } }