View Single Post
05-05-20, 05:13 AM   #3
Xrystal
nUI Maintainer
 
Xrystal's Avatar
Premium Member
AddOn Author - Click to view addons
Join Date: Feb 2006
Posts: 5,892
This appears to be how nUI does it and I haven't seen it be too far out with its calculations

Lua Code:
  1. for i=1,40 do
  2.         local aura.name, aura.icon, aura.count, aura.type, aura.max_time, aura.end_time, aura.caster, aura.is_stealable = UnitAura( unit_id, i, filter );
  3.         if aura.max_time and aura.max_time > 0 then
  4.         aura.start_time = aura.end_time - aura.max_time;
  5.     elseif aura.end_time and aura.end_time > 0 then
  6.         aura.start_time = GetTime();
  7.         aura.max_time   = aura.end_time - aura.start_time;
  8.     else
  9.         aura.max_time   = nil;
  10.         aura.start_time = nil;
  11.         aura.end_time   = nil;
  12.     end
  13. end

nUI calls the function that contains this code using a function ( updateAuraInfo( unit_id, unit_info ) ) for each unit. Which is called whenever the custom OnAuraUpdate function is run every update cycle and there is something to process in its UpdateQueue.

Our OnAuraEvent function handles the following events:
frame:RegisterEvent( "ADDON_LOADED" );
frame:RegisterEvent( "PLAYER_ENTERING_WORLD" );
frame:RegisterEvent( "UNIT_AURA" );

In ADDON_LOADED we set up the aura buttons and refresh the callbacks ( which then updates the auras )
In PLAYER_ENTERING_WORLD we refresh the callbacks again
In UNIT_AURA we add the aura and unit it has affected to an update queue to be acted on the next time the game does an update cycle.

I haven't played with C_Timer myself so not sure what restrictions if any there are in how it can be used but in *theory* you could do something like the following but I suspect it would just set up multiple timers, so you may have to have some sort of list of timers and whether they can be re-used:

Lua Code:
  1. for i=1,40 do
  2.         local name, icon, count, type, maxTime, endTime, caster, isStealable = UnitAura( unit_id, i, filter );
  3.         if name then
  4.             local startTime = GetTime();
  5.             local timeLeft = endTime - startTime
  6.             local timeBufferImminent = 10
  7.             local timeBufferSoon = 60
  8.             C_Timer.After(timeLeft - timeBufferImminent,function() AuraExpireImminent(unit_id,name,i) end)
  9.             C_Timer.After(timeLeft - timeBufferSoon,function() AuraExpireSoon(unit_id, name,i) end)
  10.         end
  11. end

I've added name in there in case there is a glitch and aura i is no longer aura name. How that would occur I don't know. How much of the aura system is accessible I don't know myself either. I recall limits on only seeing your own auras on other players or npcs. But not sure if that was Classic or Retail.
__________________

Last edited by Xrystal : 05-05-20 at 05:44 AM.
  Reply With Quote