#The item SO shouldn't have a quantity
1 messages · Page 1 of 1 (latest)
Sorry, it's a bit complex, I ran out of words earlier. The item class stores all the ingredients used to craft and the potions are things that can result from crafting. (Alchemy game so it's the main focus).
I'll definitely check some tutorials on the grid based inventory systems, it might give me some clarity on the matter.
What I mean for the last part is that I may have a multidimensional array (I think 3D would be the right term for an array that holds a value for 0,0 as the top left, 0,1 as the top middle, 0,2 at the top right, 1,0 as the middle left... etc.) that holds dictionaries in each array slot instead of something like a simple int value. Dictionaries are a List type that takes two values, a Key and a Value of which are generic types. In a dictionary when you call a Key, it returns the Value, so I was thinking that each of the ingredients would input a key into the crafting grid, and then the result would be a value. The value would be where the 'root' (can only be one square, would be designated per item/ingredient) of the shape is in the crafting grid (for math that's not completely relevant here). The value would also return a type of mana that the value would be added to. The values go A-F.
So I could put the item "Charcoal" into the bottom middle slot (3D array value 2,1) and the shape may take up bot 2,1 and 1,2 (like a diagnol of 2 squares, just an example). The resulting value for charcoal in that specific library contained with the array at index 2,1 would then spit out a value of say manaType: A, totalStrength: 10. The crafting grid (the 3x3 minecraft-style grid) would total the manaType and Strength values of all this together to get a total.
Let's say that total is Type A: 100, Type B:20, Type C:100. Then the value of all of those would pass to a ratio value using some method and then pass through a switch statement to display the result of the crafting which would be a Potion scriptable object.
It makes sense in my head I think...
Also, if I don't store the value of the item quantity in the scriptable object, how would I go about keeping track of how many my player has? I have a working Inventory system (early stages) that keeps track of all these and displays to the UI... But if I'm handling it poorly I'd love to have another idea on how to go about it.
Sorry, I've been at work since my first response. As I mentioned before, it's a 2D array consisting of a row and column. A 3D array would be 3 layers with a row, column, and depth
It's more simple than that. You can store an item class or container in each cell of the grid—by default, they're all null. When you add an item, you start at the selected grid cell (x/y) and add the width/height of the item to get the size of each loop. Then iterate and check if each cell is occupied (null)
If a cell is not null, return false (if AddItem returns a bool) . If not, you repeat the same loop for x,y and assign each cell to the item. Create a method to check if a specific cell is occupied and use that method when attempting to add the item . . .
A ScriptableObject should only consist of data you read from, not write to. Storing the quantity in an SO means that it would change, and any other item referencing that SO—to gets its name, stats, etc.,—would also have that same quantity value, which is incorrect. If you want to store the same item in multiple slots/cells, you have to store the quantity in the cell itself (which contains an Item or ItemContainer class) . . .
I forgot to say, your item SO would store its width and height (how much grid space it occupies) and you access that to determine the size of each loop (x/y) when attempting to add an item . . .
That all makes perfect sense. For my specific game's purpose I think storing the data in an SO would work, but I can see it posing problems in future projects so I'll just go ahead and change that now. Thanks for that. Also that's a good idea for the grid space. I think that would be much simpler than what I was trying yesterday!
Thanks for you feedback!