Monday 15 June 2015

iphone - Objective-C - RPG Skills design pattern -


I am trying to create a new RPG for the iPhone, but when I started thinking in a way that my skill system Actually to build, each class character will have a set set of skills in the form of classic RPG. However, I do not really know how to code them.

Some skills will bring harm, some will correct, apply changes in some situations etc. Therefore, I had the idea of ​​building a basic skill class, to "override" ("activate") a task, and then for each type of skill, create subclasses of that class like this:

  @implementation BasicSkill - (id) initFromName: (NSString *) _name {int value = ...; Int chance chance = ...; NSString * statusToChange = ...; } - activate {zero} {// nothing}. @ @ @ Implementation damage: Basic scale - activate (zero) {int lossToDeal = value; // etc} @end @implementation HealsSkill: BasicSkill - (zero) active {int lossToHeal = value; // etc} @end   

Each variable required for each skill will be stored in a database (I already have work to do for it), but I'm scared It is also possible that many subclasses for every type of skill, as I do not know how many types will be ...

The second thought I had to make was to create only one class, but every This will be your work of skill, stored in a SEL, and Riy () call. (Sorry, I really do not know how to explain it)

  @implementation BasicSkill - (id) initFromName: (NSString *) _ name {SEL action = NSSelectorFromString (@ "Fireball"); Int value = ...; Int chance chance = ...; NSString * statusToChange = ...; } - Activate (zero) {{self executor: action]; } - (zero) fireball {int lossToDeal = value; // etc ...} @end   

I do not know these two samples are both good practice, or if there is another way to do this, but if you know another solution , I would be very happy to read it!

PS Each player stats (HP, Ait, DEF ...) are stored in a dictionary, so I want to string it, but there is no problem in manipulating them. There is no specialist in RPG games (except for some of them sports).

However, I think that you think about it a bit more. For the skills of medical and damage, you must also pay attention to whether the effect of the skill is loss-to-medicine or a loss-to-deal. If the loss is affected at the hit point, then you can say that Skill X +100 HP, Scale Y-100 HP.

And you can work in this way for all types of features (like speed, DX, magic point).

And the effect of skills can be dealt with on both skill processor and skill goal, which can be in the same class but different examples (programming class, not character classes).

To answer your question, you can do it in a classical way, you can do all the skills in the subclass from the basic skills category. You can divide the skills into several levels that you want if they do the same things (like Heel Level 1, there are sub-orbits of Heel Level 2 Heel Class.)

Or if your Having so many skills, you can spread the skills in a table of abilities. For example, I will create a table like this:

  Skill_ID, Skill_Name, HP_Target, MP_Target, Speed_Target, HP_Self, MP_Self, Speed_Self 1, Punch, -50, 0, -10, 0, 0 , 0 2, kick, -100, 0, -10, 0, 0, -103, magic, -120, 0, 0, 0, -25, 4, heel, +500, 0, 0, 0, After that, you can read the values ​​of parameters that are influenced by skill from this table and they are applied to the goal and themselves, in this way, you have There may be only a few skill classes. If you have other modifiers or side-effects from skills (like charging time), then you can keep them on the table as well.  

Again, I am not an expert in this area, but I hope that it helps. / P>

No comments:

Post a Comment