Hi,
Easy question. I created a custom processor, but how do I apply it?
What should I do with the script?
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);
}
}