For character abilities that have a certain trigger condition, eg. “OnAttack”, “OnJump”, “OnDamaged” etc…
Currently each of these triggers is a signal. When a signal fires, the character loops through all of its abilities and activates each one with that specific condition, so it just runs an if statement for every ability, regardless of whether it has that condition or not:
if ability.trigger_condition == Triggers.OnAttack:
ability.activate()
My issue is that this could get a little unscalable with many characters on-screen each having many abilities of their own. A character could have 1 OnDamaged ability and 19 OnAttack abilities, but when an “OnDamaged” signal is received, it will still loop through all 19 OnAttack abilities.
Any advice on this is appreciated, thank you all.
When you add a new ability you could register it in a OnAttack or whatever list for that character.
Then you can just loop that list and activate them all.
I patched together some version of this using nested dictionaries:
with each value being another key:value pair of
{ "ability_id": }
so I can keep a reference to the Ability node and use dictionary functions like .has() to check if a character has a specific ability:Then when a trigger fires, it calls this (I omitted the return code):
This seems to work, but it still gives me that tickling sensation that it could be a little cleaner.