Action items with cooldown

I have a question regarding cooldowns. I have successfully implemented a cooldown option for my action items so far. Everything is working fine, except for dragging items during cooldown. I want to prevent dragging items from the action bar or into the action bar, which have currently a cooldown. What is the best way to get that managed?

cooldown_dragging

You could add a isCoolingDown boolean flag to your action item and set it to true at the start of the cool down timer and back to false once the cool down ends.
You could then use this flag in the drag code for the items and not let them be dragged while the flag is true on it.

1 Like

Yes, there is a cooldown flag in the ActionSlotUI script which causes ActionStore to ‘BlockUsing’. After cooldown is finished ‘BlockUsing’ is set to false again. I could use this flag to block the dragging as well, but I think that would mean, I have to change the DragItem script? I hoped, there might be a way without changing that script - I have to think about it.

Ok, I had to change the script DragItem. It has a protected bool draggingAllowed now. That is checked at beginning of OnBeginDrag, OnDrag and OnEndDrag. If false, the methods are returned immediately.
ActionSlotUI sets this variable through the InventoryDragItem script.
Also I had to expand the IDragDestination interface with a method ‘AllowedToDrop’, to prevent dragging other items to an item, that has currently a cooldown.
Everything is working fine now. :smile:

First of all, good job in implementing cooldowns!

Here was my solution to this issue (and to explain it, I have to explain how I managed the cooldowns).
I didn’t worry about if the player dragged another of the same item to the ActionBar, because like in World of Warcraft, it wouldn’t do them any good if they did it anyways.

First, I put a CooldownManager on any entity that can use Actions. This Cooldown Manager maintains a list of strings and floats representing a “token” for the timer, and the duration of the timer. I added a public virtual string GetToken() to ActionItem that children override and provide a token for the cooldown timer. A Heal spell, for example, would simply return “HealingSpell” (Actually, since my potion and heal spell use the same SO, I return isConsumable?“HealingPotion”:“HealingSpell”;

I also added two functions to ActionItem, CanUse(user) and CooldownRemaining(user)
CooldownRemaining checks the CooldownManager against the GetToken() value.
CanUse lets you check for conditions (a fireball shoudln’t work if you have no target)… and also ensures CooldownRemaining isn’t zero.
Use starts the CooldownTimer in the CooldownManager for that GetToken()

So even if you add a second copy of that spell or potion to the Action Bar, all it means is that both of those items will be on cooldown at the same time. When added, the CooldownUI checks for any current cooldowns on that token and sets it’s own timer accordingly. Whenever a cooldown is started in the CooldownManager, an event fires and all the CooldownUI get their current cooldowns (if any) from the Cooldownmanager, so everything stays in sync.

Hey Brian, thats seems to be a really good solution and also shows a lack in my solution. Because I indeed have the problem, that when I cast e.g. a power spell with 60sec cooldown, and then put another power scroll into another action slot, there is no cooldown on it and I can cast a second power spell, even the first one hasn’t cooled down. Hm, that’s not what I intend for my game.
I think I will have a deeper look on your solution and implement minimum a synchronisation of cooldowns between same action items.
Thank you for the tips :slight_smile:

Privacy & Terms