I’ve hit a wall in my logic and need some help figuring out the next piece dealing with different “types” of items and having an interesting way of dynamically generating loot for containers.
When a container is created I generate it’s contents, I had this originally separating the items in different structs like “Weapons”, “Consumables” etc… but I realized I can’t return an array of different type structs to my player after they “Open the container and get all the loot”
Am I stuck with having to put all items into one struct and manually creating individual loot tables for all the different combinations and attaching those to my containers (which seems really tedious) or can I programmatically define them somehow?
Currently I’m also leveraging a weight system which makes sense to me for picking one item, but what if I want to give the user X amount of items? Do I need to attach a total value to the container as well as a value to each individual item and then add up each item that gets picked from the weighted loot table then stop generating when the total is reached?
And then last thought is, if I’m using one struct to house all my items, I’ll need to leverage Enums to define Item type so I know which Items are “weapons” allowing my player to equip those, etc…
Would you then leverage a TMap<Enum Item Type : TArray for the player’s inventory?
I hope this makes sense, I’ve been spinning in my head while reading/watching a lot but the solutions I saw stop after generating randomly one item.
Here’s what I do for my inventory system. Every item only ever has the same struct so it can be stored in a array. You store the minimal information to find the item, not the whole item’s information.
Use the ItemID to find it in the DT_ItemType (DT_Weapon/DT_Armor/DT_Consumable). Your system has weight so you may want to do more calculation moving around containers beside quantity.
Container loot generation would use ItemID/Quantity/SpawnChance to generate loot array. I make several DataTable for different container with rows like
I use SpawnWeight to determine the chance of spawning. In this table, all rows have the same chance to spawn because their weights are the same. Once the row is determined, do a random amount in Min/Max.
How I generate from DT:
1.Get total amount of rows(items) and total weight of all items
If your loot logic has more things going on like not repeating loot, handle that within the function. I parse the out put struct array to another function that stacks any potential stackable items within the array.