2 local pairs, ipairs = pairs, ipairs;
3 local floor = math.floor;
4 local GetTime = GetTime;
5 local UnitAura = UnitAura;
6 local UnitIsDeadOrGhost, UnitIsConnected = UnitIsDeadOrGhost, UnitIsConnected;
7 local CTimerAfter = C_Timer.After;
9 local Frames = OmaFrames;
10 local positions = Frames.Positions;
12 local watchedAuras = {
14 [156910] = "TOPRIGHT",
15 [200025] = "TOPRIGHT",
16 [200654] = "BOTTOMLEFT",
19 ["Psychic Assault"] = true,
20 ["Everburning Flames"] = true,
22 ["Sleep Canister"] = true,
24 ["Necrotic Embrace"] = true,
25 ["Fulminating Pulse"] = true,
26 ["Chilled Blood"] = true,
27 ["Soulblight"] = true,
35 local auraFilters = {"HELPFUL", "HARMFUL"};
40 local function remaining(text, expires, current)
45 local remain = expires - current;
49 text:SetText(floor(remain+0.5));
54 local function updateIndicators(frame, unit)
55 if not frame:IsShown() or not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
56 updating[frame] = nil;
60 local needUpdate = false;
61 local current = GetTime();
62 for _, pos in pairs(positions) do
63 local ind = frame.inds[pos];
64 if ind.expires ~= nil then
65 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
69 local ind = frame.major[i];
70 if ind.expires ~= nil then
71 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
75 CTimerAfter(0.16, updaters[frame]);
77 updating[frame] = nil;
81 function M.CheckIndicators(frame, unit)
82 for _, pos in pairs(positions) do
83 frame.inds[pos].expires = nil;
84 frame.inds[pos]:Hide();
85 frame.inds[pos].text:Hide();
88 frame.major[i].expires = nil;
89 frame.major[i]:Hide();
90 frame.major[i].text:Hide();
91 frame.major[i].stack:Hide();
93 local name, icon, count, expires, caster, id;
94 local showInds, showMajors, needUpdate = false, false, false;
96 local current = GetTime();
97 for _, filter in ipairs(auraFilters) do
100 name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
101 if not id then break end
102 local pos = watchedAuras[id] or watchedAuras[name];
103 if pos and caster == "player" then
104 needUpdate = remaining(frame.inds[pos].text, expires, current);
105 frame.inds[pos].expires = expires;
106 frame.inds[pos]:Show();
107 frame.inds[pos].text:Show();
110 if (majorAuras[id] or majorAuras[name]) and majorPos <= 3 then
111 needUpdate = remaining(frame.major[majorPos].text, expires, current);
112 frame.major[majorPos].expires = expires;
113 frame.major[majorPos]:SetTexture(icon);
114 frame.major[majorPos]:Show();
115 frame.major[majorPos].text:Show();
117 frame.major[majorPos].stack:SetText(count);
118 frame.major[majorPos].stack:Show();
121 majorPos = majorPos + 1;
126 if showInds or showMajors then
129 if needUpdate and not updating[frame] then
130 updating[frame] = true; -- race?
131 -- create a function for updating the indicator
132 local func = updaters[frame];
134 func = function() updateIndicators(frame, unit) end;
135 updaters[frame] = func;
137 CTimerAfter(0.16, func);