#Craft multiple things at once

1 messages · Page 1 of 1 (latest)

topaz geyser
#

Simple fix for the crafting panel

#

Go to CraftingPanel.cs

#

add to the top under the line [SerializeField] private Image castBarFill;:

[SerializeField] private TMP_InputField craftAmountInput; private int craftAmount = 1;

#

Change your FixedUpdate method:

`private void FixedUpdate()
{
if (!isCrafting) return;
curCraftTime += Time.deltaTime;
castBarFill.fillAmount = curCraftTime / maxCraftTime;

        if (curCraftTime >= maxCraftTime)
        {
            for (int i = 0; i < craftAmount; i++)
            {
                CraftingManager.Instance.GenerateCraftedItem(selectedRecipe);
            }

            isCrafting = false;
            curCraftTime = 0;
            maxCraftTime = 0;
        }
    }`
#

Change your ClickCraftRecipe method:

`public void ClickCraftRecipe()
{
if (isCrafting || selectedRecipe == null) return;
if (RPGBuilderUtilities.isInventoryFull())
{
UIEvents.Instance.OnShowAlertMessage("The inventory is full", 3);
return;
}

        if (craftAmountInput == null || string.IsNullOrWhiteSpace(craftAmountInput.text))
        {
            craftAmount = 1;
            if (craftAmountInput != null) craftAmountInput.text = "1";
        }
        else if (!int.TryParse(craftAmountInput.text, out craftAmount) || craftAmount <= 0)
        {
            craftAmount = 1;
            craftAmountInput.text = "1";
        }

        var curRank = RPGBuilderUtilities.getRecipeRank(selectedRecipe.ID);
        var rankREF = selectedRecipe.ranks[curRank];

        foreach (var t in rankREF.allComponents)
        {
            int totalAvailable = Character.Instance.CharacterData.Inventory.baseSlots
                .Where(slot => slot.itemID != -1 && slot.itemID == t.componentItemID)
                .Sum(slot => slot.itemStack);

            if (totalAvailable < t.count * craftAmount) return;
        }
                    // Získáme maximální počet craftů, které může hráč udělat
        int maxCraftable = CraftingManager.Instance.getRecipeCraftCount(selectedRecipe);

        // Ořežeme craftAmount na to maximum
        if (craftAmount > maxCraftable)
        {
            craftAmount = maxCraftable;

            // Volitelně hráči řekni, že to bylo omezeno
            UIEvents.Instance.OnShowAlertMessage($"Craft amount limited to {craftAmount} due to available materials.", 3);

            if (craftAmount == 0) return;
        }


        isCrafting = true;
        curCraftTime = 0;
        maxCraftTime = rankREF.craftTime * craftAmount;
    }`
#

Go to the ui_scene
find: RPG_Builder_Essentials

--> go to PANELS ---> Crafting
Add InputField (TMP) - style it to suit your game

#

In the Crafting object is attached crafting panel (script)

#

Assign InputField (TMP) to the last Serializable Object "Craft Amount Input"

#

You are done

#

**The script knows: **

  1. Recognize how much materials you have left and set up max number when you type too big number, it will calculate max
  2. When you leave it blank or write something else then number = it will fall back to 1 = min if you have resources
  3. Calculate the time needed x number of crafted items and extends the crafting time
  4. Give you XP per item if you have attached skill
  5. Take your resources per item
#

**The script doesnt know: **

  1. crafting while UI is closed - it can be done. But i dont want it for my game
#

.
.
Enjoy and leave a like if it helped you :))

#

Bye

gloomy frost
#

def going to add this one