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 Frames = OmaFrames;
11 local positions = Frames.Positions;
13 local watchedAuras = {
15 [156910] = "TOPRIGHT",
16 [200025] = "TOPRIGHT",
17 [200654] = "BOTTOMLEFT",
20 ["Psychic Assault"] = true,
21 ["Everburning Flames"] = true,
23 ["Sleep Canister"] = true,
25 ["Necrotic Embrace"] = true,
26 ["Fulminating Pulse"] = true,
27 ["Chilled Blood"] = true,
28 ["Soulblight"] = true,
36 local auraFilters = {"HELPFUL", "HARMFUL"};
41 local function remaining(text, expires, current)
46 local remain = expires - current;
50 text:SetText(floor(remain+0.5));
55 local function updateIndicators(frame, unit)
56 if not frame:IsShown() or not UnitIsConnected(unit) or UnitIsDeadOrGhost(unit) then
57 updating[frame] = nil;
61 local needUpdate = false;
62 local current = GetTime();
63 for _, pos in pairs(positions) do
64 local ind = frame.inds[pos];
65 if ind.expires ~= nil then
66 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
70 local ind = frame.major[i];
71 if ind.expires ~= nil then
72 needUpdate = remaining(ind.text, ind.expires, current) or needUpdate;
76 CTimerAfter(0.16, updaters[frame]);
78 updating[frame] = nil;
82 function M.CheckIndicators(frame, unit)
83 for _, pos in pairs(positions) do
84 frame.inds[pos].expires = nil;
85 frame.inds[pos]:Hide();
86 frame.inds[pos].text:Hide();
89 frame.major[i].expires = nil;
90 frame.major[i]:Hide();
91 frame.major[i].text:Hide();
92 frame.major[i].stack:Hide();
94 local name, icon, count, expires, caster, id;
95 local showInds, showMajors, needUpdate = false, false, false;
97 local current = GetTime();
98 for _, filter in ipairs(auraFilters) do
101 name, _, icon, count, _, _, expires, caster, _, _, id = UnitAura(unit, i, filter);
102 if not id then break end
103 local pos = watchedAuras[id] or watchedAuras[name];
104 if pos and UnitIsPlayer(caster) then
105 needUpdate = remaining(frame.inds[pos].text, expires, current);
106 frame.inds[pos].expires = expires;
107 frame.inds[pos]:Show();
108 frame.inds[pos].text:Show();
111 if (majorAuras[id] or majorAuras[name]) and majorPos <= 3 then
112 needUpdate = remaining(frame.major[majorPos].text, expires, current);
113 frame.major[majorPos].expires = expires;
114 frame.major[majorPos]:SetTexture(icon);
115 frame.major[majorPos]:Show();
116 frame.major[majorPos].text:Show();
118 frame.major[majorPos].stack:SetText(count);
119 frame.major[majorPos].stack:Show();
122 majorPos = majorPos + 1;
127 if showInds or showMajors then
130 if needUpdate and not updating[frame] then
131 updating[frame] = true; -- race?
132 -- create a function for updating the indicator
133 local func = updaters[frame];
135 func = function() updateIndicators(frame, unit) end;
136 updaters[frame] = func;
138 CTimerAfter(0.16, func);