Back in July I asked this question:
https://community.playfab.com/questions/3752/read-custom-data-from-iteminstance.html#answer-3772
and since then this became a feature:
https://community.playfab.com/content/idea/895/210537287-Atomically-Creating-Items.html
So coming back to finish our title's inventory system in September and deciding my original question didn't really reach the conclusion I wanted, I started looking around for other similar questions since then but with every helpful thread I found I kept getting more and more questions.
Here is how our titles inventory system works:
The system has items, some items have customData say a weapon or piece of armor and these have stats defined as customData in the catalog, when an item is granted we generate randomized stats based on rarity (we also generate rarity even after drop tables already do this so I put in this request: https://community.playfab.com/content/idea/3842/access-drop-table-odds.html )
when granting the item we want to set the custom data for that item instance but first we need to get the customData from the catalog version of the item we are granting as the global "base stats" of the item with the customData based on the rarity being the "modifier" of those base stats. To do this we need to do this:
and before I found that thread I had this in my cloud script:
var getCatalogItemsResponse = server.GetCatalogItems({CatalogVersion: null}); var catalogItems = getCatalogItemsResponse.Catalog; var length = catalogItems.length; var catalogItemInstance; for(var i = 0; i <= length; i++) { if(catalogItems[i].ItemId) == itemId)//itemId being the item id of the item we are granting (these are all unique in the catalog). Note: I tried JSON.parse(catalogItems[i]) and got errors. { catalogItemInstance = catalogItems[i]; } }
So I have to iterate through all the catalog items to find the catalog item with the ID matching the Id of the item I am trying to grant and set itemInstance customData for. I can't seem to get the ID off the catalog item instance though.
This also helps determine what kind of stats the item has.
Example:
var ItemStat = catalogItemInstance.CustomData["keyname"] * rarityModifier;
when granting the item we would set ItemStat as the value of a customData key in the itemInstance before it is added to the inventory.
The end result I am trying to get is:
1) catalog items with the universal "base stats", when these are changed all item instances apply their rarity modifiers to the new base stat.
2) All ItemInstances in the players inventory are unique to almost all other items in other players inventory (random stats/rarities) and I can access the customData that is in the inventory itemInstance we defined when granting the item for use in gameplay mechanics.
I would like it if someone can lay this all out for me or share how they did this or something similar, I'm sure a lot of people have similar questions but it seems every answer I find gives me several more questions.