Postby Luhz » Tue Sep 01, 2009 8:14 pm
My suggestion:
Split Spell into SpellXEffect and Effect.
The Spell Database would have ID, ClientEffect, Icon, Name, EffectList, MergeStyle.
The Effect database would be similar to the existing Spell database, but it would remove ID, ClientEffect, Icon, Name, SubSpellID, and Type.
Basically, this change leads to a whole bunch of other necessary changes, and has a number of effects.
1. Effect no longer contains SubSpellID - Spells themselves contain an EffectList of 1..n Effects, meaning any spell is made up from a list of spell effects. Subspells are no longer needed because having a subspell is equivalent to having a Spell with two effects. The bonus here is that you can cleanly create spells with more than two effects.
My primary idea here was to remove redundancy in things like SingleStatBuff, DualStatBuff, AllStatBuff - why have three spell handlers for stat buffs? With and EffectList, cut the code down to SingleStatBuff, and use multiple effects to achieve the same effect.
2. MergeStyle is a new field (or fields if design requires) which dictates how multiple Effects are incorporated together. This would handle things like whether the mana cost of the effects is summed, whether the range of the spell is limited to the range of the shortest-range effect, etc.
The simplest two examples would be "Free Mix", where each effect retains whatever values it has, and casting the spell is effectively like casting all of the effects at once (eg. different effects could have different maximum ranges, mana cost for each effect could be distinct, etc), and "Strict Mix" where the effects are mixed to ensure that the spell still acts like a single spell does in DAoC.
Optionally, the Spell database could retain a few duplicate fields which could act as "master" values. This way you could have a spell with 4 effects, but have a "master" ClientEffect so that only one effect is triggered for the whole spell. This could also be left out of the database and could be handled through a form of MergeStyle.
3. Most significant, removing Type requires a redesign of how spells are written in the code and in the database. The idea here is that the removal of Type specification requires two things: SpellHandlers be merged into one; Effect database be expanded with sufficient values to identify every aspect of an effect. The point is that the database becomes generic enough to create any spell through selection of the correct values, rather than through selection of spell handler.
The reason this ultimately "simplifies" things is that the current system makes it difficult to merge and mix different aspects of spells. For example, there is a BoltSpellHandler which inherits from SpellHandler. If you then want to make a bolt spell that does lifedrain return you need to create another spellhandler to mix aspects of the lifedrain spellhandler and the bolt spellhandler. If the appropriate fields were instead stored in the database, you would only need to create an effect that does damage, returns life, and is flagged as "Bolt".
How many fields would the new table need? I'm guessing about the number that are in the existing table, plus at least one new field for each spell handler that exists. That's about 440. Just for reference, MySQL has a table column limit of 4096, and a row size limit of 65535bytes, which shouldn't be an issue with this design unless someone throws in lots of text/unicode columns.
This would probably be reduced by removing a good deal of redundancy, but by how much I'm not sure. However, the database would be much more powerful as a result, and performance shouldn't be an issue here so long as effects are pre-loaded when the server loads.
I think this kind of system is what DOL was originally designed for when the Spell database and SpellHandler were written, but the desire to keep the code clean overrode this and we ended up with a new spellhandler every time something needed tweaking, as opposed to keeping flexibility in the database and everything in one big mess in SpellHandler.cs. Moreover, I think that DOL would benefit from the flexibility in having a general "Effects" system, rather than a mishmash of spells, abilities, realm abilities, etc. Every one of those could simply make use of the same Effects backend.
I hope this book actually gets my idea across.