#Dynamic offset/width in a TSU, region size is being reset after region:SetWidth()

21 messages · Page 1 of 1 (latest)

fickle zinc
#

Problem statement: attempting to create a feral energy tick that doesn't "reset" when leaving/exiting forms.

Current (working) code:

function(a, e, t)
    local currEnergy = UnitPower("player", 3)
    local inc = currEnergy - (aura_env.lastEnergy or currEnergy)
    if (e == "UNIT_POWER_FREQUENT"
        and currEnergy > (aura_env.lastEnergy or 0)
        and inc ~= 5
        and inc ~= 8
        and inc ~= 25
        and inc ~= 35
        and inc ~= 60
    and inc ~= 100)
    or (e == "UNIT_POWER_FREQUENT"
        and currEnergy > (aura_env.lastEnergy or 0)
        and currEnergy == UnitPowerMax("player", 3))
    or (e == "OVERLAYTICK" and t and currEnergy == UnitPowerMax("player", 3))
    then
        if not a[""]  then
            a[""] = {
                show = true,
                changed = true,
                duration = 2,
                expirationTime = GetTime() + 2,
                progressType = "timed"
            }
        else
            local s = a[""]
            s.changed = true
            s.duration = 2
            s.expirationTime = GetTime() + 2
            s.show = true
            C_Timer.After(2, function() WeakAuras.ScanEvents("OVERLAYTICK", true) end)
        end
    end
    aura_env.lastEnergy = currEnergy
    return true
end

Video: https://www.youtube.com/watch?v=sILBIiDSWWQ
Dynamic group (for reference): https://i.imgur.com/Y0mzbVe.png

My issue with this is that leaving/exiting cat form re-triggers "UNIT_POWER_FREQUENT," resetting the auras duration/expirationTime. My goal is to make an aura that will persist where the tick ("Energy Tick 2" aura in screenshot) should be so it can "resume" dynamically. The problem with this is that you can't set a start point for "timed" states, only the duration.

My hack to get around this is to dynamically calculate to attempt to calculate the remaining duration and corresponding frame width/offset relative to the energy bar's ("Energy bar" aura) frame.
Currently, after calls to aura_env.region:SetWidth(x) on the tick's frame, the frame width is resetting to whatever static width is set in the aura's settings.

Hacky code:

function(a, e, t)
    if aura_env.intended_width then
        aura_env.region:SetWidth(aura_env.intended_width)
        print("Setting width to" .. aura_env.intended_width)  
    end
    
    local currEnergy = UnitPower("player", 3)
    local dur = 2
    if (e == "UNIT_POWER_FREQUENT" and t and currEnergy > (aura_env.lastEnergy or 0))
    or (e == "ENERGYTICK" and t == aura_env.id and currEnergy == UnitPowerMax("player", 3))
    then        
        if (e == "UNIT_POWER_FREQUENT") then
            local curTime = GetTime()
            if (aura_env.lastFreqEventTime 
                and curTime - aura_env.lastFreqEventTime >= 2.000
            and curTime - aura_env.lastFreqEventTime <= 2.026) then
                aura_env.lastIntervalEnergyTickTime = curTime
                aura_env.intended_width = 100
                
                local s = a[""]
                s.changed = true
                s.duration = dur
                s.expirationTime = GetTime() + dur
                s.show = true
                local id = aura_env.id
                C_Timer.After(2, function() WeakAuras.ScanEvents("ENERGYTICK", id) end)
            end
            aura_env.lastFreqEventTime = GetTime()
        end
        
        
        if not a[""] then
            a[""] = {
                show = true,
                changed = true,
                duration = dur,
                expirationTime = GetTime() + dur,
                progressType = "timed"
            }
        end
    end
    aura_env.lastEnergy = currEnergy
    return true
end

Video: https://www.youtube.com/watch?v=JnO-i6QgUGU

What approach should I be taking here? I figure region:SetWidth was not built for this purpose, so what other approaches do I have for this?

#

Dynamic offset/width in a TSU, region size is being reset after region:SetWidth()

fickle zinc
#

anyone have any ideas

formal finch
#

How does the energy tick work?

#

I was under the impression that it starts ticking upon PLAYER_ENTERING_WORLD and then ticks once every 2s no matter what happens

#

Even when you're full energy etc.

#

Is that correct?

fickle zinc
#

pretty new to WoW so don't know the intracacies of its client/server relationship

#

I do know that energy ticks are 20.2/2.2 sec

#

oh

#

is your line of thinking that we could just be purely predictive of when ticks would happen, instead of reacting to the event?

formal finch
#

Yes

#

Take GetTime() once when entering world

#

Save it to aura_env, and then compare whenever you lost track

#

But that's under the assumption that it works in that way.

fickle zinc
#

the script saves GetTime() whenever it detects a time interval of [2.000, 2.026] between events and saves that

#

my issue now is getting the time interval to match the "width"

#

i.e. we shift into cat form in the middle of a tick

#

if we simply set the state's s.expirationTime value, the energy ticker display would move over the full width of the energy bar in w/e % of the energy tick interval is left