Custom crafting processors

Chris

New member
Hi,

Easy question. I created a custom processor, but how do I apply it?

What should I do with the script?

C#:
public class LevelCraftingProcessor : SimpleCraftingProcessor
{
    /// <summary>
    /// Check if the parameters are valid to craft an item.
    /// </summary>
    /// <param name="recipe">The recipe.</param>
    /// <param name="inventory">The inventory containing the items.</param>
    /// <param name="quantity">The quantity to craft.</param>
    /// <param name="selectedIngredients">The item infos selected.</param>
    /// <returns>True if you can craft.</returns>
    protected override bool CanCraftInternal(CraftingRecipe recipe, IInventory inventory, int quantity, ListSlice<ItemInfo> selectedIngredients)
    {
        // Get the character level from your custom character script.
        var myCharacterLevel = inventory.gameObject.GetComponent<CharacterController>().GetComponent<XPMonitor>().m_Level;
        // Find the level required by the recipe.
        var levelRequired = 0;

        // Option 2: create a custom recipe with a level field and use that field as the constraint.
        if (recipe is CraftingRecipeCurrencyLevel customRecipeCurrency)
        {
            levelRequired = customRecipeCurrency.LevelRequired;
        }

        if (recipe is CraftingRecipeLevel customRecipe)
        {
            levelRequired = customRecipe.LevelRequired;
        }

        if (myCharacterLevel < levelRequired) { return false; }

        return base.CanCraftInternal(recipe, inventory, quantity, selectedIngredients);
    }
}
 
So right now the demo crafting UI contains the crafting processor... not great I know, I'm changing that in V1.1. It requires you to create a completely new UI or modify the demo crafting UI to test out your processor.
There are a few people who got it working. The scripts of interest are CraftingMenu and RecipePanel, there you'll see I create a crafting processor during initialization.

Note that in V1.1 I split the UI and the functionality such that the crafting processor is defined in a "Crafter/Crafting" component (not 100% sure on the name). The crafting UI will then use that component to get the recipes available and the crafting processor.
 
Top