jimi
Member
I'm building a custom crafting processor and attempting to get the mutable variant property of an attribute on the selected item while crafting. However, I can't quite figure out how to get the current item with Custom Item Attributes opposed to the default values.
Does the selectedIngredients get the actual item in the inventory with custom Item Attributes or is it just a reference to the default item?
Full Method:
Does the selectedIngredients get the actual item in the inventory with custom Item Attributes or is it just a reference to the default item?
C#:
var ingredientWidthValue = 10;
var ingredient = selectedIngredients.Last.Item;
var ingredientWidth = ingredient.GetAttribute<Attribute<int>>("Width");
//ingredientWidth.SetVariantType(VariantType.Override);
ingredientWidthValue = ingredientWidth.GetValue();
Full Method:
C#:
protected override CraftingResult CraftInternal(CraftingRecipe recipe, IInventory inventory, int quantity,
ListSlice<ItemInfo> selectedIngredients)
{
// Check that the recipe can be crafted.
if (CanCraftInternal(recipe, inventory, quantity, selectedIngredients) == false)
{
return new CraftingResult(null, false);
}
// Remove all the ingredient items from the inventory.
if (RemoveIngredients(inventory, selectedIngredients) == false)
{
return new CraftingResult(null, false);
}
// Get the result of the craft.
var ingredientWidthValue = 10;
ItemAmount[] resultItemAmounts;
var ingredient = selectedIngredients.Last.Item;
var ingredientWidth = ingredient.GetAttribute<Attribute<int>>("Width");
ingredientWidth.SetVariantType(VariantType.Inherit);
ingredientWidthValue = ingredientWidth.GetValue();
Debug.Log(ingredientWidthValue);
resultItemAmounts = new ItemAmount[recipe.DefaultOutput.ItemAmounts.Count];
for (int i = 0; i < resultItemAmounts.Length; i++)
{
var itemAmount = recipe.DefaultOutput.ItemAmounts[i];
var craftedItem = InventorySystemManager.CreateItem(itemAmount.Item);
var qualityAttribute = craftedItem.GetAttribute<Attribute<int>>("Width");
if (qualityAttribute != null)
{
qualityAttribute.SetOverrideValue(ingredientWidthValue);
}
var craftedItemAmount = new ItemAmount(craftedItem, itemAmount.Amount * quantity);
resultItemAmounts[i] = craftedItemAmount;
}
// Add the crafted items in the inventory.
for (int i = 0; i < resultItemAmounts.Length; i++)
{
inventory.AddItem((ItemInfo)resultItemAmounts[i]);
}
// Convert the crafted items into an crafting output.
var output = new CraftingOutput(resultItemAmounts);
// Return a success crafting result.
return new CraftingResult(output, true);
}