The best way to seperate logic is using coupling tables. In the case of elements ( lightning, darkness etc) and weapons You can do it like this:
Code: Select all
table: Weapons
weapon_id PK,
name,
description,
icon
etc
Table: Elements
element_id PK,
name,
attributes,
def,
magic,
atk,
etc
Table: Weapons_Elements
weapon_id,
element_id
It`s important to note that the last table has NO primary keys ( PK ) this is because it`s a collection of ID`s.
This way you can bind more then 1 element to 1 weapon.
It`s like this: weapon can have more then 1 elements, but elements can also be attached to more then 1 weapon. This is called a many-to-many relation. This is a problem, because you don`t want the overhead of creating 3 of the same weapons all just so they have 3 elements, correct?
That`s when you use a coupling table. This only stores the weapon_id and 1 element_id.
So if you have a weapon like this:
id = 1
name = DragonSword
and the following elements:
id = 1
name = fire,
id =2
name = ice,
id = 3
name = wind,
id = 4
name = lightning
If you want to bind fire, wind and lighting to the sword, you create 3 entries in the weapons_elements table. Like this:
weapon_id = 1, elements_id = 1
weapon_id = 1, elements_id = 3
weapon_id = 1, elements_id = 4
So every time you query the sword, you have the sword ID, now all you have to do is query the weapons_elements table where weapon_id = 1.
That way you have all the ID`s of the elements you have bound to the sword.
So now you query all the elements and you have the elements as well.