• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece! 🔗 Click here to enter!

How do units track abilities being used. Behind the scene question

Status
Not open for further replies.
I'm trying to achieve my own ability system in a project outside of warcraft and I would love some input on how warcraft handles ability casts, if anyone knows.

  • Does an ability track its own cooldown and duration? Or is it an ability component on the unit that tracks this for each ability on the unit?
  • How do "start casting" and "start channeling" and " start an effect" differ in terms of coding?
  • How do an ability (or the unit using the ability) know if it is channeled?

If these questions can be answered with actual code examples it would be great (I can probably convert it to C#), but any insight is appreciated.

Please move this question to the appropriate forum if this is not the place for this type of question.
 
Seems like a fascinating question, actually.

Does an ability track its own cooldown and duration? Or is it an ability component on the unit that tracks this for each ability on the unit?
I think it would have to be an ability component, wouldn't it? So if I have two Priest units, their Heal cooldown can be different. One of them can have 1 second remaining and the other can have 2 seconds remaining. Seems to me that this would mean Priest A must store his cooldown for Heal separately from Preist B, so then the map-wide concept of Heal is not the location where the cooldown is stored.

Items have a setting called Cooldown Group that takes in an ability though. And two abilities that are both copied from Heal seem to often share a cooldown or have other buggy behaviors with regards to this. Maybe the unit object contains a dictionary type object where the Cooldown Group is the key and the remaining cooldown is the value?
 

Uncle

Warcraft Moderator
Level 64
Joined
Aug 10, 2018
Messages
6,583
Here's what makes the most sense to me:

1) A unit can have multiples of the same ability which can all be on their own cooldowns as long as each ability has a different ID. So the design would need to allow for this.

2) When you issue the order to cast an ability and you meet the requirements (in range, valid target, etc) it goes like this:
If the ability has Casting Time then the ability is delayed by this amount using a Timer. After Casting Time has finished, the "Begins casting" stage occurs. The unit then begins playing the spell animation associated with the ability ("spell" by default) and a Timer using the unit's Art - Animation - Cast Point starts. This Timer needs to finish before the ability actually launches it's effect. If the Cast Point Timer finishes successfully then the unit enters the "Starts the effect" stage. You can interrupt any of these Timers to prevent the ability from executing. Lastly, the Art - Animation - Backswing Timer starts, which will attempt to play the rest of the spell animation before the unit exits this casting state and can begin acting freely again (move, attack, etc). The user can interrupt this state whenever they'd like, which has become known as Animation Cancelling.

Channeling abilities are the same when it comes to the Begins/Starts stages, except that they use a Repeating timer for the effects of the ability and during this time the unit remains in a "Channeling" state which prevents it from doing anything else on it's own. The user can manually interrupt and end the channeling state whenever they'd like, killing the Repeating timer.

3) A simple Boolean field on the ability like: IsChanneled = true/false

If the ability is categorized as Instant (Berserk, Defend, Mana Shield, etc) then no animation is played, the "Begins casting" stage happens for the sake of triggering Events and the "Starts the effect" stage happens immediately after it. Instant abilities don't interrupt orders so they can be cast while moving/attacking and skip any Timers / delays. This is probably a Boolean field as well -> IsInstant = true/false.
 
Last edited:
@Uncle
I have been doing the boolean way with channel and passive abilities, and a simple 0 casttime duration for instant casts.

What you say about begins/starts make sense, and is also the way I have been doing it so far.
I am wondering about the ability cooldowns still.
Because either the ability itself tracks its cooldown, but it could also be an AbilityModule on the unit which controls each of the abilities cooldowns.
You have a list of abilities, and the AbilityModule runs through them all reducing their cooldowns.

Same goes for casting. Is it the ability that controls the casttimer, or is it the unit, or a module on the unit.
I wanna say it's the unit that controls at least the casting bit. That way you only have CheckCastime in one place, instead of on each ability. But I can't be certain of course.
But extracting castime/duration and begins/starts checks could easily be controlled by an AbilityModule. I can't figure out what seems to be the smartest option.
 
Status
Not open for further replies.
Top