예제 #1
0
        public override void DoSmelt(IWorldAccessor world, ISlotProvider cookingSlotsProvider, ItemSlot inputSlot, ItemSlot outputSlot)
        {
            ItemStack[] stacks = GetCookingStacks(cookingSlotsProvider);

            CookingRecipe recipe = GetMatchingCookingRecipe(world, stacks);

            Block     block       = world.GetBlock(CodeWithPath(CodeWithoutParts(1) + "-cooked"));
            ItemStack outputStack = new ItemStack(block);

            if (recipe != null)
            {
                int quantityServings = recipe.GetQuantityServings(stacks);
                for (int i = 0; i < stacks.Length; i++)
                {
                    stacks[i].StackSize /= quantityServings;
                }

                ((BlockCookedContainer)block).SetContents(recipe.Code, quantityServings, outputStack, stacks);

                outputStack.Collectible.SetTemperature(world, outputStack, GetIngredientsTemperature(world, stacks));
                outputSlot.Itemstack = outputStack;
                inputSlot.Itemstack  = null;

                for (int i = 0; i < cookingSlotsProvider.Slots.Length; i++)
                {
                    cookingSlotsProvider.Slots[i].Itemstack = null;
                }
                return;
            }
        }
예제 #2
0
        public MeshRef GetOrCreateMealMeshRef(CompositeShape containerShape, CookingRecipe forRecipe, ItemStack[] contentStacks, Block block, Vec3f foodTranslate = null)
        {
            Dictionary <int, MeshRef> meshrefs = null;

            object obj;

            if (capi.ObjectCache.TryGetValue("cookedMeshRefs", out obj))
            {
                meshrefs = obj as Dictionary <int, MeshRef>;
            }
            else
            {
                capi.ObjectCache["cookedMeshRefs"] = meshrefs = new Dictionary <int, MeshRef>();
            }

            if (contentStacks == null)
            {
                return(null);
            }

            int mealhashcode = GetMealHashCode(containerShape, capi.World, contentStacks);

            MeshRef mealMeshRef = null;

            if (!meshrefs.TryGetValue(mealhashcode, out mealMeshRef))
            {
                meshrefs[mealhashcode] = mealMeshRef = capi.Render.UploadMesh(CreateMealMesh(containerShape, forRecipe, contentStacks, block, foodTranslate));
            }

            return(mealMeshRef);
        }
예제 #3
0
        public CookingRecipe Reward()
        {
            if (reward == null)
            {
                if (Romancable.ParentObject.GetPart <acegiak_Romancable>() == null)
                {
                    //IPart.AddPlayerMessage("no romancable");
                    return(null);
                }

                List <GameObject> foods = Romancable.preferences
                                          .Where(b => b is acegiak_FoodPreference).Select(b => (acegiak_FoodPreference)b)
                                          .OrderBy(o => Stat.Rnd2.NextDouble())
                                          .Select(b => b.exampleObject())
                                          .ToList();

                if (foods.Count() <= 0)
                {
                    //IPart.AddPlayerMessage("no example object");
                    return(null);
                }
                List <GameObject> GList = new List <GameObject>();

                reward = CookingRecipe.FromIngredients(GList);
            }
            return(reward);
        }
예제 #4
0
        public async Task <int> CreateCookingRecipeAsync(CookingRecipe cookingRecipe)
        {
            await this.DbContext.CookingRecipes.AddAsync(cookingRecipe);

            await this.DbContext.SaveChangesAsync();

            //possible incorect id
            return(cookingRecipe.Id);
        }
예제 #5
0
 private void DiscoverRecipes()
 {
     _cookingRecipes = new List <CookingRecipe>();
     foreach (var recipe in CraftingRecipe.cookingRecipes)
     {
         var cookingRecipe = new CookingRecipe(recipe.Key, recipe.Value);
         if (Game1.player.cookingRecipes.ContainsKey(cookingRecipe.Name))
         {
             cookingRecipe.IsKnown = true;
         }
         _cookingRecipes.Add(cookingRecipe);
     }
 }
예제 #6
0
        public override acegiak_RomanceChatNode BuildNode(acegiak_RomanceChatNode node)
        {
            node.Text = "Are you hungry? I'd like to make you " + Reward().GetDisplayName() + ".";

            node.AddChoice("End", "Thankyou! [Eat " + Reward().GetDisplayName() + "].", "You're very welcome.", -30, delegate(){
                IPart.PlayUISound("Human_Eating");
                Reward().ApplyEffectsTo(XRLCore.Core.Game.Player.Body);
                Popup.ShowBlock("You eat " + this.Romancable.ParentObject.the + this.Romancable.ParentObject.DisplayNameOnly + "'s " + Reward().GetDisplayName() + "!");
                this.reward = null;
            });
            node.AddChoice("rejectgift", "No thankyou.", "Oh I'm sorry. That makes sense.", -30);
            return(node);
        }
예제 #7
0
        private void DiscoverRecipes()
        {
            var knownRecipes = Game1.player.cookingRecipes.Keys;

            _cookingRecipes = new List <CookingRecipe>();
            foreach (var recipe in CraftingRecipe.cookingRecipes)
            {
                var cookingRecipe = new CookingRecipe(recipe.Key, recipe.Value);
                if (Game1.player.cookingRecipes.ContainsKey(cookingRecipe.Name))
                {
                    cookingRecipe.IsKnown = true;
                }
                _cookingRecipes.Add(cookingRecipe);
            }

            var unknownRecipeCount = _cookingRecipes.Where(x => !x.IsKnown).Count();
        }
예제 #8
0
        public MeshData CreateMealMesh(CompositeShape cShape, CookingRecipe forRecipe, ItemStack[] contentStacks, Block inBlock, Vec3f foodTranslate = null)
        {
            MealTextureSource source = new MealTextureSource(capi, inBlock);
            Shape             shape  = capi.Assets.TryGet("shapes/" + cShape.Base.Path + ".json").ToObject <Shape>();

            MeshData containerMesh;

            capi.Tesselator.TesselateShape("meal", shape, out containerMesh, source, new Vec3f(cShape.rotateX, cShape.rotateY, cShape.rotateZ));

            if (forRecipe != null)
            {
                MeshData foodMesh = GenFoodMixMesh(contentStacks, forRecipe, foodTranslate);
                containerMesh.AddMeshData(foodMesh);
            }

            return(containerMesh);
        }
예제 #9
0
        public void CreateCookingRecipe(string creatorId, CreateRecipeViewModel viewModel)
        {
            var cookingRecipe = new CookingRecipe()
            {
                Title = viewModel.Title,
                ShortDescription = viewModel.ShortDescription,
                ExecutingTime = viewModel.ExecutingTime,
                Products = viewModel.Products,
                Content = viewModel.Content,
                Hashtags = viewModel.Hashtags,
                CreationDate = DateTime.UtcNow,
                LastModifiedAt = DateTime.UtcNow,
                CreatorId = creatorId,
                CoverImageFileName = viewModel.CoverImageFileName,
            };

            var newCookingRecipeId = this.cookingRecipeRepo
                .CreateCookingRecipeAsync(cookingRecipe)
                .GetAwaiter().GetResult();
        }
예제 #10
0
        public override void OnBeforeRender(ICoreClientAPI capi, ItemStack itemstack, EnumItemRenderTarget target, ref ItemRenderInfo renderinfo)
        {
            if (meshCache == null)
            {
                meshCache = capi.ModLoader.GetModSystem <MealMeshCacheFix>();
            }

            CookingRecipe recipe = GetCookingRecipe(capi.World, itemstack);

            ItemStack[] contents = GetContents(capi.World, itemstack);

            float yoff = 2.5f; // itemstack.Attributes.GetInt("servings");

            MeshRef meshref = meshCache.GetOrCreateMealMeshRef(this.Shape, recipe, contents, this, new Vec3f(0, yoff / 16f, 0));

            if (meshref != null)
            {
                renderinfo.ModelRef = meshref;
            }
        }
예제 #11
0
        /// <summary>
        /// Gets the formatted string representing the list of ingredients required to cook this recipe.
        /// Shorter than the default game version of the ingredient list, which repeats "1 serving of "
        /// before every ingrient. Instead, this function returns a string similar to "1 serving each
        /// of <ingredient_one>, <ingredient_two>, and <ingredient_three>". This slightly shorter
        /// phrasing helps ensure the ingredient list can always fit on two lines in the menu.
        /// </summary>
        /// <remarks>
        ///  * I am 99% sure a recipe can never call for an amount > 1 of any single ingredient.
        ///    However, I've implemented logic below to account for this possiblity just to be safe.
        ///  * This method defaults to using the "serving" language always, even for liquids. The
        ///    default game uses "drams" but "serving" seems an appropriate adjective for liquids
        ///    in the context of cooking a recipe, and allows us to use simpler phrasing herein.
        /// </remarks>
        public static string GetBriefIngredientList(this CookingRecipe recipe)
        {
            string        ingredientList      = string.Empty;
            int           maxAmount           = 0;
            List <string> ingredientNamesOnly = new List <string>(recipe.Components.Count);
            List <int>    ingredientAmounts   = new List <int>(recipe.Components.Count);

            for (int i = 0; i < recipe.Components.Count; i++)
            {
                ICookingRecipeComponent component = recipe.Components[i];
                ingredientAmounts.Add(component.GetComponentAmount());
                ingredientNamesOnly.Add(component.GetComponentSimpleName());
                if (ingredientAmounts[i] > maxAmount)
                {
                    maxAmount = ingredientAmounts[i];
                }
            }
            if (maxAmount == 1)
            {
                ingredientList = "1 serving " + (recipe.Components.Count > 1 ? "each" : string.Empty) + " of ";
                for (int i = 0; i < recipe.Components.Count; i++)
                {
                    ingredientList += ingredientNamesOnly[i].PrependListElementJoinString(i, recipe.Components.Count);
                    ingredientList += "{{K|(" + CookingGamestate.GetIngredientQuantity(recipe.Components[i]) + ")}}";
                }
            }
            else
            {
                for (int i = 0; i < recipe.Components.Count; i++)
                {
                    string thisIngredient = ingredientAmounts[i].ToString() + " serving" + (ingredientAmounts[i] > 1 ? "s" : string.Empty);
                    thisIngredient += " of " + ingredientNamesOnly[i];
                    ingredientList += (i > 0 ? ", " : string.Empty) + thisIngredient;
                    ingredientList += "{{K|(" + CookingGamestate.GetIngredientQuantity(recipe.Components[i]) + ")}}";
                }
            }
            return(ingredientList);
        }
예제 #12
0
    void Cook()
    {
        // Get the current item the player has equiped in WEAPON slot. This needs to be a bit more elegant in the future.
        Item ingredient = EquipmentManager.instance.GetCurrentEquipment(EquipmentSlot.Weapon);

        if (ingredient == null)
        {
            return;
        }

        CookingRecipe recipe = CookingManager.instane.GetRecipe(ingredient);

        if (recipe != null)
        {
            // Shouldn't even use equipment. change in future.
            EquipmentManager.instance.Unequip((int)EquipmentSlot.Weapon);
            // Unequip moves item to inventory. Must delete from there too.
            Inventory.instance.Remove(ingredient);

            Item  result   = recipe.result;
            float duration = recipe.cookingTime;
            StartCoroutine(CookingProcess(result, duration));
        }
    }
예제 #13
0
 public async Task UpdateCookingRecipeAsync(CookingRecipe updatingModel)
 {
     this.DbContext.CookingRecipes.Update(updatingModel);
     await this.DbContext.SaveChangesAsync();
 }
예제 #14
0
 public async Task DeleteAsync(CookingRecipe cookingRecipe)
 {
     this.DbContext.CookingRecipes.Remove(cookingRecipe);
     await this.DbContext.SaveChangesAsync();
 }
예제 #15
0
        /// <summary>
        /// Our main menu screen method. Draws the recipe selection screen and handles related functions.
        /// </summary>
        /// <remarks>
        /// This (and several supporting methods) are static just for simplicity's sake, because it
        /// is easier to call from a Harmony patch when it's static. If we were implementing this
        /// directly, we wouldn't make this static.
        /// </remarks>
        public static ScreenReturn Show(List <Tuple <string, CookingRecipe> > recipeList, out int screenResult)
        {
            screenResult = -1;
            if (recipeList == null || recipeList.Count <= 0 || recipeList.Any(r => r.Item2 == null))
            {
                return(ScreenReturn.Exit);
            }

            recipeList.Sort(RecipeComparator);

            GameManager.Instance.PushGameView("QudUX:CookRecipes");
            ScreenBuffer cachedScrapBuffer = ScreenBuffer.GetScrapBuffer2(true);
            Keys         keys                = Keys.None;
            bool         shouldExitMenu      = false;
            int          scrollOffset        = 0;
            int          scrollAreaHeight    = 11;
            int          selectedRecipeIndex = 0;

            while (!shouldExitMenu)
            {
                ScrapBuffer.Clear();
                //Event.ResetPool();  // Can't call this here because there are active event pool lists in use by the enclosing Campfire code
                CookingRecipe selectedRecipe = recipeList[selectedRecipeIndex].Item2;

                //TODO: HANDLE 0 RECIPES (because user deleted them all)

                //Draw main box
                ScrapBuffer.TitledBox("Recipes");
                ScrapBuffer.SingleBoxHorizontalDivider(14);
                ScrapBuffer.EscOr5ToExit();
                //Help text
                ScrapBuffer.Write(2, 0, " {{W|2}} or {{W|8}} to scroll ");
                ScrapBuffer.Write(2, 24, " {{W|Space}}/{{W|Enter}} - Cook ");
                ScrapBuffer.Write(45, 24, " {{W|F}} - Favorite ");
                ScrapBuffer.Write(62, 24, " {{W|D}}/{{W|Del}} - Forget ");

                //Draw scrollable recipe list
                for (int drawIndex = scrollOffset; drawIndex < recipeList.Count && drawIndex - scrollOffset < scrollAreaHeight; drawIndex++)
                {
                    CookingRecipe recipe = recipeList[drawIndex].Item2;
                    string        name   = ColorUtility.StripFormatting(recipe.GetDisplayName());
                    if (name.Length > 74)
                    {
                        name = name.Substring(0, 71) + "...";
                    }
                    name = (recipe.CheckIngredients() ? "{{W|" + name + "}}" : "{{K|" + name + "}}");
                    name = (recipe.Favorite ? "{{R|\u0003" + name + "}}" : name);
                    int xPos = recipe.Favorite ? 4 : 5;
                    int yPos = 2 + (drawIndex - scrollOffset);

                    ScrapBuffer.Write(xPos, yPos, name);

                    if (drawIndex == selectedRecipeIndex)
                    {
                        ScrapBuffer.Write(2, yPos, "{{Y|>}}");
                    }
                }

                //Draw ingredients
                int bottomPaneTextStartPos = 2;
                int maxBottomPaneWidth     = 76;
                int ingredientPaneStartRow = 15;
                int ingredientPaneHeight   = 2;
                ScrapBuffer.Goto(bottomPaneTextStartPos, ingredientPaneStartRow);
                List <string> ingredients = StringFormat.ClipTextToArray(selectedRecipe.GetBriefIngredientList(), maxBottomPaneWidth);
                for (int i = 0; i < ingredients.Count && i < ingredientPaneHeight; i++)
                {
                    ScrapBuffer.WriteLine(ingredients[i]);
                }

                //Draw recipe effect description
                int           recipeDescriptionPaneStartRow = 18;
                int           recipeDescriptionPaneHeight   = 6;
                List <string> description = StringFormat.ClipTextToArray(selectedRecipe.GetDescription(), maxBottomPaneWidth, KeepNewlines: true);
                if (description.Count > 6)
                {
                    //This should be extremely rare - but if some single effects are longer than 2 lines for instance, this removes
                    //line breaks to condense the effect description and ensure it can fit on 6 lines total.
                    description = StringFormat.ClipTextToArray(selectedRecipe.GetDescription(), maxBottomPaneWidth, KeepNewlines: false);
                }
                ScrapBuffer.Goto(bottomPaneTextStartPos, recipeDescriptionPaneStartRow);
                for (int i = 0; i < description.Count && i < recipeDescriptionPaneHeight; i++)
                {
                    ScrapBuffer.WriteLine(description[i]);
                }

                //Draw the screen
                Console.DrawBuffer(ScrapBuffer);

                //Respond to keyboard input
                keys = Keyboard.getvk(Options.MapDirectionsToKeypad);

                if (keys == Keys.Escape || keys == Keys.NumPad5)
                {
                    screenResult   = -1;                   //canceled
                    shouldExitMenu = true;
                }
                if (keys == Keys.NumPad8)
                {
                    if (selectedRecipeIndex == scrollOffset)
                    {
                        if (scrollOffset > 0)
                        {
                            scrollOffset--;
                            selectedRecipeIndex--;
                        }
                    }
                    else if (selectedRecipeIndex > 0)
                    {
                        selectedRecipeIndex--;
                    }
                }
                if (keys == Keys.NumPad2)
                {
                    int maxIndex = recipeList.Count - 1;
                    if (selectedRecipeIndex < maxIndex)
                    {
                        selectedRecipeIndex++;
                    }
                    if (selectedRecipeIndex - scrollOffset >= scrollAreaHeight)
                    {
                        scrollOffset++;
                    }
                }
                if (keys == Keys.Prior)                 //PgUp
                {
                    selectedRecipeIndex = ((selectedRecipeIndex != scrollOffset) ? scrollOffset : (scrollOffset = Math.Max(scrollOffset - (scrollAreaHeight - 1), 0)));
                }
                if (keys == Keys.Next)                 //PgDn
                {
                    if (selectedRecipeIndex != scrollOffset + (scrollAreaHeight - 1))
                    {
                        selectedRecipeIndex = scrollOffset + (scrollAreaHeight - 1);
                    }
                    else
                    {
                        int advancementDistance = scrollAreaHeight - 1;
                        selectedRecipeIndex += advancementDistance;
                        scrollOffset        += advancementDistance;
                    }
                    selectedRecipeIndex = Math.Min(selectedRecipeIndex, recipeList.Count - 1);
                    scrollOffset        = Math.Min(scrollOffset, recipeList.Count - 1);
                }
                if (keys == Keys.F)
                {
                    selectedRecipe.Favorite = !selectedRecipe.Favorite;
                    recipeList.Sort(RecipeComparator);
                    if (selectedRecipe.Favorite)
                    {
                        //if this was just marked as a favorite, update selection index to continue to point to it where it was moved
                        for (int i = 0; i < recipeList.Count; i++)
                        {
                            if (recipeList[i].Item2 == selectedRecipe)
                            {
                                selectedRecipeIndex = i;
                                //scroll the selection back into view if needed
                                if (selectedRecipeIndex < scrollOffset || selectedRecipeIndex >= (scrollOffset + scrollAreaHeight))
                                {
                                    scrollOffset = Math.Max(0, selectedRecipeIndex - (scrollAreaHeight / 2));
                                }
                            }
                        }
                    }
                }
                if (keys == Keys.D || keys == Keys.Delete)
                {
                    if (Popup.ShowYesNo("{{y|Are you sure you want to forget your recipe for }}" + selectedRecipe.GetDisplayName() + "{{y|?}}") == DialogResult.Yes)
                    {
                        selectedRecipe.Hidden = true;
                        for (int i = 0; i < recipeList.Count; i++)
                        {
                            if (recipeList[i].Item2 == selectedRecipe)
                            {
                                recipeList.RemoveAt(i);
                                break;
                            }
                        }
                        selectedRecipeIndex = Math.Min(selectedRecipeIndex, recipeList.Count - 1);
                        scrollOffset        = Math.Min(scrollOffset, recipeList.Count - 1);
                    }
                }
                if (keys == Keys.Space || keys == Keys.Enter)
                {
                    if (!selectedRecipe.CheckIngredients())
                    {
                        List <ICookingRecipeComponent> missingComponents = selectedRecipe.Components.Where(c => !c.doesPlayerHaveEnough()).ToList();
                        string message = "{{y|You don't have enough servings of }}";
                        int    idx     = 0;
                        foreach (ICookingRecipeComponent component in missingComponents)
                        {
                            message += component.GetComponentSimpleName().PrependListElementJoinString(idx++, missingComponents.Count, "or");
                        }
                        message += "{{y| to cook }}" + selectedRecipe.GetDisplayName() + "{{y|.}}";
                        Popup.Show(message, LogMessage: false);
                        continue;
                    }
                    else if (Popup.ShowYesNo("Cook " + selectedRecipe.GetDisplayName() + "&y?") == DialogResult.Yes)
                    {
                        screenResult   = selectedRecipeIndex;
                        shouldExitMenu = true;
                    }
                }
            }

            //Screen exit
            Console.DrawBuffer(cachedScrapBuffer);
            GameManager.Instance.PopGameView(true);
            return(ScreenReturn.Exit);
        }
예제 #16
0
        public MeshData GenFoodMixMesh(ItemStack[] contentStacks, CookingRecipe recipe, Vec3f foodTranslate, Block inBlock)
        {
            MeshData          mergedmesh = null;
            MealTextureSource texSource  = new MealTextureSource(capi, inBlock);

            Shape shape = capi.Assets.TryGet("shapes/" + recipe.Shape.Base.Path + ".json").ToObject <Shape>();
            Dictionary <CookingRecipeIngredient, int> usedIngredQuantities = new Dictionary <CookingRecipeIngredient, int>();

            for (int i = 0; i < contentStacks.Length; i++)
            {
                texSource.ForStack = contentStacks[i];
                CookingRecipeIngredient ingred = recipe.GetIngrendientFor(
                    contentStacks[i],
                    usedIngredQuantities.Where(val => val.Key.MaxQuantity <= val.Value).Select(val => val.Key).ToArray()
                    );

                if (ingred == null)
                {
                    ingred = recipe.GetIngrendientFor(contentStacks[i]);
                }
                else
                {
                    int cnt = 0;
                    usedIngredQuantities.TryGetValue(ingred, out cnt);
                    cnt++;
                    usedIngredQuantities[ingred] = cnt;
                }

                if (ingred == null)
                {
                    continue;
                }


                MeshData meshpart;
                string[] selectiveElements = null;

                CookingRecipeStack recipestack = ingred.GetMatchingStack(contentStacks[i]);

                if (recipestack.ShapeElement != null)
                {
                    selectiveElements = new string[] { recipestack.ShapeElement }
                }
                ;
                texSource.customTextureMapping = recipestack.TextureMapping;

                capi.Tesselator.TesselateShape(
                    "mealpart", shape, out meshpart, texSource,
                    new Vec3f(recipe.Shape.rotateX, recipe.Shape.rotateY, recipe.Shape.rotateZ), 0, 0, null, selectiveElements
                    );

                if (mergedmesh == null)
                {
                    mergedmesh = meshpart;
                }
                else
                {
                    mergedmesh.AddMeshData(meshpart);
                }
            }

            if (foodTranslate != null)
            {
                mergedmesh.Translate(foodTranslate);
            }

            return(mergedmesh);
        }