private void ParseNPC() { Program.PhantomNewTab(Url, 1); // Reset table settings Program.Driver.FindElementByXPath("//*[@id=\"NpcTable_wrapper\"]/div[1]/div[2]/div/a").Click(); // Wait if table is loading, Quit if table is empty while (Program.Driver.FindElementByXPath("//*[@id=\"NpcTable\"]/tbody/tr/td").Displayed) { if (Program.Driver.FindElementByXPath("//*[@id=\"NpcTable\"]/tbody/tr/td").Text == "No data available in table") { Trace.WriteLine("\nNo data available in table."); Thread.Sleep(2000); Program.Main(); } else { Thread.Sleep(500); } } HtmlDocument doc = new HtmlDocument(); int npcs_size = TableUtility.Count(Program.Driver, "//*[@id=\"NpcTable_info\"]"); NpcEntry[] npcs = new NpcEntry[npcs_size]; // Sort by ID Program.Driver.ExecuteScript("document.evaluate(\"//*[@id=\\\"NpcTable\\\"]/thead/tr/th[1]\"," + " document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue.click();"); // Set the table size to 50 Program.Driver.ExecuteScript("document.getElementsByTagName(\"option\")[1]" + ".setAttribute(\"value\",\"50\");"); Program.Driver.FindElementByXPath("//*[@id=\"NpcTable_length\"]/label/select").Click(); Program.Driver.FindElementByXPath("//*[@id=\"NpcTable_length\"]/label/select/option[2]").Click(); // Click on Page 1 Program.Driver.FindElementByXPath("//*[@id=\"NpcTable_paginate\"]/ul/li[2]/a").Click(); int file_index = 1; Stopwatch timer = new Stopwatch(); timer.Start(); int validNpcIndex = 0; for (int item = 0; item < npcs_size;) { doc.LoadHtml(File.ReadAllText(Program.SaveHTML(file_index++.ToString()))); HtmlNode table = doc.DocumentNode.SelectSingleNode("//*[@id=\"NpcTable\"]"); for (int tr = 0; tr < 50; tr++) { try { string tableXPath = ""; if (table != null && doc.DocumentNode.SelectSingleNode( table.XPath + "/tbody/tr[" + (tr + 1) + "]/td[1]") != null) { tableXPath = table.XPath; } else { throw new Exception("{EOF}"); } NPCRace race = TableUtility.ParseRace(doc, tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[3]/div"); int id = TableUtility.ParseText <int>(doc.DocumentNode.SelectSingleNode(tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[1]").InnerText); NPCGrade grade = TableUtility.ParseGrade(TableUtility.ParseText <NPCGrade>( doc.DocumentNode.SelectSingleNode(tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[6]").InnerText)); string name = ""; string url = ""; if (race == NPCRace.BALAUR) { name = TableUtility.ParseText <string>(doc.DocumentNode.SelectSingleNode( tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[3]/a/b").InnerText); url = TableUtility.ParseUrl(TableUtility.ParseText <string>( doc.DocumentNode.SelectSingleNode(tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[3]/a").GetAttributeValue("href", ""))); } else { name = TableUtility.ParseText <string>(doc.DocumentNode.SelectSingleNode(tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[3]/div/a/b").InnerText); url = TableUtility.ParseUrl(TableUtility.ParseText <string>( doc.DocumentNode.SelectSingleNode(tableXPath + "/tbody/tr[" + (tr + 1) + "]/td[3]/div/a").GetAttributeValue("href", ""))); } if (validNpcIndex > 0 && npcs[validNpcIndex - 1].ID == id) { throw new Exception("{Duplicate ID}"); } npcs[validNpcIndex] = new NpcEntry(); npcs[validNpcIndex].Race = race; npcs[validNpcIndex].Name = name; npcs[validNpcIndex].Url = url; npcs[validNpcIndex].ID = id; npcs[validNpcIndex].Grade = grade; npcs[validNpcIndex].Info(item + 1); npcs[validNpcIndex].GetDrop(Program.LoadADBXName(Url, UrlName)); validNpcIndex++; } catch /*(Exception e)*/ { //Trace.WriteLine(e.Message); } finally { item++; } } // Click on Next Page Program.Driver.FindElementByXPath("//*[@id=\"NpcTable_next\"]/a").Click(); } timer.Stop(); Trace.WriteLine("\nParsed " + UrlName + " in " + timer.Elapsed.ToString("hh\\:mm\\.ss")); }
protected void Application_Start(object sender, EventArgs e) { // Rebuild the char names list json new SMAccountHelper().RebuildCharacterJSONFile(); // Websocket WebSocketCollection wsClients = new WebSocketCollection(); Application["WSClients"] = wsClients; // Botclients //List<BotClient> botClients = new List<BotClient>(); //Application["BotClients"] = botClients; // Character List List <SMCharacter> smc = new List <SMCharacter>(); Application["SMCharacters"] = smc; // Room List List <SMRoom> smr = new List <SMRoom>(); Application["SMRooms"] = smr; // Load the Commands into memory for usage later // Used for both parsing commands sent in and also for help output List <SMCommand> smcl = new List <SMCommand>(); // Get all files from the Commands path string commandsFolderPath = FilePathSystem.GetFilePathFromFolder("Commands"); DirectoryInfo dirInfo = new DirectoryInfo(commandsFolderPath); FileInfo[] CommandFiles = dirInfo.GetFiles("Commands.*.json"); foreach (FileInfo file in CommandFiles) { string path = FilePathSystem.GetFilePath("Commands", file.Name, ""); // Use a stream reader to read the file in (based on the path) using (StreamReader r = new StreamReader(path)) { // Create a new JSON string to be used... string json = r.ReadToEnd(); // Get all the commands from the commands file smcl.AddRange(JsonConvert.DeserializeObject <List <SMCommand> >(json)); } } Application["SMCommands"] = smcl; // Load class builder specs into memory for usage later // Used for creating objects that are used to call user commands on ClassBuilderSpecs cbs = new ClassBuilderSpecs(); string specsPath = FilePathSystem.GetFilePath("Misc", "ClassBuilder"); if (File.Exists(specsPath)) { using (StreamReader r = new StreamReader(specsPath)) { string json = r.ReadToEnd(); cbs = JsonConvert.DeserializeObject <ClassBuilderSpecs>(json); } } Application["ClassBuilderSpecs"] = cbs; // Load the Skills into memory for usage later // Used for both parsing commands sent in and also for help output List <SMSkill> lsk = new List <SMSkill>(); // Get all filenames from path string skillFolderFilePath = FilePathSystem.GetFilePathFromFolder("Skills"); DirectoryInfo d = new DirectoryInfo(skillFolderFilePath); //Assuming Test is your Folder FileInfo[] Files = d.GetFiles(); foreach (FileInfo file in Files) { string skillFilePath = FilePathSystem.GetFilePath("Skills", file.Name, ""); // Use a stream reader to read the file in (based on the path) using (StreamReader r = new StreamReader(skillFilePath)) { // Create a new JSON string to be used... string json = r.ReadToEnd(); // ... get the information from the help file lsk.Add(JsonConvert.DeserializeObject <SMSkill>(json)); } } Application["SMSkills"] = lsk; // Load the Receipes into memory for usage later // Used for both parsing commands sent in and also for help output List <SMReceipe> smrl = new List <SMReceipe>(); // Get all filenames from path string receipeFolderFilePath = FilePathSystem.GetFilePathFromFolder("Receipe"); d = new DirectoryInfo(receipeFolderFilePath); //Assuming Test is your Folder Files = d.GetFiles(); foreach (FileInfo file in Files) { string receipeFilePath = FilePathSystem.GetFilePath("Receipe", file.Name, ""); // Use a stream reader to read the file in (based on the path) using (StreamReader r = new StreamReader(receipeFilePath)) { // Create a new JSON string to be used... string json = r.ReadToEnd(); // ... get the information from the help file smrl.Add(JsonConvert.DeserializeObject <SMReceipe>(json)); } } Application["SMReceipes"] = smrl; // Load the Skills into memory for usage later // Used for both parsing commands sent in and also for help output List <SMNPC> lnpcs = new List <SMNPC>(); //Get all filenames from path string NPCsFolderFilePath = FilePathSystem.GetFilePathFromFolder("NPCs"); d = new DirectoryInfo(NPCsFolderFilePath); //Assuming Test is your Folder Files = d.GetFiles(); foreach (FileInfo file in Files) { if (file.Name != "NPCNamesList.json") { string NPCFilePath = FilePathSystem.GetFilePath("NPCs", file.Name, ""); // Use a stream reader to read the file in (based on the path) using (StreamReader r = new StreamReader(NPCFilePath)) { // Create a new JSON string to be used... string json = r.ReadToEnd(); // ... get the information from the help file lnpcs.Add(JsonConvert.DeserializeObject <SMNPC>(json)); } } } Application["SMNPCs"] = lnpcs; // load and fetch NPCRaces, using a dictionary for speedy lookups later. Dictionary <string, NPCRace> dnpcRaces = new Dictionary <string, NPCRace>(); string NPCRacesFolderFilePath = FilePathSystem.GetFilePathFromFolder("NPCRaces"); d = new DirectoryInfo(NPCRacesFolderFilePath); Files = d.GetFiles(); foreach (FileInfo file in Files) { string RaceFilePath = FilePathSystem.GetFilePath("NPCRaces", file.Name, ""); using (StreamReader r = new StreamReader(RaceFilePath)) { string json = r.ReadToEnd(); NPCRace raceFromJSON = JsonConvert.DeserializeObject <NPCRace>(json); dnpcRaces[raceFromJSON.Name.ToLower()] = raceFromJSON; } } Application["NPCRaces"] = dnpcRaces; Application["Parties"] = new List <SMParty>(); #region "The Pulse" // Set the current context to pass into the thread HttpContext ctx = HttpContext.Current; // Create a new thread Thread pulse = new Thread(new ThreadStart(() => { HttpContext.Current = ctx; new SMPulse().Initiate(); // this is the item that is going to initiate })); // Start the thread pulse.Start(); #endregion // Register the global configuration items for the bot helper //GlobalConfiguration.Configure(WebAPIConfig.Register); }
/// <summary> /// /// </summary> /// <param name="race"></param> /// <param name="isMale"></param> /// <returns></returns> public static string GenerateName( NPCRace race, NPCGender gender ) { switch( race ) { case NPCRace.Dragonborne: return DragonborneName( gender ); case NPCRace.Dwarf: return DwarvenName( gender ); case NPCRace.Eldarin: return EladrinName( gender ); case NPCRace.Elf: return ElvenName( gender ); case NPCRace.HalfElf: if( rand.Next(2)==0 ) return ElvenName( gender ); else return HumanName( gender ); case NPCRace.Gnome: return GnomishName( gender ); case NPCRace.Orc: return OrcishName( gender ); case NPCRace.HalfOrc: if( rand.Next(2)==0 ) return OrcishName( gender ); else return HumanName( gender ); case NPCRace.Angelic: return AngelicName( gender ); default: // human return HumanName( gender ); } }