Ability System

A system I've wanted to make for a while.
It works by using my component system to create and manipulate components.

Why make an Ability System?

I’ve always liked making abilities for RPGs, but there is always code you don’t want to copy for most abilities like cooldown, damage, stat scaling and delayed effects. When you try to add these to a game you will encounter many other problems such as canceling a charging ability, and if you use a component system you might want to pre-define what components an ability should create or manipulate.
When I made the abilities in Spite, even though all abilities were very different, I wanted a system to handle the interface, cooldown and stat scaling for abilities. I started working on a big ability system, but quickly realized it would take too long time to make, so I settled for a simpler system to handle cooldown and casting through callback functions.
When I got the chance to finaly make it, I knew wanted to make a big flexible system to handle all types of abilities for all types of games, but I still wanted it to be low level enough to be used specifically by the ones making the components. The reason is that it’s the way I would want to create abilities and I felt that way you get a good sense of over the flow of the code.

AbilityManager AbilityManager
AbilityManager update Manager update

Casting Events

The ability system is built around the concept of events, and all abilities consists an array of objects, each with an array of component actions (create, remove or custom action). During the creation of the system I changed what events I was going to use a couple of times, due to the last one not working as I expected. At first the casting events were the same as the input, press, hold and release that is, but I settled on charge start, charge stop and cast. Every object needs to specify what casting event they should act on.
All three casting events are very different from each other, and therefore are handled in different ways by the system. Charge start has all its components and objects added to special arrays on creation, to be removed when another event is called. Charge stop is basically canceling the charge without casting. Cast is the main event that actually does the ability, but it's also called every upkeep interval. Through these three events and the more complex on hit event, you should be able to make almost every ability or spell in any game.

Charge cancel Charge canceling

On Hit Event

The on hit event is very special, I could have made it as simple as the others, but I wanted to make it more flexible in a few ways. Instead of having every object act on anything you collide with, you specify which collision flags the object should act on. This makes it much more flexible and opens up the ability to make much cooler abilities.
What collision you should let objects act on is not the only thing you use collision flags for. Collision flags are used to specify which flags your collision have, and what collisions will block (destroy) your ability. I also made it easier to change stats on hit, since I felt thats what you're most likely to use the on hit event for.
This was probably the most difficult part to figure out how to make it work, it ended up making me change a lot of code to be general in how it handles events.

Split ability Split ability

Features, Bugs and Time

When I decided to make this ability system, I set out to make a lot of features in only three weeks, half-time. I soon realized I needed to cut down the amount of things I wanted done by the end.
I ended up cutting mostly general components to be used in creating abilites, all but one of them to be exact. The one I kept was a velocity component, as I was sure that most abilities could be created using that and the ones already created for the engine.
In the end, I still didn't have enough time to polish some of the features or even test it in one instance, which is the upkeep feature. I never got the time to make an upkeep ability to test the feature, so I dont even know if it works, only that it doesn't crash and should work in theory.
I still don't think I could've planned it much better since I encountered several unexpected bugs/crashes that took multiple days to fix.

Component creation Component creation
Delayed creation Delayed creation

Some Abilities

I made a total of six unique abilities to test the ability system. They are: Fireball, Blink, Dash, Hook, Wall and Split.
Fireball was the first ability I wanted to make, it's a simple charge up then release spell.
Blink I used Dishonored as reference and is a teleport spell you aim when you charge.
Dash looks very simple, the player dashes forward a small distance, but the tricky part is that it isn't creating a new object.
Hook I used Pike from League of Legends as reference, it goes further the longer you charge it.
Wall is the simplest one, it creates a wall offset from the ground facing the caster.
Split is the most interesting one, it looks like fireball but when it hits something it splits into two, and will continue to split whenever one hits something.

Split Split
Fireball Fireball
Blink Blink