What's new
  • Visit Rebornbuddy
  • Visit Panda Profiles
  • Visit LLamamMagic
  • Visit Resources
  • Visit Downloads
  • Visit Portal

Determining left cooldown

wownerds

New Member
Joined
Feb 15, 2011
Messages
1,385
Reaction score
30
Hey there,

I'm trying to get the exact cooldown left for a spell that's been cast.

The basic idea is to have a timer increase an int by 1 every second after the spell was cast and subtracting that int from the base cd of the spell.

Here's the code I got:

Code:
public static System.Timers.Timer CSCDTimer;
        public int CurrentCSCD = 0;
        public int RanCS = 0;
        uint basecd = SpellManager.Spells["Colossus Smash"].BaseCooldown;
        public void CSCD()
        {
            CSCDTimer.Interval = 1000;
            CSCDTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        }

        public void CalcCD()
        {
            RanCS = RanCS + 1;
            CurrentCSCD = (int)basecd - RanCS;
            Logging.Write(Color.GreenYellow, "CSCD: "+ CurrentCSCD + " !");
        }

        public void ResetCD()
        {
            Logging.Write(Color.GreenYellow, "Reset CSCD");
            if (CSCDTimer.Enabled == true)
            {
                CSCDTimer.Enabled = false;
            }
            RanCS = 0;
            CSCDTimer.Enabled = true;
        }

        public void OnTimedEvent(object source, ElapsedEventArgs e)
        {
            Logging.Write(Color.GreenYellow, "Calculating CSCD");
            CalcCD();
        }

I'm castin the spell with this code:

Code:
        public Composite CastCS()
        {
            return new Decorator(ret => SpellManager.CanCast("Colossus Smash"),
                                 new Action(delegate
                                 {
                                     SpellManager.Cast("Colossus Smash");
                                     Logging.Write(Color.Red, "!!--> Colossus Smash <--!!");
                                     ResetCD();
                                     return RunStatus.Success;
                                 }
                                     ));

        }

I'm calling CSCD()

Code:
        public void CSCD()
        {
            CSCDTimer.Interval = 1000;
            CSCDTimer.Elapsed += new ElapsedEventHandler(OnTimedEvent);
        }

in the initialization part of the cc.

I added the logging code for checking where it gets stuck. Until now, all I get is:

Code:
Reset CSCD

each time the spell was cast.

Does anyone have an idea why this does not work?

Thanks in advance!
 
personally i would use Stopwatch or WaitTimer for that.

something like:
Code:
private Stopwatch swColossusSmash = new Stopwatch();

private void WriteColossusSmashCD()
{
    int cdleft;
    cdleft = WoWSpell.FromId(86346).BaseCooldown - swColossusSmash.Elapsed.TotalSeconds;
    if (cdleft > 0)
        Logging.Write("Cooldown left:" + cdleft);
    else
        Logging.Write("Cooldown finished");
}


private bool Cast()
{
    if (SpellManager.CanCast("Colossus Smash") && SpellManager.Cast("Colossus Smash"))
    {
        swColossusSmash.Reset();
        swColossusSmash.Start();
        return true;
    }
    return false;
}

Waittimer:
Code:
private WaitTimer wtColossusSmash = new WaitTimer(new TimeSpan().FromSeconds(WoWSpell.FromId(86346).BaseCooldown)); // initialization

wtColossusSmash.Reset(); // you start it with Reset()
wtColossusSmash.TimeLeft.TotalSeconds //getting seconds left

dont know if code is 100% right but that should give you hint of what to use.
 
Last edited:
you do know that SpellManager.CanCast Checks for global cool down and now with spell queuing, it deals with serverside lag with the global cool down. basically what im saying is, why try and manage your own cool downs for spell casting when i can assure you, letting the spellmanager handle it all, will give you better results without the trouble of writing your own manager.
 
guess he wants to use different spells based on what cooldowns are available at the moment.
Something like when i wanted use Slice and Dice left duration (some ability cooldown left in this case) to determine whether i should use Rupture or not.
 
Last edited:
guess he wants to use different spells based on what cooldowns are available at the moment.
Something like when i wanted use Slice and Dice left duration (some ability cooldown left in this case) to determine whether i should use Rupture or not.
then the wait timer code you gave him should work. or at least with modification do what he wants.
 
If you want to get it more accurate you should check faster than every second :)
 
First of all: Thank you :)

What I'm trying to do is getting the exact CD left for Colossus Smash. If the CD is greater than 5 secs, the cc should go on with it's normal rotation, if CD < 5, it should stop using some abilities.

That's why I'm looking for the CD code
 
Code:
using Styx.Helpers;

        WaitTimer ColossusSmashCooldown;


            if (ColossusSmashCooldown == null) {
                ColossusSmashCooldown = new WaitTimer(TimeSpan.FromSeconds(SpellManager.Spells["Colossus Smash"].BaseCooldown));
            }
            new Decorator(
                Delegator => ColossusSmashCooldown.IsFinished && SpellManager.CanCast("Colossus Smash"),
                new Sequence(
                    new TreeSharp.Action(Delegator => SpellManager.Cast("Colossus Smash")),
                    new TreeSharp.Action(Delegator => ColossusSmashCooldown.Reset())
                )
            )
 
Back
Top