2 local pairs, ipairs = pairs, ipairs;
3 local floor = math.floor;
4 local GetTime = GetTime;
5 local UnitAura = UnitAura;
6 local UnitIsPlayer = UnitIsPlayer;
7 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
8 local CTimerAfter = C_Timer.After;
10 local watchedAuras = {
12 [156910] = "TOPRIGHT",
13 [200025] = "TOPRIGHT",
14 [200654] = "BOTTOMLEFT",
17 ["Psychic Assault"] = true,
18 ["Everburning Flames"] = true,
20 ["Sleep Canister"] = true,
22 ["Necrotic Embrace"] = true,
23 ["Fulminating Pulse"] = true,
24 ["Chilled Blood"] = true,
25 ["Soulblight"] = true,
33 local positions = {"TOPRIGHT", "BOTTOMLEFT"};
34 local auraFilters = {"HELPFUL", "HARMFUL"};
36 local function remaining(text, expires, current)
41 local remain = expires - current;
45 text:SetText(floor(remain+0.5));
50 local function updateIndicators(frame, unit)
51 if not frame:IsShown() or not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
52 updating[frame] = nil;
56 local needUpdate = false;
57 local current = GetTime();
58 for _, pos in pairs(positions) do
59 local ind = frame.inds[pos];
60 if ind.expires ~= nil then
61 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
65 local ind = frame.major[i];
66 if ind.expires ~= nil then
67 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
71 CTimerAfter(0.16, updaters[frame]);
73 updating[frame] = nil;
77 function OmaCheckIndicators(frame, unit)
78 for _, pos in pairs(positions) do
79 frame.inds[pos].expires = nil;
80 frame.inds[pos]:Hide();
81 frame.inds[pos].text:Hide();
84 frame.major[i].expires = nil;
85 frame.major[i]:Hide();
86 frame.major[i].text:Hide();
87 frame.major[i].stack:Hide();
89 local name, icon, count, expires, caster, id;
90 local showInds, showMajors, needUpdate = false, false, false;
92 local current = GetTime();
93 for _, filter in ipairs(auraFilters) do
96 name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
97 if not id then break end
98 local pos = watchedAuras[id] or watchedAuras[name];
99 if pos and UnitIsPlayer(caster) then
100 needUpdate = remaining(frame.inds[pos].text, expires, current);
101 frame.inds[pos].expires = expires;
102 frame.inds[pos]:Show();
103 frame.inds[pos].text:Show();
106 if (majorAuras[id] or majorAuras[name]) and majorPos <= 3 then
107 needUpdate = remaining(frame.major[majorPos].text, expires, current);
108 frame.major[majorPos].expires = expires;
109 frame.major[majorPos]:SetTexture(icon);
110 frame.major[majorPos]:Show();
111 frame.major[majorPos].text:Show();
113 frame.major[majorPos].stack:SetText(count);
114 frame.major[majorPos].stack:Show();
117 majorPos = majorPos + 1;
122 if showInds or showMajors then
125 if needUpdate and not updating[frame] then
126 updating[frame] = true; -- race?
127 -- create a function for updating the indicator
128 local func = updaters[frame];
130 func = function() updateIndicators(frame, unit) end;
131 updaters[frame] = func;
133 CTimerAfter(0.16, func);