/// <summary>Prints the details of the instanced <see cref="Character"/>.</summary> public void ExamineCharacter() { Console.WriteLine(string.Concat($"Name: {name}\n", $"Adventurer: {adv_lvl} {Crate.adv_classes[adv_class]}\n", $"Tradeskill: {ts_lvl} {ts_class}\n", $"Recipie count: {recipies.Count}\n", $"Spell count: {spells.Count}\n")); RunCrate.Pe2c(); }
public override bool Edit(Menu EditMenu) { const string recipeURL = @"recipe/?c:show=name&id="; List <string> menu_items = new List <string>(); bool ExitMenu = false, returnValue = false; string UserReply; do { menu_items.Clear(); menu_items.Add($"Item name: {ItemName}"); menu_items.Add($"Item Level: {ItemLevel}"); menu_items.Add($"Item Quantity: {ItemQuantity}"); menu_items.Add("List Recipies."); switch (EditMenu.ThisMenu(menu_items, true, $"Edit Menu for Item: {ItemName}")) { case -1: ExitMenu = true; break; case 0: Console.WriteLine("Enter the new name of the item."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); if (string.IsNullOrEmpty(UserReply)) { break; } ItemName = UserReply; returnValue = true; break; case 1: Console.WriteLine($"Please enter {ItemName}'s new level. Use -1 to cancel."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); short UserShort; while (!short.TryParse(UserReply, out UserShort)) { Console.WriteLine("That was an invalid response."); Console.WriteLine($"Please enter {ItemName}'s new level."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); } if (UserShort == -1) { } else if (UserShort > -1) { ItemLevel = UserShort; returnValue = true; } else { Console.Write($"That number was too small. Press Enter to return to {ItemName}'s menu."); _ = Console.ReadLine(); } break; case 2: Console.WriteLine("Please enter the new quantity or use -1 to cancel."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); while (!short.TryParse(UserReply, out UserShort)) { Console.WriteLine("I didn't understand that response. Please try again."); Console.WriteLine("Please enter the new quantity or use -1 to cancel."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); } if ((UserShort == 0) && !string.IsNullOrEmpty(UserReply)) { Console.WriteLine(BadQuant); RunCrate.Pe2c(); } else if (UserShort > 0) { ItemQuantity = UserShort; returnValue = true; } break; case 3: Console.Write("Please wait while we assemble this menu. Just a moment..."); menu_items.Clear(); ConcurrentBag <string> ConStrings = new ConcurrentBag <string>(); _ = Parallel.ForEach(RecipieList, (ThisRec) => { XDocument thisRecipe = RunCrate.GetThisUrl(string.Concat(recipeURL, ThisRec.ToString())); ConStrings.Add(thisRecipe.Element("recipe_list").Element("recipe").Attribute("name").Value); }); menu_items = ConStrings.ToList(); _ = EditMenu.ThisMenu(menu_items, false, $"{ItemName}'s Recipe List"); break; } } while (!ExitMenu); return(returnValue); }
private void ParseCharacter(XElement root_element, XElement misc_element) { char_id = long.Parse(root_element.Attribute("id").Value); name = root_element.Attribute("displayname").Value.Split(' ')[0]; bool IsErrored = false; if (short.TryParse(root_element.Element("type").Attribute("level").Value, out short new_short_val)) { adv_lvl = new_short_val; } else { Console.WriteLine("Unable to determine the character's adventure level."); IsErrored = true; adv_lvl = -1; } if (short.TryParse(root_element.Element("type").Attribute("ts_level").Value, out new_short_val)) { ts_lvl = new_short_val; } else { Console.WriteLine("Unable to determine the character's tradeskill level."); IsErrored = true; ts_lvl = -1; } if (short.TryParse(root_element.Element("type").Attribute("classid").Value, out new_short_val)) { adv_class = new_short_val; } else { Console.WriteLine("Unable to determine the character's adventure class."); IsErrored = true; adv_class = -1; } try { ts_class = root_element.Element("type").Attribute("ts_class").Value; } catch (ArgumentNullException) { Console.WriteLine("Unable to determine the character's tradeskill class."); IsErrored = true; ts_class = "Unknown."; } try { spells = root_element.Element("spell_list").Elements("spell").Select(p => long.Parse(p.Value)).ToList(); } catch (ArgumentNullException) { Console.WriteLine("Unable to get the character's spells."); IsErrored = true; spells = new List <long>(); } catch (InvalidCastException err) { Console.WriteLine(err.Message); Console.WriteLine("There was an Invalid Cast Exception error."); Console.WriteLine("Unable to get the character's spells."); IsErrored = true; spells = new List <long>(); } try { recipies = misc_element.Element("known_recipe_list").Elements("known_recipe").Select(p => long.Parse(p.Attribute("id").Value)).ToList(); } catch (ArgumentNullException err) { Console.WriteLine(err.Message); Console.WriteLine("Unable to get the character's known recipies."); IsErrored = true; recipies = new List <long>(); } catch (InvalidCastException err) { Console.WriteLine(err.Message); Console.WriteLine("There was an Invalid Cast Exception error."); Console.WriteLine("Unable to get the character's recipies."); IsErrored = true; recipies = new List <long>(); } if (spells.Count > 0) { temp_crc_dict.Clear(); _ = Parallel.ForEach(spells, (thisSpell) => { long spell_crc; short spell_tier; XDocument SpellRaw = RunCrate.GetThisUrl(string.Concat(RunCrate.urlSpell, RunCrate.urlIDGet, thisSpell.ToString())); XElement SpellCooked = SpellRaw.Element("spell_list"); switch (int.Parse(SpellCooked.Attribute("returned").Value)) { case 0: break; case 1: spell_crc = long.Parse(SpellCooked.Element("spell").Attribute("crc").Value); spell_tier = short.Parse(SpellCooked.Element("spell").Attribute("tier").Value); if (temp_crc_dict.ContainsKey(spell_crc)) { Console.WriteLine($"This character has two spells with the crc {spell_crc}."); } else { if (!temp_crc_dict.TryAdd(spell_crc, spell_tier)) { Console.WriteLine($"Unable to add {spell_crc}. The key already existed."); IsErrored = true; } } break; default: Console.WriteLine($"Found too many spells based on ID {thisSpell}."); IsErrored = true; break; } }); } crc_dict.Clear(); foreach (KeyValuePair <long, short> thisPair in temp_crc_dict) { crc_dict.Add(thisPair.Key, thisPair.Value); } if (spells.Count < crc_dict.Count) { Console.WriteLine("The number of spells is greater than the number of crc dictionary entries."); Console.WriteLine("Sanity check fails."); IsErrored = true; } if (IsErrored) { RunCrate.Pe2c(); } }
public override bool Edit(Menu EditMenu) { bool ExitMenu = false, returnValue = false; List <string> menu_items = new List <string>(); string UserReply; short UserShort; do { menu_items.Clear(); menu_items.Add($"Spell Scroll Name: {ItemName}"); menu_items.Add($"Type ID: {ItemType}"); menu_items.Add($"Spell CRC: {SpellCRC}"); menu_items.Add($"Quantity: {ItemQuantity}"); menu_items.Add($"Level: {ItemLevel}"); menu_items.Add("Show available classes."); switch (EditMenu.ThisMenu(menu_items, true, $"{ItemName}'s menu")) { case -1: ExitMenu = true; break; case 0: Console.WriteLine("Please enter the new name of the item then press ENTER or leave blank to abort."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); if (!string.IsNullOrEmpty(UserReply)) { ItemName = UserReply; } returnValue = true; break; case 1: case 2: case 4: Console.WriteLine("This value is immuteable. That means we can't change it, even intentionally."); RunCrate.Pe2c(); break; case 3: Console.WriteLine($"How many copies of {ItemName} do you have now? Leave blank to cancel."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); if (string.IsNullOrEmpty(UserReply)) { break; } while (!short.TryParse(UserReply, out UserShort)) { Console.WriteLine("That was not a value I understood. Please try again."); Console.WriteLine($"How many copies of {ItemName} do you have now? Leave blank to cancel."); Console.Write(RunCrate.userPrompt); UserReply = Console.ReadLine(); if (string.IsNullOrEmpty(UserReply)) { break; } } if ((UserShort < 1) && !string.IsNullOrEmpty(UserReply)) { Console.WriteLine(BadQuant); RunCrate.Pe2c(); } else if (UserShort > 0) { ItemQuantity = UserShort; returnValue = true; } break; } } while (!ExitMenu); return(returnValue); }