This iteration I'm planning on implementing varying difficulty monsters and hopefully items of varying strengths. In my previous post, I suggested using a "trait" system to implement some of the monster characteristics. For example, one wolf might be "fast"-er or "strong"-er than another, trading that off against some additional base attributes. In my head I hoped to sneak in items with enchantments; a sword that could make you tougher or a staff that made you case spells better.
It came to me that both of these use cases are very similar to the skill tree attributes I implemented last iteration. Those skills could increase base stats or allow new skills. As a programmer, when I hear of three different implementations of an idea, I get an itch to make a generic framework or factor out the pattern or something.
The crux of the idea is that all of these ideas can be implemented as a system of tags and values. For example, a skill that increases the characters base hitpoints by 5 could be:
m_player["HPBonus"] = 5;
Then to calculate the number of hitpoints in this simple example one can do something like:
// Player int GetSkillTags(string tagName) { int total = 0; foreach(ISkill s in Skills) { if(s.attributes.Contains(tagName)) total += s.attributes[tagName]; } foreach(IItem i in Equipment) { if(i.attributes.Contains(tagName)) total += s.attributes[tagName]; } return total; } // Monster int GetSkillTags(string tagName) { int total = 0; foreach(Dictionary<string, int> d in Traits) { if(d.Contains(tagName)) total += d[tagName]; } return total; }
Once I implement a given skill or trait checking in one section of the game engine using this API, creating a new skill, item attribute, or monster trait to do the same thing is trivial. Also, since checking if a dictionary contains a key is fast, it should be efficient as well.
Thoughts?