2
\$\begingroup\$

This question already has an answer here:

Hi guys I am currently working on a turn-based RPG that will require me to create numerous abilities with little overlap. I've been looking to other games to see how their ability and combat system is design and has run into issues regarding the data structure.

For the purpose of this question let's look at Pokemon RED & BLUE's ability system. Here are a few things that abilities can do:

  • Target User or Target Enemy or Both (i.e. Self Destruct)
  • Has an Accuracy Value
  • Has 1-2 Element value
  • Has PP Value
  • Is either a Special or Normal attack type (determines which stat is used to calculate the damage value.)
  • Increase / Decrease a primary Stat for the battle (ATK, DEF, SATK, SDEF, SPD, LUK)
  • Increase / Decrease overall Accuracy of the target by X% for Y turns (or the entire combat.)
  • Increase / Decrease overall Evasion of the target by X% for Y turns (or the entire combat.)
  • Deal Damage to Target for X amount (Where X can be based on calculated from the ability's base damage value, or using the damage taken that turn i.e. Counter)
  • Heal the Target for X amount (Where X can be based on calculated from the ability's base power OR based on damage dealt by the ability, i.e. Absorb)
  • Skips X Turn (i.e. Dig)
  • Critical chance * X for this attack.
  • Has X% chance to apply Status Effect Y (Y being: Burn, Confuse, Sleep, Poison, etc)
  • 1 Hit KO Target
  • Cannot be hit for X turn (i.e. Dig)
  • Hits X times (Taking the ability's Accuracy value into account each time.)
  • Forces the attack to happen first
  • Forces the attack to happen last

I believe there may be many more. Now, Pokemon abilities can manifest a combination of any number of the above properties, usually no more than 3-4. For example: - Counter = Skip 1 turn and deals damage to the enemy equal to 2x the damage received that turn as long as it's a Normal or Fighting move. - Dig = Skip 1 turn, cannot be attacked that turn, deal damage next turn. - Absorb = Deals damage, at the same time heal the user for 1/2 the damage dealt. - Self Destruct = Kills self and deal huge damage to the enemy. - Comet Punch = Hits the enemy 2-5 times (each time the hit chance is 85%)

As you can see, this gets quite complex. The examples cited above are just a few of the abilities that the game have and with those capabilities, it's possible to create quite a varied set of abilities that do not overlap.

The problem I am facing is 2 folds:

  1. How would I design the data structure that would allow me to keep adding new abilities like this into the Database after the system has already been written?
  2. How would the combat system actually handle the data once it's pulled out?

I assume that it will have to involve some form of scripting... and unstructured data structure like NoSQL so some abilities can have some things and some do not (like skipping turns.) However, how is this normally done? Do I store each ability as a blob somehow and handle them differently in code? That also means that the code MUST be able to handle ALL possible combinations (which will make the combat system extremely complex and time consuming to build?) Or did Pokemon just hard coded all the abilities (which seems quite impractical?)

Here's what we currently have for our ability data structure: (in JSON)

{
    "name"     : "Ability Name",
    "accuracy" : 0.85,
    "base"     : 50,
    "type"     : 0,              // (0 = normal, 1 = special)
    "target"   : 0,              // (0 = self, 1 = enemy, 2 = both)
    "PP"       : 30,
    "element1" : 1,              // (0 - 16, for each element)
    "element2" : 2,
    "blob"     : { ... }
}

This will allow for something like the above, but the code would still have to handle all the possible combination of the blob. Would my understanding be correct here?

Any insight would be extremely appreciated.

P.S. - If this question need to be reworded somehow to make it clearer, please let me know... it's an extremely complex problem so I did as best I could, but would appreciate feedback. Thanks!

\$\endgroup\$

marked as duplicate by Sean Middleditch, MichaelHouse Nov 22 '13 at 20:47

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • \$\begingroup\$ The linked question deals with "buffs" but the same general practice is applicable. \$\endgroup\$ – Josh Nov 21 '13 at 17:46
  • \$\begingroup\$ @JoshPetrie The linked question deals with a problem which is quite structurally similar, I will give it a look and see if it answers parts of the question or require me to elaborate this question further, thank you! \$\endgroup\$ – Jamornh Nov 21 '13 at 18:18
  • \$\begingroup\$ the question is quite broad, but there are design patterns that will help, most notably component based design (abilities are components of an entity). The combat system has the abilities perform the work, for example a received "raw" damage struct is passed to all abilities that modify damage (AC, buffs, resistances, powerups, etc. etc.) and those will modify the resulting damage one after the other. So what's important is to be able to prioritize abilities and have abilities that can deny doing damage at all (ie invincibility powerup). \$\endgroup\$ – LearnCocos2D Nov 21 '13 at 18:52