public VillageInfo GetBuildingInfo() { villageInfo = new VillageInfo(); var reg = new Regex(@"buildingSlot a([0-9]{1,2}) g19"); var match = reg.Match(content); if (match.Success) { villageInfo.Buildings.Barracks.Id = match.Groups[1].Value; } return(villageInfo); }
public void CollectData(ref VillageInfo info) { var getParams = new Dictionary <string, string> { }; if (!HTTP.GetRequest("http://" + _server + "/dorf2.php", getParams, _server, true)) { return; } htmlCrawler = new HtmlCrawler(Info.ResponseBody); info = htmlCrawler.GetBuildingInfo(); }
private void ButtonStart_Click(object sender, EventArgs e) { StartBrowserProxy(); username = textBoxName.Text; password = textBoxPassword.Text; server = textBoxServer.Text; _trainTroopType = comboBoxTroop.SelectedIndex; _farmlistTroopType = comboBoxFarmlist.SelectedIndex; _interval = Convert.ToInt32(textBoxTrainInterval.Text); travian = new Travian(username, password, server, _trainTroopType, _farmlistTroopType); travian.mainForm = this; villageInfo = new VillageInfo(); travian.CollectData(ref villageInfo); var barracksId = villageInfo.Buildings.Barracks.Id; if (buttonStart.Text == "Stop") { Bot.Log("Bot stopped", Color.Black); worker.Abort(); buttonStart.Text = "Start"; if (timer != null) { if (timer.IsAlive) { timer.Abort(); } } textBoxName.Enabled = true; textBoxPassword.Enabled = true; textBoxServer.Enabled = true; comboBoxFarmlist.Enabled = true; comboBoxTroop.Enabled = true; buttonLogin.Enabled = true; checkBoxBuyAnimals.Enabled = true; checkBoxBuyResources.Enabled = true; checkBoxExcludeList.Enabled = true; checkBoxNpc.Enabled = true; } else { if (_login) { buttonStart.Text = "Stop"; textBoxName.Enabled = false; textBoxPassword.Enabled = false; textBoxServer.Enabled = false; comboBoxFarmlist.Enabled = false; comboBoxTroop.Enabled = false; buttonLogin.Enabled = false; checkBoxBuyAnimals.Enabled = false; checkBoxBuyResources.Enabled = false; checkBoxExcludeList.Enabled = false; checkBoxNpc.Enabled = false; if (checkBoxExcludeList.Checked) { travian.ExcludeLastList = true; Bot.Log("Exclude raid list is active. The last raid list will not send to raid.", Color.Black); } if (checkBoxBuyAnimals.Checked) { travian.BuyAnimalsState = true; Bot.Log("- Animal purchasing is active.", Color.Green); } if (checkBoxBuyResources.Checked) { travian.BuyResourcesState = true; Bot.Log("- Resources purchasing is active.", Color.Green); } if (checkBoxNpc.Checked) { travian.DoNpc = true; Bot.Log("- NPC is active.", Color.Green); } timer = new Thread(() => { while (true) { Bot.Log("Starting to buy goodies in 5 seconds.", Color.Black); Thread.Sleep(5000); travian.BuyGoodies(); travian.TrainTroops(barracksId); Thread.Sleep(355000); } }); timer.Start(); worker = new Thread(() => { int raidCount = 0; while (buttonStart.Text == "Stop") { if (raidCount < _interval) { if (travian.StartRaid()) { Bot.Log("Sending raid...", Color.Black); } else { Bot.Log("Error: Raid couldn't started.", Color.Black); } raidCount++; Thread.Sleep(10000); } else { Bot.Log("Training troops", Color.Black); if (travian.TrainTroops(barracksId)) { Bot.Log("Raid next.", Color.Black); } raidCount = 0; } } }); worker.Start(); } else { Bot.Log("First login!", Color.DarkRed); } } if (threadLogin != null) { threadLogin.Abort(); } }