I'm writing a game for social network and we have a lot of formulas for weapons stats, items stats etc th开发者_运维知识库at depend on player's characteristics. Formulas look like
player.money += 10 * player.level
It looks like a good idea to just store functions like these in db and let game-designer enter them through admin site.
But i'm not sure about this. What problems can occur with this approach?
Thank you.
The issue you need to contend with is not whether you should use a database (you should) but the proper design of such. Consider the object hierarchy you have in the game and how that would be reflected in a database.
Making a database column for each property is a bad idea in that it is too rigid. You want to look at a "property bag" approach where you have look-up tables for most of it that can be indexed for performance.
This of a model like this:
itemId, propertyId, propertyValue
For higher performance, combine this with something like Memcached.
This would be an OK approach. As Jon pointed out, it's not really "code", more like item/equipment attributes.
Pros
- Easy to modify
Cons
- Requires a lookup for each item or piece of equipment
The fact that you will be doing a lookup for each item could be a performance bottleneck. If you decide to use a DB in the end, I would suggest pulling data from it once and then caching it for, say, the rest of the session. The item attributes aren't likely to change frequently, and this will limit the queries to the database.
精彩评论