I was wondering if anyone would mind explaining a little about how a composition based spell system should work.
I've been working on this for a few days now, I think I understand the composite pattern enough for what I want to do as my entity's follow the same pattern. (Everything has a single purpose)
But I am really having trouble connecting everything together.
For example my Entity
has a Entity Caster Component
and Entity SpellList Component
and I believe following a pattern like this the Entity Caster Component
shoudn't need to know anything about the spell other than it's just been asked to cast the one given, correct?
Which leads me to the problem of actually casting the spell as each spell is currently an empty object with 4 SpellComponents on it one of each type (SpellTargeting
, SpellEffect
, SpellLocomotion
, SpellModifier
) which all extend from SpellComp
so I should in theory be able to treat them all the same.
But in practice I can't as targeting, modifier and effect mostly only need to run once where as locomotion needs to be called every frame.
I haven't figured out how to still call one inherited base method but have 1 component fire a coroutine and the others work as normal while still treating them the same.
Currently when I "cast" a spell I spawn an empty gameobject with the comps and enable the first component which does it's job and fires an event to start the next component until the last.
TargetComp
> EffectComp
(VFX) > LocomotionComp
> ModifierComp
(Heal/Hurt etc)
which has the obvious effect of leaving a empty object in my scene that responds to target input even after the spell is over.
I feel like at some point I've started mixing two separate systems together and made an unholy mess I no longer understand.
Every other part of the project has gone and is going fine but just thinking about taking another look at the spell system makes me lose a few brain cells.
I linked an empty project I created purely for testing this with my "oh god its so awful but it sort of works" implementation attempt.
I would add the code for each file but there is over 10 and most of them are just extending from a base abstract class so I can treat them the same and this post is already very long.
https://www.dropbox.com/s/ft6awn4v36a0pu0/Modular%20Spell%20Test.zip?dl=0
Any help appreciated, thanks!
Note: Also I use "Entity" as a base class for anything that moves and would have health, I am not trying to implement ECS, I think.. it was just the easiest way to categorize it in my head.
Caster
aCast()
method to cast theSpell
, make it so that everySpell
has aCast()
method which takes in aCaster
, e.g.myFireSpell.Cast(myGenericSpellCaster);
. You retain the "spell agnostic" caster class, but every spell (class) can work with this caster the way they need to. \$\endgroup\$