database design to store magic attack and effect

Started by
7 comments, last by DrEvil 10 years, 4 months ago

I want to create a database that can store a magic/skill and it's effect to target like rpg style. For some example :

my hero have some active magic/skill and passive skill,

active skill may damage and slowed attack speed of enemy for couple of seconds. or maybe only stun some enemies for couple of seconds but not damage the enemies

passive skill may increase status of hero like hit point, or/and attack power

how I can store them as a table in database ?

and last sorry for my bad english,

thank you

Advertisement

I don't think you really need to store them in a database, but rather design them in a smart way. This will at least reduce the amount of spells you have. You can obviously store them in a database, but how depends also on what the spells are based on (player level, player selection, item choice)

You don't need to store every single variation of a spell. In the end, it's nothing more than a number that does something (healing or damage) with 0 or more side effects (like a stun) and perhaps a timer, or whatever you want a certain spell to have. This, same as above, also depends on what affects your spells.

I guess it also depends a bit on how big the game is, or rather, how many different kind of spells you're going to have. I would personally think it's more of a hybrid between storing base spells in some way (doesn't need to be a database per se, perhaps some XML file, I don't know) where different factors (player level, stats, etc) are a modifier for the final outcome.

I guess it can also be achieved with scripting the spells (so the designers don't have to dive in the actual code).

In the end it probably also depends a bit on how many spells you have though. Maybe setting up a scripting language or parsing through some database/file isn't worth the effort if you're going to have 5 base spells with level based variations that don't need to be stored.

Others can probably shed some more light on it, but this should at least give you something to think about. :)

as rld says, no need to store them in database. i think you should store them in binary file, or even hard-code it in your library. database means slow on setup, and fast on query. but your query quite simple, read only. database system is suitable for huge number of query or complex query. such as you must read 100 records/second, or store 1000000 records to file, or you need to take some data that match some conditions.

If you really think that database is OK try this : http://www.sqlite.org/

I suggest you to use XML/Json for the storage, there are a lot of read/write libs for those *formats*

use sqllite

"Database" is probably the wrong word. It is usually associated with relational databases, which is why so many people suggested SQL-based engines.

SQL is used in relational databases. This kind of database is great for big data with one-to-many and many-to-many relationships. For example, one customer might have thousands of order invoices and payments and shipping details, and the database all told may have millions of entries. These are great for businesses.

While a relational database is great for many computing solutions, it is generally not an ideal solution for the problem that was described.

You can maintain a few simple data tables (not SQL-based databases) that solve the problem fairly easily. Create a structure or class that defines each one, and dump them all in an array. If spells and effects are different enough you might consider having two arrays, one for each. Then each player can track any spells or effects that are on them by referencing the ID. You will also need some way to store the data, probably in a format like XML or JSON or something you write yourself. The process of loading the data is called serialization, and your favorite search engine can find many thousand examples of serialization code.

A proper relational database is overkill -- I suppose if you were using a database heavily for other things it would make sense to consolidate storage systems, but that's certainly not a dependency you want to take just for this.

If it were me, I'd design my spells and other effects as a component system, and then have a set of factories to build them from a declarative sort of description; or, tie that into a scripting language like Lua to define the languages.

throw table_exception("(? ???)? ? ???");

thanks for your suggestion,

but the problem is our game designer haven't designed all of magic in game, and not only that, because the game will be connected with server cause if some parameter will change it will be the database not the code. Oh and we using sqlite for the database.

From the perspective of a client/server I would consider restricting the details of the spell effects to the server side only, and only propagate data necessary for visualization to the clients. This would allow you to create effects and spells and such that don't need to be communicated to the clients, potentially even while the game is still running. The clients just need to download the visual aspects of the effects such as animations, textures, particle systems, hud icons, and many of those can be shared or mixed and matched between skills. The client need not even have any knowledge of the spell system in general. Maybe the client has only the capability to communicate targeting information to the server and activate spells by an id value, and the server kicks communicates streams of visualization instructions at entity positions to relevant players around those locations in a generic way that has no dependency on the spell system.

Alternately, is your question more about how to structure the definition of a spell effect?

This topic is closed to new replies.

Advertisement