I'm using a custom attribute to be able to have items with procedural stats & modifications. My attribute is simply keeping that randomized mods.
But first I have to generate those mods for the item (ideally when the item is initialized / created in the inventory system)
I can use EventNames.c_Inventory_OnAdd_ItemInfo_ItemStack event to be aware when that item type is added, then I can access the item to randomize values and apply to the attribute, but as I see that event just responsible for a specific inventory, but I need to do this globally, like when an item from that category drops from a monster, or spawned in a shop, lootbox etc.
I tried to make that attribute a Monobehaviour so that I can use OnAwake() for this, but I can not access if the attribute is monobehaviour and gives nullreference error.
For now, I'm manually iterating my characters itemCollection and generate data for those kind of items to be able to test my gameplay;
But first I have to generate those mods for the item (ideally when the item is initialized / created in the inventory system)
I can use EventNames.c_Inventory_OnAdd_ItemInfo_ItemStack event to be aware when that item type is added, then I can access the item to randomize values and apply to the attribute, but as I see that event just responsible for a specific inventory, but I need to do this globally, like when an item from that category drops from a monster, or spawned in a shop, lootbox etc.
I tried to make that attribute a Monobehaviour so that I can use OnAwake() for this, but I can not access if the attribute is monobehaviour and gives nullreference error.
For now, I'm manually iterating my characters itemCollection and generate data for those kind of items to be able to test my gameplay;
Code:
opInventory = player.GetComponent<Inventory>();
ItemCollection ItemCollection = opInventory.GetItemCollection("NewItemCollection");
var allItemStacks = ItemCollection.GetAllItemStacks();
for (int i = 0; i < allItemStacks.Count; i++)
{
var itemStack = allItemStacks[i];
var item = itemStack.Item;
if(item == null){ continue;}
if (item.GetItemCategory().name == "Submodule")
{
var sData = item.GetAttribute<Attribute<SubmoduleData>>("Submodule Data");
if (sData.GetValue() == null)
Debug.LogWarning("submoduleData is null");
if (sData.GetValue().itemLevel == 0) //means its not generated yet, minimum level is 1
{
GenerateSubmodule();
sData.SetOverrideValue(GenerateSubmoduleData());
}
}
Last edited: