Sunday, June 28, 2015

architecture - Creating a database with special items, like in Diablo


I am in the middle of creating a browser game. I need to add 'special items' like in Diablo, but simpler. Item names are fixed (e.g. 'ring of power'), so only their attributes change.


In my game there are different towns. Each town may trade a different set of items with randomized characteristics. For instance, in Town A a 'ring of power' will have better attributes than the same item in Town B (and, thus, it will cost more).


My question is how to construct the database to handle this.


After constructing the database I will create a small script that will assign a different subset of items in each town. Each item with random attributes and a price that reflects its value.


I can make the script; what I need help on is creating the database.




Answer



You can think about items as a pair of names with description and attributes (including the price)
You can do a table 'items': ID, descid, attrid


You can make the two others like this:
'item_descriptions': ID, name, desc
'item_attributes':


ID, strength, intellect, agility, price


This would split up the description part and the, let's say, value part of the item.


Edit:
I would, as said in a comment, now recommend the following structure:



'items': ID, descid, strength, intellect, agility, price
'item_descriptions': ID, name, desc


The item is in a table with the attributes, because every attribute set should be unique.


The description is in another table, because you wanted to have the same description for different attributes.


And one thing in addition:
I strongly recommend to use memcached! With it you don't have to query the database all the time. Memory is much faster.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...