Best practice for organizing/storing character/monster data in an RPG?

Posted by eclecto on Game Development See other posts from Game Development or by eclecto
Published on 2012-12-14T17:06:28Z Indexed on 2012/12/14 17:21 UTC
Read the original article Hit count: 190

Synopsis: Attempting to build a cross-platform RPG app in Adobe Flash Builder and am trying to figure out the best class hierarchy and the best way to store the static data used to build each of the individual "hero" and "monster" types. My programming experience, particularly in AS3, is embarrassingly small.

My ultra-alpha method is to include a "_class" object in the constructor for each instance. The _class, in turn, is a static Object pulled from a class created specifically for that purpose, so things look something like this:

// Character.as
package
{
  public class Character extends Sprite
  {
    public var _strength:int;
    // etc.
    public function Character(_class:Object)
    {
      _strength = _class._strength;
      // etc.
    }
  }
}

// MonsterClasses.as
package
{
  public final class MonsterClasses extends Object
  {
    public static const Monster1:Object={
      _strength:50,
      // etc.
    }
    // etc.
  }
}

// Some other class in which characters/monsters are created.
// Create a new instance of Character
var myMonster = new Character(MonsterClasses.Monster1);

Another option I've toyed with is the idea of making each character class/monster type its own subclass of Character, but I'm not sure if it would be efficient or even make sense considering that these classes would only be used to store variables and would add no new methods. On the other hand, it would make creating instances as simple as var myMonster = new Monster1; and potentially cut down on the overhead of having to read a class containing the data for, at a conservative preliminary estimate, over 150 monsters just to fish out the one monster I want (assuming, and I really have no idea, that such a thing might cause any kind of slowdown in execution).

But long story short, I want a system that's both efficient at compile time and easy to work with during coding. Should I stick with what I've got or try a different method?

As a subquestion, I'm also assuming here that the best way to store data that will be bundled with the final game and not read externally is simply to declare everything in AS3. Seems to me that if I used, say, XML or JSON I'd have to use the associated AS3 classes and methods to pull in the data, parse it, and convert it to AS3 object(s) anyway, so it would be inefficient. Right?

© Game Development or respective owner

Related posts about actionscript-3

Related posts about rpg