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

Accessing DBM timers

kermzu

New Member
Joined
Aug 17, 2011
Messages
16
Reaction score
0
Anyone know how to access the timers from DBM in a combat routine? I imagine there is some lua that could be used to grab them but I'm not sure
 
Quickly thrown together, could easily be optimized, but that's a lesson for others :)

Code:
        class DBMTimers        {
            public static int NumBars
            {
                get { return Lua.GetReturnVal<int>("return DBM.Bars.numBars", 0); }
            }


            public static IEnumerable<DBMTimerBar> Bars
            {
                get
                {
                    var barIds =
                        Lua.GetReturnVal<string>(
                            "t={} for bar in pairs(DBM.Bars.bars) do table.insert(t, bar.id) end return (table.concat(t,'@!@'))",
                            0);


                    foreach (var barId in barIds.Split(new[]{"@!@"}, StringSplitOptions.RemoveEmptyEntries))
                    {
                        yield return new DBMTimerBar(barId);
                    }
                }
            }


            internal class DBMTimerBar
            {
                public string Id { get; private set; }
                public DBMTimerBar(string barId)
                {
                    Id = barId;
                }




                public bool Dead { get { return Lua.GetReturnVal<bool>(FindBarAndExecute(Id, "return bar.dead"), 0); } }
                public bool Dummy { get { return Lua.GetReturnVal<bool>(FindBarAndExecute(Id, "return bar.dummy"), 0); } }
                public bool Flashing { get { return Lua.GetReturnVal<bool>(FindBarAndExecute(Id, "return bar.flashing"), 0); } }
                public bool Enlarged { get { return Lua.GetReturnVal<bool>(FindBarAndExecute(Id, "return bar.enlarged"), 0); } }
                public bool FadingIn { get { return Lua.GetReturnVal<bool>(FindBarAndExecute(Id, "return bar.fadingIn"), 0); } }
                public float LuaTimeLeft { get { return Lua.GetReturnVal<float>(FindBarAndExecute(Id, "return bar.timer"), 0); } }
                public float LuaTotalTime { get { return Lua.GetReturnVal<float>(FindBarAndExecute(Id, "return bar.totalTime"), 0); } }


                public TimeSpan TotalTime { get { return TimeSpan.FromSeconds(LuaTotalTime); } }
                public TimeSpan TimeLeft { get { return TimeSpan.FromSeconds(LuaTimeLeft); } }


                public void Cancel()
                {
                    Lua.DoString(FindBarAndExecute(Id, "bar:Cancel()"));
                }


                public override string ToString()
                {
                    return string.Format("Id: {0}, TotalTime: {1}, TimeLeft: {2}", Id, TotalTime, TimeLeft);
                }
            }


            static string FindBarAndExecute(string id, string doStuff)
            {
                return string.Format("for bar in pairs(DBM.Bars.bars) do if '{0}' == bar.id then {1} end end",
                    id,
                    doStuff);
            }
        }
 
K I've had some time to play around with it. I'm able to pull a specific timer by looking at the DBM lua file for the boss I want to check something on.. like

in JiKun.lua: local timerDowndraftCD = mod:NewCDTimer(97, 134370)

134370 is the timer ID (looks like almost all of them go by the spell id). The actual resulting barId is TimerXXXXXXYYYY where X is the ID and Y is some incrementing number.

In my combat routine I grab it with DBMTimers.Bars.FirstOrDefault(bar => bar.Id.Contains("Timer134370")).TimeLeft.TotalSeconds

And seeing "skipping incarnation, downdraft in 12s" show up in my log instead of wasting cooldowns was awesome. Thanks again
 
What if you were to cache the results and refresh the timers every 0.5 sec or so? I would think that should be more than accurate enough for anything you would need.
 
You're better off grabbing the timer once, caching the time you took it, and the time left, and keeping track of it yourself in .NET.

Additionally, you can use the "WaitTimer" class provided by HB to handle most of it. Just pass the TimeLeft when creating the WaitTimer. :)

Edit; here's some code to facilitate that. Just add it to the DBMTimerBar class and use the "Timer" property. It'll only call into Lua once.

Code:
                private WaitTimer _timer;                public WaitTimer Timer
                {
                    get { return _timer ?? (_timer = new WaitTimer(TimeLeft)); }
                }
 
Last edited:
Brilliant stuff, so stupid I did not find this earlier.
 
Back
Top