Example #1
0
 private void CraftItem()
 {
     if (CurrentRecipe == null)
     {
         return;
     }
     else if (BattleManager.Instance.BattleHasEnded == false)
     {
         MessageManager.AddMessage("You can't make that while fighting!");
         CurrentRecipe = null;
         return;
     }
     if (CurrentRecipe.Create(out int created))
     {
         TicksToNextAction = CurrentRecipe.CraftingSpeed;
         MessageManager.AddMessage(CurrentRecipe.GetOutputsString().Replace("$", (created * CurrentRecipe.OutputAmount).ToString()));
         if (CurrentRecipe.CanCreate() == false)
         {
             if (CurrentRecipe.HasSpace())
             {
                 CurrentRecipe.Output.Rerender = true;
                 MessageManager.AddMessage("You have run out of materials.");
                 if (OvenComponent != null)
                 {
                     OvenComponent.Source = "";
                 }
             }
             else
             {
                 MessageManager.AddMessage("You don't have enough inventory space to do it again.");
             }
             if (CurrentRecipe != null)
             {
                 foreach (Ingredient i in CurrentRecipe.Ingredients)
                 {
                     i.Item.Rerender = true;
                 }
             }
             CurrentRecipe = null;
             itemViewer.ClearItem();
         }
         if (CurrentRecipe != null)
         {
             foreach (Ingredient i in CurrentRecipe.Ingredients)
             {
                 i.Item.Rerender = true;
             }
         }
     }
     else
     {
         if (CurrentRecipe.Ingredients.Count == 1 && CurrentRecipe.Ingredients[0].Item.Name == itemViewer.Item.Name && CurrentRecipe.HasSpace())
         {
             itemViewer.ClearItem();
             MessageManager.AddMessage("You have run out of materials.");
             CurrentRecipe.Output.Rerender = true;
             if (OvenComponent != null)
             {
                 OvenComponent.Source = "";
             }
         }
         foreach (Ingredient i in CurrentRecipe.Ingredients)
         {
             i.Item.Rerender = true;
         }
         CurrentRecipe = null;
     }
     if (CraftingComponent != null)
     {
         CraftingComponent.ReloadRecipes();
     }
 }