I am starting to think about a basic database driven game(rpg).
I am having trouble sorting out how to save the character, his attributes and his items. For most things where there is only one of them static is fine, but when there are mulitple objects like an inventory for example I am at a bit of a loss.
I decided to put items into a bag object. the bag object can have any where from 5 – 20 slots, each of these slots will reference an item based on unique database ID. So how do I design the bag table.
BagID | Owner | Slot1 | Slot2 | Slot3 | Slot4 ……
or
BagID | Owner | Contents <-varbinary
Any suggestions? I was told once that when database programming, one column one data, but I don’t like the idea of Slot1 | Slot2 etc… it just doesn’t seem right.
Edit
Did I miss this altogether, and it is rightfully the item that should be referencing the Bag.
ItemID | BagID | Slot | Name | …..
Then when you want to find out what is in a bag you would
Select * from Items where BagID=10
STANDARD approach since the invention of relational databases way back in the 60ies by cobb is normalization.
BadId, SlotNr, ItemRef
Finished.
Another table has the items.
Note that OwnerId is missing – this is the BagItemMap table. THe BagTable has BagId, OwnerId and possibly other items (total weight etc.)
This is a standard m:n relationshit. WHen you materialize the objects you ahve a Bag object that has the Items as collection.