Пример #1
0
 /// <summary>Construct an instance.</summary>
 /// <param name="item">The item metadata to copy.</param>
 public SearchableItem(SearchableItem item)
 {
     this.Type       = item.Type;
     this.ID         = item.ID;
     this.CreateItem = item.CreateItem;
     this.Item       = item.Item;
 }
Пример #2
0
 /// <summary>Create a searchable item if valid.</summary>
 /// <param name="type">The item type.</param>
 /// <param name="id">The unique ID (if different from the item's parent sheet index).</param>
 /// <param name="createItem">Create an item instance.</param>
 private SearchableItem TryCreate(ItemType type, int id, Func <SearchableItem, Item> createItem)
 {
     try
     {
         var item = new SearchableItem(type, id, createItem);
         item.Item.getDescription(); // force-load item data, so it crashes here if it's invalid
         return(item);
     }
     catch
     {
         return(null); // if some item data is invalid, just don't include it
     }
 }
Пример #3
0
        /// <summary>
        /// Creates an item by their tag description
        /// </summary>
        /// <param name="description">The tag description</param>
        /// <returns></returns>
        public static Item Create(string description)
        {
            string[] descSplit = description.Trim().Split(' ');
            string[] tagSplit  = descSplit[0].Trim().Split('_');

            try
            {
                ItemType       type    = (ItemType)Enum.Parse(typeof(ItemType), tagSplit[0], ignoreCase: true);
                string         nameTag = "item_" + string.Join("_", tagSplit.Skip(1));
                SearchableItem match   = factory.GetAll()
                                         .Where(p => p.Type == type && p.NameTag == nameTag)
                                         .FirstOrDefault();

                if (match != null && match.Item != null)
                {
                    if (descSplit.Contains("special"))
                    {
                        match.Item.specialItem = true;
                    }

                    if (descSplit.Contains("quest") && match.Item is SObject obj)
                    {
                        obj.questItem.Value = true;
                    }

                    if (descSplit.Contains("lost"))
                    {
                        match.Item.isLostItem = true;
                    }

                    return(match.Item);
                }
            }
            catch (ArgumentException ex)
            {
                throw new ArgumentException($"Invalid item type '{tagSplit[0]}': {ex.Message}");
            }

            return(null);
        }