BaseSpell Class
Spells inherit from the BaseSpell class, which contains some functionality that is shared between all spells. This class contains the dictionaries that store spell data, the cooldown timer, and the flag that determines whether a spell uses mouseover targeting.
initialize_base_spell takes the ID of a spell as an argument, and reads the corresponding data from the data/db_spells.json file. It then creates the spell_base and spell_current dictionaries, and connects the signal for the global cooldown, if the spell is on the global cooldown, and adds the cooldown timer node.
Note: spell_base contains the unmodified data read from the data/db_spells.json file. It does not change. spell_current contains the spell data, and is modified with changes by things such as talents.
get_spell_target determines which target the spell is used on. The target can either be the mouseover target, or the selected target of the source. If both are null, an individual spell may set the target to the source in its own script. The current intent is to enable or disable mouseover targeting for each spell individually in a future update.
is_illegal_target checks whether the target of the spell is a legal target, by checking whether it is in the correct group.
is_on_cd checks whether the spell is currently on cooldown, by checking the cooldown timer.
insufficient_resource checks whether the source of the spell has sufficient resources to trigger the spell.
is_not_in_range checks whether the target of the spell is within the maximum range of the spell.
is_not_in_line_of_sight checks whether the target is within line of sight of the source. This is currently not functional.
trigger_cd starts the cooldown timer of the spell, if it is not currently on cooldown with a higher remaining duration than the new cooldown would be. For example, a spell that has 25 seconds of cooldown left would not have a global cooldown applied to it, but a spell with no running cooldown timer would have the global cooldown applied to it.
trigger_gcd causes the spell container to emit the gcd signal, which starts the gcd of all spells that use it, with the duration being specificed in the spell_container.
update_resource applies the resource cost (or gain) caused by the spell to the source of the spell.
start_cast sets the is_casting state to true, links the cast timer to the cast_success function of the spell being cast, starts the cast timer, and causes the gcd signal to be emitted.
cast_success is a dummy function for use with instant spells, and is overridden by spells that have a cast time. This function is then called when the cast timer times out. For spells with cast time, the overriding function in the individual spell script applies resource costs, sends the combat event, and calls finish_cast.
finish_cast plays the spell success animation, disconnects the cast timer from the cast_success function, triggers the spell cd, sets the is_casting state to false, and checks for queued spells that are automatically cast next.