game implementation advice

Started by
1 comment, last by pein87 10 years ago

Hey everyone I'm trying to develop a rpg game in php. I know horrible idea, but that aside I would like to ask for advice on a problem I'm facing. I want to implement a class system. Each class would have skills that would modify an attribute based on a percent. I want to be able to modify weapons(damage), character attributes, magic(mana cost, increase or decrease; damage, increase or decrease). My problem is tying the skills to each thing I want to have it modify. I'm using a database to create attributes so they can be added and deleted without editing files. The tables are like so:

attributes table


create table attributes
(
id int not null auto_incremet,
title varchar(30) not null unique, # attribute name
points int not null, # default point
increase int not null, # amount to increase per level
primary key(id)
);

class table


create table classes
(
id int not null auto_increment,
title varchar(30) not null unique, # class name
description text not null, # class description
icon varchar(128) not null, # url or path to icon
logo varchar(128) not null, # url or path to logo
active int not null, # usable 1 for yes, 0 for no
primary key(id)
);

skill table


create table skills
(
id int not null auto_increment,
title varchar(30) not null, # skill name
description text not null, # what skill does
amount int not null, # amount in percent to modify
cost int not null, # number of skill points needed to unlock
class int not null, # class skill belongs to
modifies int not null, # attribute to modify
modType int not null, # type of modification it does 1 for increase, 0 for decrease
icon varchar(128) not null, # url or path to icon
logo varchar(128) not null, # url or path to logo
active int not null, # is skill usable, 1 for yes 0 for no
primary key(id),
foreign key(class) references classes(id),
foreign key(modifies) references attributes(id)
);

My original plan was to add attributes to weapons and magic so I can attach a skill to it and add a field that says where the attributes goes. The attributes for weapon would be damage, the attributes for magic would be cost(in mana, this is a problem for me tying this to mana) damage, speed, element( reduce or increase damage based on the element attribute). My goal is to create an interface in html, css, and jquery that allows the admin to build a weapon and magic.

My question: whats the best way to tie the concepts together so the skills can modify an attribute of a weapon and spell. Also how do I represent that a a user has unlocked a skill. Do I create a table that has the user id, skill id, and a field that shows it's been unlocked?

the attributes for the character would be something like this:

  • Attack
  • Speed
  • Mana
  • Perception
  • Agility
  • Intelligence
  • Stamina
  • Defense

Weapon:

  • damage

Spell

  • element
  • power
  • speed
  • cost

These would be stored in the database.

Advertisement

My question: whats the best way to tie the concepts together so the skills can modify an attribute of a weapon and spell. Also how do I represent that a a user has unlocked a skill. Do I create a table that has the user id, skill id, and a field that shows it's been unlocked?

Use relationships and pivot tables. It's easier if you see tables as classes, and columns as attributes in object oriented programming. You can make a table which defines a class of objects and its basic attributes, and these attributes can be a reference to another class of objects (another table). For example, you can define a weapon table, and it has:


weapon:

id, name, weapon_type, weight, attack_range, damage, price, other_attributes

And an element table:


element:

id, name, other, attributes, goes, here

To assign an element to a weapon, you can make a pivot table which stores the relation between a weapon and its elements. We use a pivot table because a weapon can have more than one elements (ex: fire, wind). Just name this table weapon_elements.


weapon_elements:

id, weapon_id, element_id

Here, weapon_id is an integer which refers to a weapon's id (weapon.id), and element_id refers to an id of an element from the element table. You can insert some rows which define the relations of a weapon to several elements, like:


id | weapon_id | element_id
1  | 1         | 1
2  | 1         | 3
3  | 2         | 4
Say weapon 1 is a sword with fire and wind element, and weapon 2 is an axe with earth element. You can get a list of weapon 1 elements by making a query to this table with only the weapon's id, or you can try to find out if weapon 2 has a fire element or not. It can be applied on the case where you want to see if a skill is unlocked already on a character, or in other word, if a character already has that particular skill. If it returns no result, then the character simply hasn't got that skill yet. It's much better than making the weapon table like:

id, name, type, weight, attack_range, damage, price, element_one, element_two, element_three, element...

If it's just a one-to-one relationship, where an attribute refers to only an object of another class, you don't need a pivot table. For example, a weapon only has one type. A weapon can't be a sword and a bow at the same time, can it? That's why type in in the weapon table refers to a weapon_type table which defines the types of weapons available in the game.


weapon_type:

id, name, other, attributes, that, defines, a_type, of_weapons

Be creative with the rest.

P.S. I hate formatting.

Thanks. What I did was create a base class for modifiers and sub-classes for each modifier type. the stats now belong to a specific type so the modifiers can modify the stats in their own class. I added conditions to the spells and tie ins so the character mana stat is used to pay the mana cost of spells. I added a universal modifier for items so it can mod any stat from any stat type. I will use the pivot table idea though. Thank you for the advice.

This topic is closed to new replies.

Advertisement