예제 #1
0
 /// <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();
 }
예제 #2
0
        /// <summary>
        /// This constructor uses the Daybreak ID number (<paramref name="charID"/>) to find and construct a <see cref="Character"/>.
        /// </summary>
        /// <param name="charID">This is the Daybreak ID number of the given character.</param>
        public Character(long charID)
        {
            XDocument root_element, misc_element;
            string    get_url = string.Concat(RunCrate.urlCharacter, RunCrate.urlIDGet, charID.ToString());

            root_element = RunCrate.GetThisUrl(get_url);
            get_url      = string.Concat(RunCrate.urlCharMisc, RunCrate.urlIDGet, charID.ToString());
            misc_element = RunCrate.GetThisUrl(get_url);
            ParseCharacter(root_element.Element("character_list").Element("character"), misc_element.Element("character_misc_list").Element("character_misc"));
        }
예제 #3
0
        static void Main(string[] args)
        {
            switch (args.Length)
            {
            case 0:
                _ = new RunCrate();
                break;

            default:
                break;
            }
        }
예제 #4
0
        public void ThreadedOK()
        {
            Character TestChar = new Character(433792994743);
            Dictionary <long, short> testDict = new Dictionary <long, short>();

            foreach (long thisSpell in TestChar.spells)
            {
                long      spell_crc;
                short     spell_tier;
                XDocument rawSpell    = RunCrate.GetThisUrl(string.Concat(RunCrate.urlSpell, RunCrate.urlIDGet, thisSpell.ToString()));
                XElement  SpellCooked = rawSpell.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 (testDict.ContainsKey(spell_crc))
                    {
                        Console.WriteLine($"This character has two spells with the crc {spell_crc}.");
                    }
                    else
                    {
                        testDict.Add(spell_crc, spell_tier);
                    }
                    break;

                default:
                    Console.WriteLine($"Found too many spells based on ID {thisSpell}.");
                    break;
                }
            }
            foreach (KeyValuePair <long, short> thisPair in testDict)
            {
                if (TestChar.crc_dict.ContainsKey(thisPair.Key) && (TestChar.crc_dict[thisPair.Key] == thisPair.Value))
                {
                }
                else if (!TestChar.crc_dict.ContainsKey(thisPair.Key))
                {
                    Assert.Fail($"Spell CRC {thisPair.Key} did not make it into the dictionary.");
                }
                else
                {
                    Assert.Fail($"Spell CRC {thisPair.Key} had a different tiers!");
                }
            }
            Assert.IsTrue(true);
        }
예제 #5
0
파일: Crate.cs 프로젝트: ejep520/eq2crate
        /// <summary>This queries the Daybreak Games census server for the current &quot;constants&quot; of the game.</summary>
        internal void GetConstants()
        {
            XDocument xml_doc  = RunCrate.GetThisUrl(urlConstants);
            XElement  DocuNode = xml_doc.Root;

            if (short.Parse(DocuNode.Attribute("returned").Value) != 1)
            {
                throw new Exception("No constants returned!");
            }
            XElement consts_node = DocuNode.Element("constants");

            if (short.TryParse(consts_node.Attribute("maxtradeskilllevel").Value, out short new_short))
            {
                max_ts_lvl = new_short;
            }
            else
            {
                throw new Exception("Unable to determine the max TS level.");
            }
            if (short.TryParse(consts_node.Attribute("maxadventurelevel").Value, out new_short))
            {
                max_adv_lvl = new_short;
            }
            else
            {
                throw new Exception("Unable to determine the max Adv level.");
            }
            IEnumerable <XElement> adv_element = consts_node.Element("adventureclass_list").Elements("adventureclass");
            IEnumerable <XElement> ts_element  = consts_node.Element("tradeskillclass_list").Elements("tradeskillclass");

            adv_classes.Clear();
            rev_adv_classes.Clear();
            ts_classes.Clear();
            foreach (XElement thisClass in adv_element)
            {
                adv_classes.Add(short.Parse(thisClass.Attribute("id").Value), FirstCharToUpper(thisClass.Attribute("name").Value));
                rev_adv_classes.Add(thisClass.Attribute("name").Value, short.Parse(thisClass.Attribute("id").Value));
            }
            foreach (XElement thisClass in ts_element)
            {
                ts_classes.Add(thisClass.Attribute("name").Value, short.Parse(thisClass.Attribute("id").Value));
            }
        }
예제 #6
0
파일: Crate.cs 프로젝트: ejep520/eq2crate
        /// <summary>Creates a new <see cref="CrateItem"/> based on <paramref name="GetIDNum"/>.</summary>
        /// <param name="GetIDNum">This is the Daybreak Games ID number of the item being created.</param>
        /// <returns>A new instance of <see cref="CrateItem"/> based on the <paramref name="GetIDNum"/> <see cref="long"/> retrieved from Daybreak Games.</returns>
        public CrateItem GetItemFromID(long GetIDNum)
        {
            CrateItem ReturnVal   = new CrateItem();
            string    NewReq      = string.Concat(urlItem, urlIDGet, GetIDNum.ToString());
            XDocument BasicXML    = RunCrate.GetThisUrl(NewReq);
            string    returnedNum = BasicXML.Element("item_list").Attribute("returned").Value;

            if (short.TryParse(returnedNum, out short ReturnedItems))
            {
                if (ReturnedItems == 0)
                {
                    throw new CrateException("No items were found with that ID number", 0);
                }
                else if (ReturnedItems == 1)
                {
                    try
                    {
                        ReturnVal = ProcessXML(BasicXML.Element("item_list").Element("item"));
                    }
                    catch (CrateException err)
                    {
                        Console.WriteLine("An error occurred!");
                        Console.WriteLine(err.Message);
                        if (err.severity > 1)
                        {
                            throw err;
                        }
                    }
                }
                else
                {
                    throw new CrateException("More than one item with the same ID was found! WTH!?");
                }
            }
            return(ReturnVal);
        }
예제 #7
0
파일: Crate.cs 프로젝트: ejep520/eq2crate
        /// <summary>Accepts a string and searches for an item with this name.</summary>
        /// <param name="search_key">This is the search key passed to the method.</param>
        /// <returns>A <see cref="CrateItem"/> with the discovered item.</returns>
        /// <exception cref="CrateException">Thrown when no items matching the search key are found.</exception>
        /// <exception cref="CrateException">Thrown if duplicate items are discovered.</exception>
        public CrateItem GetItemFromName(string search_key)
        {
            CrateItem return_val;
            string    search_url = string.Concat(urlItem, urlNameGet, search_key.ToLower());
            XDocument new_xml    = RunCrate.GetThisUrl(search_url);

            if (!int.TryParse(new_xml.Element("item_list").Attribute("returned").Value, out int returned_num))
            {
                throw new CrateException("Got a problem with the returned value!!");
            }
            switch (returned_num)
            {
            case 0:
            {
                throw new CrateException($"No items found with the name {search_key}.");
            }

            case 1:
            {
                return_val = ProcessXML(new_xml.Element("item_list").Element("item"));
                break;
            }

            case 2:
            {
                XElement item_zero, item_one;
                item_zero = new_xml.Element("item_list").Elements("item").First();
                item_one  = new_xml.Element("item_list").Elements("item").Last();
                if (HasHeirloom(item_zero) ^ HasHeirloom(item_one))
                {
                    Console.Write("Is the item Heirloom flagged (y/N)?  ");
                    if (Console.ReadLine().ToLower().StartsWith("y"))
                    {
                        if (HasHeirloom(item_zero))
                        {
                            return_val = ProcessXML(item_zero);
                        }
                        else
                        {
                            return_val = ProcessXML(item_one);
                        }
                    }
                    else
                    {
                        if (HasHeirloom(item_zero))
                        {
                            return_val = ProcessXML(item_one);
                        }
                        else
                        {
                            return_val = ProcessXML(item_zero);
                        }
                    }
                }
                else if (HasLore(item_zero) ^ HasLore(item_one))
                {
                    Console.Write("Is this item Lore flagged (y/N)?  ");
                    if (Console.ReadLine().ToLower().StartsWith("y"))
                    {
                        if (HasLore(item_zero))
                        {
                            return_val = ProcessXML(item_zero);
                        }
                        else
                        {
                            return_val = ProcessXML(item_one);
                        }
                    }
                    else
                    {
                        if (HasLore(item_zero))
                        {
                            return_val = ProcessXML(item_one);
                        }
                        else
                        {
                            return_val = ProcessXML(item_zero);
                        }
                    }
                }
                else if (HasDescription(item_zero) ^ HasDescription(item_one))
                {
                    Console.Write("Does this item have a description (y/N)?  ");
                    if (Console.ReadLine().ToLower().StartsWith("Y"))
                    {
                        if (HasDescription(item_zero))
                        {
                            return_val = ProcessXML(item_zero);
                        }
                        else
                        {
                            return_val = ProcessXML(item_one);
                        }
                    }
                    else
                    {
                        if (HasDescription(item_zero))
                        {
                            return_val = ProcessXML(item_one);
                        }
                        else
                        {
                            return_val = ProcessXML(item_zero);
                        }
                    }
                }
                else
                {
                    Console.WriteLine("Two nearly identical items were found. This shouldn't happen!");
                    throw new CrateException("Unable to distinguish two items.");
                }
                break;
            }

            default:
            {
                throw new CrateException($"Found {returned_num} items with the name {search_key}");
            }
            }
            return(return_val);
        }
예제 #8
0
        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();
            }
        }
예제 #9
0
        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);
        }
예제 #10
0
        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);
        }