///-------------------------------------------------------------------------------------------------
        /// <summary>   Creates a recipe. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="recipeName">       Name of the recipe. </param>
        /// <param name="inputs">           The inputs. </param>
        /// <param name="outputs">          The outputs. </param>
        /// <param name="baseRecipe">       The base recipe. </param>
        /// <param name="itemId">           Identifier for the item. </param>
        /// <param name="requiredItems">    The required items. </param>
        /// <param name="recipeCategory">   Category the recipe belongs to. </param>
        ///-------------------------------------------------------------------------------------------------

        public static void CreateRecipe(string recipeName, classes.Input[] inputs, object[] outputs, string baseRecipe, string itemId, string[] requiredItems, string recipeCategory)
        {
            var outputItem = GameResources.Instance.Items.FirstOrDefault(s => s.name == outputs[0].ToString());
            var finalInput = new InventoryItemData[inputs.Length];
            var i          = 0;

            foreach (classes.Input input in inputs)
            {
                var itemVar = GameResources.Instance.Items.FirstOrDefault(s => s.name == input.input_name);
                finalInput[i] = new InventoryItemData {
                    Item = itemVar, Amount = input.input_amount
                };
                i++;
            }

            var recipe = ScriptableObject.CreateInstance <Recipe>();

            recipe.name   = recipeName;
            recipe.Inputs = finalInput;
            recipe.Output = new InventoryItemData {
                Item = outputItem, Amount = Convert.ToInt32(outputs[1])
            };
            if (requiredItems[0] != "")
            {
                var requiredFinal = new ItemDefinition[inputs.Length];
                var iReq          = 0;
                foreach (string item in requiredItems)
                {
                    var instanceVar = GameResources.Instance.Items.FirstOrDefault(s => s.name == item);
                    requiredFinal[iReq] = instanceVar;
                    iReq++;
                }
                recipe.RequiredUpgrades = requiredFinal;
            }
            else
            {
                var baseRecipeTag = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipe);
                recipe.RequiredUpgrades = baseRecipeTag.RequiredUpgrades;
            }
            if (recipeCategory != "")
            {
                recipe.Categories = new RecipeCategory[] { FindCategory.FindCategoryName(recipeCategory) };
            }
            else
            {
                var baseRecipeTag = GameResources.Instance.Recipes.FirstOrDefault(s => s.name == baseRecipe);
                recipe.Categories = baseRecipeTag.Categories.ToArray();
            }

            var guid = GUID.Parse(itemId);

            AssetReference[] assets = new AssetReference[] { new AssetReference()
                                                             {
                                                                 Object = recipe, Guid = guid, Labels = new string[0]
                                                             } };
            RuntimeAssetStorage.Add(assets, default);
        }
        ///-------------------------------------------------------------------------------------------------
        /// <summary>   Generates a category array. </summary>
        ///
        /// <remarks>   MelodicAlbuild, 3/8/2021. </remarks>
        ///
        /// <param name="categories">   The categories. </param>
        ///
        /// <returns>   An array of recipe categories. </returns>
        ///-------------------------------------------------------------------------------------------------

        public static RecipeCategory[] GenerateCategoryArray(string[] categories)
        {
            RecipeCategory[] finalInput = new RecipeCategory[categories.Length];
            var i = 0;

            foreach (string category in categories)
            {
                finalInput[i] = FindCategory.FindCategoryName(category);
                i++;
            }
            return(finalInput);
        }
Example #3
0
        public List <AuctionInfoVM> FindAuction(FindCategory cFind, string value)
        {
            var ListAuctions = new List <AuctionInfoVM>();

            if (cFind == FindCategory.AuctionCategory)
            {
                var categoryId = _aplicationDbContext.AuctionCategories
                                 .SingleOrDefault(p => p.Name == value);

                if (categoryId != null)
                {
                    var Auctions = _aplicationDbContext.Auctions
                                   .Where(p => p.CategoryId == categoryId.Id).ToList();

                    foreach (var item in Auctions)
                    {
                        ListAuctions.Add(GetAuctionInfo(item.Id));
                    }
                }
            }
            else if (cFind == FindCategory.Description)
            {
                var Auctions = _aplicationDbContext.Auctions
                               .Where(p => p.Description == value).ToList();

                foreach (var item in Auctions)
                {
                    ListAuctions.Add(GetAuctionInfo(item.Id));
                }
            }
            else if (cFind == FindCategory.ShippingAddress)
            {
                var Auctions = _aplicationDbContext.Auctions
                               .Where(p => p.ShippingAddress == value).ToList();

                foreach (var item in Auctions)
                {
                    ListAuctions.Add(GetAuctionInfo(item.Id));
                }
            }
            else if (cFind == FindCategory.Customer)
            {
                var customerId = _aplicationDbContext.Organizations
                                 .SingleOrDefault(p => p.FullName == value);

                if (customerId != null)
                {
                    var Auctions = _aplicationDbContext.Auctions
                                   .Where(p => p.OrganizationId == customerId.Id).ToList();

                    foreach (var item in Auctions)
                    {
                        ListAuctions.Add(GetAuctionInfo(item.Id));
                    }
                }
            }
            else if (cFind == FindCategory.StartDate)
            {
                DateTime sdate    = DateTime.Parse(value);
                var      Auctions = _aplicationDbContext.Auctions
                                    .ToList()
                                    .Where(p => p.StartDate.Date == sdate.Date).ToList();

                foreach (var item in Auctions)
                {
                    ListAuctions.Add(GetAuctionInfo(item.Id));
                }
            }
            return(ListAuctions);
        }