Exemplo n.º 1
0
        /// <summary>
        /// Copies the Item
        /// </summary>
        /// <returns>A copy of the item</returns>
        public override Item Copy()
        {
            UnknownItem item = new UnknownItem();

            copyAttributes(item);
            return(item);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Parses a single item from item reader output
        /// </summary>
        /// <param name="input">The item text to parse from</param>
        /// <returns>The parsed item</returns>
        public static Item ParseItem(string input)
        {
            input = input.Trim();
            string remainder = input;
            Item   item      = null;

            if (input == string.Empty)
            {
                return(null);
            }

            try
            {
                List <string> attributeSections = new List <string>();

                while (remainder.Contains('['))
                {
                    if (!remainder.Contains(']'))
                    {
                        throw new Exception("No matching end bracket.");
                    }

                    int start = remainder.IndexOf('[');
                    int end   = remainder.IndexOf(']', start);
                    attributeSections.Add(remainder.Substring(start + 1, end - start - 1));
                    remainder = remainder.Remove(start, end - start + 1);
                }

                bool   quantityFound = false;
                int    grind         = parseGrind(ref remainder);
                int    quantity      = parseQuantity(ref remainder, out quantityFound);
                string sRankName     = parseSRankName(ref remainder);

                // What remains should be the name of the item
                remainder = remainder.Trim();
                item      = ItemDatabase.Instance.FindItem(remainder, input);

                if (item == null)
                {
                    throw new Exception("Item not found!");
                }

                item.Quantity = quantity;
                item.ParseAttributes(attributeSections);

                if (item is Weapon weapon)
                {
                    weapon.Grind     = grind;
                    weapon.SRankName = sRankName;
                }

                item.ItemReaderText = input;
                if (quantityFound)
                {
                    item.ItemReaderText = item.ItemReaderText.Replace("x" + quantity.ToString(), "").Trim();
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine("Exception: {0}", ex.ToString());
                item = new UnknownItem();
                item.ItemReaderText = input;
            }

            return(item);
        }