public static void Search_Pack() { string file_path = @"C:\Users\danie\Documents\Visual Studio 2017\Resources\Gladiatus_bots\Items .txt files for Gladiatus_bot" + @"\items(" + Helpers.Switch_World() + ").txt"; if (!Properties.Settings.Default.pakujChecked || !File.Exists(file_path)) { return; } IReadOnlyCollection <IWebElement> items; int lineCount = File.ReadLines(file_path).Count(); if (lineCount == 0) { return; } string[] lines = File.ReadAllLines(file_path); string[] names = new string[lines.Length]; string[] soulbounds = new string[lines.Length]; string[] prices = new string[lines.Length]; string[] levels = new string[lines.Length]; string[] categories = new string[lines.Length]; string[] qualities = new string[lines.Length]; string[] amounts = new string[lines.Length]; string[] solds = new string[lines.Length]; int iterator = 0; string regex = "\'(.*?)\'"; for (int i = 0; i < lines.Length; i++) { string[] separated_line = lines[i].Split(' '); names[iterator] = Regex.Match(separated_line[0], regex).Value; soulbounds[iterator] = Regex.Match(separated_line[1], regex).Value; prices[iterator] = Regex.Match(separated_line[2], regex).Value; categories[iterator] = Regex.Match(separated_line[3], regex).Value; qualities[iterator] = Regex.Match(separated_line[4], regex).Value; levels[iterator] = Regex.Match(separated_line[5], regex).Value; amounts[iterator] = Regex.Match(separated_line[6], regex).Value; solds[iterator] = Regex.Match(separated_line[7], regex).Value; names[iterator] = names[iterator].Replace("'", ""); soulbounds[iterator] = soulbounds[iterator].Replace("'", ""); prices[iterator] = prices[iterator].Replace("'", ""); categories[iterator] = categories[iterator].Replace("'", ""); qualities[iterator] = qualities[iterator].Replace("'", ""); levels[iterator] = levels[iterator].Replace("'", ""); amounts[iterator] = amounts[iterator].Replace("'", ""); solds[iterator] = solds[iterator].Replace("'", ""); iterator++; } Navigation.Packages(); Navigation.FreeBackpack(); string path1 = ""; string path2 = ""; string found_sold = ""; bool found = false; bool both_locations = false; bool found_packages = false; string found_price = ""; string last_category = ""; string last_quality = ""; for (int i = 0; i < lines.Length; i++) { if (last_category != categories[i] || last_quality != qualities[i]) { BasicTasks.SelectElement("//select[@name='f']", Helpers.Type_Pack(categories[i])); BasicTasks.SelectElement("//select[@name='fq']", Helpers.Quality_Pack(qualities[i])); BasicTasks.Click("//input[@value='Filtr']"); last_category = categories[i]; last_quality = qualities[i]; } bool first_time = true; both_locations = false; while (!both_locations && !found) { if (!first_time) { items = Form1.driver.FindElementsByXPath("//div[@id='inv']//div[contains(@class,'ui-draggable')]"); both_locations = true; } else { items = Form1.driver.FindElementsByXPath("//div[@id='packages']//div[contains(@class,'ui-draggable')]"); } bool packages = true; while (packages) { packages = false; if (first_time) { items = Form1.driver.FindElementsByXPath("//div[@id='packages']//div[contains(@class,'ui-draggable')]"); } foreach (IWebElement item in items) { string name = item.GetAttribute("class"); string level = item.GetAttribute("data-level"); string soulbound = item.GetAttribute("data-soulbound-to"); string quality = item.GetAttribute("data-quality"); string amount = item.GetAttribute("data-amount"); bool by_name = false; bool by_level = false; bool by_soulbound = false; bool by_quality = false; bool by_amount = false; string result = @"\s*\b" + names[i] + @"\s*\b"; if (Regex.Match(name, result).Success) { by_name = true; } if (levels[i] == level || levels[i] == "null") { by_level = true; } if (soulbounds[i] == soulbound || soulbounds[i] == "null") { by_soulbound = true; } if (qualities[i] == quality || qualities[i] == "null") { by_quality = true; } if (amounts[i] == amount || amounts[i] == "null") { by_amount = true; } bool sold = false; if (solds[i] == "1") { sold = true; } if (by_name && by_level && by_soulbound && by_quality && by_quality && by_amount) { if (sold != BasicTasks.Check_sold(item)) { continue; } path1 = Prepare_XPath(true, names[i], soulbounds[i], levels[i], qualities[i], amounts[i]); path2 = Prepare_XPath(false, names[i], soulbounds[i], levels[i], qualities[i], amounts[i]); found = true; found_sold = solds[i]; found_price = prices[i]; if (!both_locations) { found_packages = true; } break; } } if (first_time && BasicTasks.Search("//a[@class = 'paging_button paging_right_step']")) { BasicTasks.Click("//a[@class = 'paging_button paging_right_step']"); packages = true; continue; } first_time = false; } } if (found_packages) { Take_From_Packages(path1, path2, found_sold); } bool success_market = false; while (!success_market && found) { Navigation.Guild_Market(); Navigation.FreeBackpack(); if (!Sell_On_Market(path2, found_price)) { Farming.Expedition(true); } else { break; } } } }
public static void Run() { BasicTasks.AlreadyRunning(); try { Thread.Sleep(5000); while (!Form1.startChrome) { Thread.Sleep(500); } var driverOptions = new ChromeOptions(); driverOptions.AddExtension(@"C:\Users\danie\Documents\Visual Studio 2017\Resources\Gladiatus_bots\GladiatusTools.crx"); if (Properties.Settings.Default.headless) { driverOptions.AddArgument("--headless"); driverOptions.AddArgument("--disable-gpu"); driverOptions.AddArgument("--window-size=1920,1080"); } if (Screen.AllScreens.Length > 1) { driverOptions.AddArgument("--window-position=1750,50"); } var driverService = ChromeDriverService.CreateDefaultService(); driverService.HideCommandPromptWindow = true; Form1.driver = new ChromeDriver(driverService, driverOptions); if (!Properties.Settings.Default.headless) { Form1.driver.Manage().Window.Maximize(); } using (Form1.driver) { bool logged_in = Login(); Form1.bot_running = true; Tests.RunTests(); bool non_stop = true; int expedition_points = 0; int dungeon_points = 0; bool dungeon_event = true; while (non_stop) { bool first_extract = true; while (Form1.botAction) { do { if (!Form1.botAction) { break; } if (first_extract) { General.ExtractItems(); General.Store_Components(); first_extract = false; } expedition_points = Farming.Expedition(false); dungeon_points = Farming.Dungeon(false); if (dungeon_event) { dungeon_event = Farming.DungeonEvent(); } Farming.Arena35(); Farming.Turma35(); General.Training(); Gold.Pack_Gold(); expedition_points = BasicTasks.ReturnInt("//span[@id='expeditionpoints_value_point']"); dungeon_points = BasicTasks.ReturnInt("//span[@id='dungeonpoints_value_point']"); if (expedition_points == 0 && !Properties.Settings.Default.dungeonsChecked && Form1.british_land && !Properties.Settings.Default.farm_arenas || expedition_points == 0 && Form1.british_land && !Properties.Settings.Default.farm_arenas || dungeon_points == 0 && !Properties.Settings.Default.expeditionsChecked && Form1.british_land && !Properties.Settings.Default.farm_arenas) { if (!Hades.Take_Pater_Costume() /*&& !Hades.DoHades()*/) { break; } } } while (dungeon_points > 0 || expedition_points > 0 || Properties.Settings.Default.farm_arenas); if (!Form1.botAction) { break; } Gold.Search_Pack(); General.ExtractItems(); General.SellItems(false); Gold.Pack_Gold(); General.BuyFood(false); General.Buy_Auction_House(); General.MovingFood(); BasicTasks.Wait_For_Exit(); } while (Form1.moveGoldAction) { Gold.Pack_Gold(); Form1.moveGoldAction = false; Form1.turn_off_func = true; Form1.notification_type = 1; } while (Form1.sellItemsAction) { General.SellItems(true); Form1.sellItemsAction = false; Form1.turn_off_func = true; Form1.notification_type = 2; } while (Form1.takeGoldAction) { Gold.TakeGold(); Form1.takeGoldAction = false; Form1.turn_off_func = true; Form1.notification_type = 3; } while (Form1.buyRingsAction) { General.Buy_Auction_House(); Form1.buyRingsAction = false; Form1.turn_off_func = true; Form1.notification_type = 4; } while (Form1.downloadPackages) { General.Download_Packages(); Form1.downloadPackages = false; Form1.turn_off_func = true; Form1.notification_type = 5; } while (!Form1.botAction && !Form1.moveGoldAction && !Form1.sellItemsAction && !Form1.takeGoldAction && !Form1.buyRingsAction && !Form1.downloadPackages) { Thread.Sleep(1500); Form1.currently_running = "Waiting for actions.."; } } } } catch (Exception _exception) { BasicTasks.Save_Exception(_exception, Helpers.Switch_World()); Run(); } }
public static void Pack_Gold() { string file_path = @"C:\Users\danie\Documents\Visual Studio 2017\Resources\Gladiatus_bots\Items .txt files for Gladiatus_bot" + @"\items(" + Helpers.Switch_World() + ").txt"; if (!File.Exists(file_path)) { return; } while (Properties.Settings.Default.pakujChecked && Gold_Level() >= Convert.ToInt32(Properties.Settings.Default.minimum_gold_pack)) { Form1.currently_running = "Packing gold.."; int lineCount = File.ReadLines(file_path).Count(); if (lineCount == 0) { return; } string[] lines = File.ReadAllLines(file_path); string[] class_items = new string[lines.Length]; string[] soulbound_items = new string[lines.Length]; string[] price_items = new string[lines.Length]; string[] level_items = new string[lines.Length]; string[] types = new string[lines.Length]; string[] quality = new string[lines.Length]; string[] amount = new string[lines.Length]; string[] already_sold = new string[lines.Length]; string regex = "\'(.*?)\'"; int iterator = 0; for (int i = 0; i < lines.Length; i++) { string[] separated_line = lines[i].Split(' '); class_items[iterator] = Regex.Match(separated_line[0], regex).Value; soulbound_items[iterator] = Regex.Match(separated_line[1], regex).Value; price_items[iterator] = Regex.Match(separated_line[2], regex).Value; types[iterator] = Regex.Match(separated_line[3], regex).Value; quality[iterator] = Regex.Match(separated_line[4], regex).Value; level_items[iterator] = Regex.Match(separated_line[5], regex).Value; amount[iterator] = Regex.Match(separated_line[6], regex).Value; already_sold[iterator] = Regex.Match(separated_line[7], regex).Value; class_items[iterator] = class_items[iterator].Replace("'", ""); soulbound_items[iterator] = soulbound_items[iterator].Replace("'", ""); price_items[iterator] = price_items[iterator].Replace("'", ""); types[iterator] = types[iterator].Replace("'", ""); quality[iterator] = quality[iterator].Replace("'", ""); level_items[iterator] = level_items[iterator].Replace("'", ""); amount[iterator] = amount[iterator].Replace("'", ""); already_sold[iterator] = already_sold[iterator].Replace("'", ""); iterator++; } bool changed = true; while (changed) { changed = false; for (int i = 0; i < lines.Length - 1; i++) { if (Convert.ToInt32(price_items[i]) < Convert.ToInt32(price_items[i + 1])) { changed = true; string temporary = price_items[i]; price_items[i] = price_items[i + 1]; price_items[i + 1] = temporary; temporary = class_items[i]; class_items[i] = class_items[i + 1]; class_items[i + 1] = temporary; temporary = soulbound_items[i]; soulbound_items[i] = soulbound_items[i + 1]; soulbound_items[i + 1] = temporary; temporary = types[i]; types[i] = types[i + 1]; types[i + 1] = temporary; temporary = quality[i]; quality[i] = quality[i + 1]; quality[i + 1] = temporary; temporary = level_items[i]; level_items[i] = level_items[i + 1]; level_items[i + 1] = temporary; temporary = amount[i]; amount[i] = amount[i + 1]; amount[i + 1] = temporary; } } } Navigation.Guild_Market(); if (!BasicTasks.Search("//input[@value='Kup']")) { return; } int found_case = 0; int orginal_case = 0; for (int i = 0; i < class_items.Length; i++) { if (Gold_Level() - Convert.ToInt32(price_items[i]) > 0) { found_case = i; orginal_case = i; break; } } loop_label: int first_iterator = Form1.driver.FindElementsByXPath("//input[@value='Kup']").Count(); int second_iterator = Form1.driver.FindElementsByXPath("//input[@value='Anuluj']").Count(); iterator = first_iterator + second_iterator; int price_item_work = Convert.ToInt32(price_items[found_case]); string name_item_work = class_items[found_case]; string soulbound_work = soulbound_items[found_case]; string level_work = level_items[found_case]; string item_quality = quality[found_case]; string amount_work = amount[found_case]; bool by_name = false; bool by_amount = false; bool by_soulbound = false; bool by_level = false; bool by_quality = false; bool bought = false; if (amount_work != "null") { by_amount = true; } if (name_item_work != "null") { by_name = true; } if (soulbound_work != "null") { by_soulbound = true; } if (level_work != "null") { by_level = true; } if (item_quality != "null") { by_quality = true; } for (int i = 2; i <= iterator + 1; i++) { if (BasicTasks.Search("//section[@id='market_table']//tr[position()='" + i + "']/td[@align='center']/input[@value='Kup']")) { IWebElement element = Form1.driver.FindElementByXPath("//section[@id='market_table']//tr[position()='" + i + "']/td[@style]/div[@style]"); string soulbound = element.GetAttribute("data-soulbound-to"); string name_item = element.GetAttribute("class"); string price_item_string = Form1.driver.FindElementByXPath ("//section[@id='market_table']//tr[position()='" + i + "']/td[position()='3']").GetAttribute("textContent"); string level = element.GetAttribute("data-level"); string quality_level = element.GetAttribute("data-quality"); string amount_loop = element.GetAttribute("data-amount"); int price_item = Convert.ToInt32(new String(price_item_string.Where(Char.IsDigit).ToArray())); if (price_item_work == price_item) { if (by_name && name_item != name_item_work || by_soulbound && soulbound != soulbound_work || by_level && level != level_work || by_quality && quality_level != item_quality || by_amount && amount_loop != amount_work) { continue; } int gold_before = Gold_Level(); BasicTasks.Click("//section[@id='market_table']//tr[position()='" + i + "']/td[@align='center']/input[@value='Kup']"); if (gold_before - Gold_Level() == price_item_work) { bought = true; } break; } } } if (!bought && found_case != class_items.Length - 1) { found_case++; goto loop_label; } else if (!bought && BasicTasks.Search("//a[contains(text(),'Następna strona')]") && found_case == class_items.Length - 1) { BasicTasks.Click("//a[contains(text(),'Następna strona')]"); found_case = orginal_case; goto loop_label; } else if (!bought && !BasicTasks.Search("//a[contains(text(),'Następna strona')]") && found_case == class_items.Length - 1) { return; } string path = "//div[@class='packageItem']//div"; string path2 = "//div[@id='inv']//div"; if (by_name) { path = path + "[contains(concat(' ', normalize-space(@class), ' '), ' " + class_items[found_case] + " ')]"; path2 = path2 + "[contains(concat(' ', normalize-space(@class), ' '), ' " + class_items[found_case] + " ')]"; } if (by_soulbound) { path += "[@data-soulbound-to='" + soulbound_work + "']"; path2 += "[@data-soulbound-to='" + soulbound_work + "']"; } if (by_level) { path += "[@data-level='" + level_work + "']"; path2 += "[@data-level='" + level_work + "']"; } if (by_quality) { path += "[@data-quality='" + item_quality + "']"; path2 += "[@data-quality='" + item_quality + "']"; } if (by_amount) { path += "[@data-amount='" + amount_work + "']"; path2 += "[@data-amount='" + amount_work + "']"; } while (true) { takeOut: Navigation.Packages(); if (BasicTasks.Search("//section[@style='display: none;']")) { BasicTasks.Click("//h2[@class='section-header'][contains(text(), 'Opcje')]"); } BasicTasks.SelectElement("//select[@name='f']", Helpers.Type_Pack(types[found_case])); BasicTasks.SelectElement("//select[@name='fq']", Helpers.Quality_Pack(quality[found_case])); BasicTasks.Click("//input[@value='Filtr']"); if (!Navigation.FreeBackpack()) { return; } if (!BasicTasks.Search(path) && BasicTasks.Search(path2)) { goto sell; } else if (!BasicTasks.Search(path) && !BasicTasks.Search(path2)) { bool found = false; while (BasicTasks.Search("//a[@class='paging_button paging_right_step']") && !found) { BasicTasks.Click("//a[@class='paging_button paging_right_step']"); if (BasicTasks.Search(path)) { found = true; } } if (!found) { break; } } Navigation.FreeBackpack(); BasicTasks.MoveMoveElement(path, "//div[@id='inv']"); if (BasicTasks.Search("//div[@class='ui-droppable grid-droparea image-grayed active']")) { BasicTasks.ReleaseElement("//div[@class='ui-droppable grid-droparea image-grayed active']"); } else { BasicTasks.ReleaseElement("//input[@name='show-item-info']"); return; } sell: Navigation.Guild_Market(); Navigation.FreeBackpack(); while (BasicTasks.Search("//div[@id='market_sell_box']//section[@style='display: none;']")) { BasicTasks.Click("//h2[@class='section-header'][text() = 'sprzedaj']"); } if (BasicTasks.Search(path2)) { BasicTasks.MoveReleaseElement(path2, "//div[@id='market_sell']/div[@class='ui-droppable']"); } else { goto takeOut; } BasicTasks.SelectElement("//select[@name='dauer']", "24 h"); var cena = BasicTasks.GetElement("//input[@name='preis']"); cena.SendKeys(OpenQA.Selenium.Keys.Control + "a"); cena.SendKeys(OpenQA.Selenium.Keys.Delete); cena.SendKeys(Convert.ToString(price_item_work)); BasicTasks.Click("//input[@value='Oferta']"); Thread.Sleep(2000); if (BasicTasks.Search("//div[@class='message fail']")) { Farming.Expedition(true); goto sell; } else { return; } } } }