Quantcast
WoWInterface: SVN - Critline - Blame - Rev 26 - /trunk/AuraTracker.lua

WoWInterface SVN Critline

[/] [trunk/] [AuraTracker.lua] - Blame information for rev 26

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 25 Lombra-42051
local addonName, addon = ...
2 Lombra-42051
 
3 Lombra-42051
local L = LibStub("AceLocale-3.0"):GetLocale(addonName)
4 Lombra-42051
local templates = addon.templates
5 Lombra-42051
 
6 Lombra-42051
local band = bit.band
7 Lombra-42051
local CombatLog_Object_IsA = CombatLog_Object_IsA
8 Lombra-42051
local IsSpellKnown = IsSpellKnown
9 Lombra-42051
local UnitAura = UnitAura
10 Lombra-42051
local UnitName = UnitName
11 Lombra-42051
local UnitGUID = UnitGUID
12 Lombra-42051
local IsInInstance = IsInInstance
13 Lombra-42051
 
14 Lombra-42051
local COMBATLOG_FILTER_ME = COMBATLOG_FILTER_ME
15 Lombra-42051
local COMBATLOG_OBJECT_REACTION_FRIENDLY = COMBATLOG_OBJECT_REACTION_FRIENDLY
16 Lombra-42051
 
17 Lombra-42051
local playerAuras = {
18 Lombra-42051
        session = {},
19 Lombra-42051
        instance = {},
20 Lombra-42051
        lastFight = {},
21 Lombra-42051
}
22 Lombra-42051
local enemyAuras = {
23 Lombra-42051
        session = {},
24 Lombra-42051
        instance = {},
25 Lombra-42051
        lastFight = {},
26 Lombra-42051
}
27 Lombra-42051
 
28 Lombra-42051
-- name of current instance
29 Lombra-42051
local currentInstance = L["n/a"]
30 Lombra-42051
 
31 Lombra-42051
 
32 Lombra-42051
local auraTracker = CreateFrame("Frame", nil, UIParent)
33 Lombra-42051
auraTracker:SetFrameStrata("DIALOG")
34 Lombra-42051
auraTracker:EnableMouse(true)
35 Lombra-42051
auraTracker:SetSize(320, 360)
36 Lombra-42051
auraTracker:SetPoint("CENTER")
37 Lombra-42051
 
38 Lombra-42051
auraTracker:RegisterEvent("COMBAT_LOG_EVENT_UNFILTERED")
39 Lombra-42051
auraTracker:RegisterEvent("PLAYER_LOGIN")
40 Lombra-42051
auraTracker:RegisterEvent("UNIT_NAME_UPDATE")
41 Lombra-42051
auraTracker:RegisterEvent("PLAYER_REGEN_DISABLED")
42 Lombra-42051
auraTracker:RegisterEvent("PLAYER_ENTERING_WORLD")
43 Lombra-42051
auraTracker:SetScript("OnEvent", function(self, event, ...)
44 Lombra-42051
        self[event](self, ...)
45 Lombra-42051
end)
46 Lombra-42051
 
47 Lombra-42051
auraTracker:SetBackdrop({
48 Lombra-42051
        bgFile = [[Interface\ChatFrame\ChatFrameBackground]],
49 Lombra-42051
        edgeFile = [[Interface\Tooltips\UI-Tooltip-Border]],
50 Lombra-42051
        edgeSize = 16,
51 Lombra-42051
        insets = {left = 4, right = 4, top = 4, bottom = 4},
52 Lombra-42051
})
53 Lombra-42051
auraTracker:SetBackdropColor(0, 0, 0)
54 Lombra-42051
auraTracker:SetBackdropBorderColor(0.5, 0.5, 0.5)
55 Lombra-42051
auraTracker:Hide()
56 Lombra-42051
 
57 Lombra-42051
local closeButton = CreateFrame("Button", nil, auraTracker, "UIPanelCloseButton")
58 Lombra-42051
closeButton:SetPoint("TOPRIGHT")
59 Lombra-42051
 
60 Lombra-42051
addon.SlashCmdHandlers["aura"] = function() auraTracker:Show() end
61 Lombra-42051
 
62 Lombra-42051
local currentFilter = playerAuras.session
63 Lombra-42051
 
64 Lombra-42051
local function auraSort(a, b)
65 Lombra-42051
        return currentFilter[a].spellName < currentFilter[b].spellName
66 Lombra-42051
end
67 Lombra-42051
 
68 Lombra-42051
local function sourceSort(a, b)
69 Lombra-42051
        a, b = currentFilter[a], currentFilter[b]
70 Lombra-42051
        if a.source == b.source then
71 Lombra-42051
                return a.spellName < b.spellName
72 Lombra-42051
        else
73 Lombra-42051
                return a.source < b.source
74 Lombra-42051
        end
75 Lombra-42051
end
76 Lombra-42051
 
77 Lombra-42051
local filters = {
78 Lombra-42051
        BUFF = true,
79 Lombra-42051
        DEBUFF = true,
80 Lombra-42051
        targetAffiliation = playerAuras,
81 Lombra-42051
        sourceType = "npc",
82 Lombra-42051
        sort = auraSort,
83 Lombra-42051
}
84 Lombra-42051
 
85 Lombra-42051
local function onClick(self, text)
86 Lombra-42051
        self.owner:SetSelectedValue(self.value)
87 Lombra-42051
        self.owner:SetText(text)
88 Lombra-42051
        currentFilter = filters.targetAffiliation[self.value]
89 Lombra-42051
        CritlineAuraTrackerScrollFrame:Update()
90 Lombra-42051
end
91 Lombra-42051
 
92 Lombra-42051
local menuList = {
93 Lombra-42051
        {
94 Lombra-42051
                text = L["Current fight"],
95 Lombra-42051
                value = "lastFight",
96 Lombra-42051
        },
97 Lombra-42051
        {
98 Lombra-42051
                text = L["Current instance (%s)"],
99 Lombra-42051
                value = "instance",
100 Lombra-42051
        },
101 Lombra-42051
        {
102 Lombra-42051
                text = L["Current session"],
103 Lombra-42051
                value = "session",
104 Lombra-42051
        },
105 Lombra-42051
}
106 Lombra-42051
 
107 Lombra-42051
local auraTrackerScope = templates:CreateDropDownMenu("CritlineAuraTrackerScope", auraTracker)
108 Lombra-42051
auraTrackerScope:SetPoint("TOP", 0, -16)
109 Lombra-42051
auraTrackerScope:SetFrameWidth(220)
110 Lombra-42051
auraTrackerScope:JustifyText("LEFT")
111 Lombra-42051
auraTrackerScope:SetSelectedValue("session")
112 Lombra-42051
auraTrackerScope:SetText(L["Current session"])
113 Lombra-42051
auraTrackerScope.initialize = function(self)
114 Lombra-42051
        for i, v in ipairs(menuList) do
115 Lombra-42051
                local info = UIDropDownMenu_CreateInfo()
116 Lombra-42051
                info.text = format(v.text, currentInstance)
117 Lombra-42051
                info.value = v.value
118 Lombra-42051
                info.func = onClick
119 Lombra-42051
                info.owner = self
120 Lombra-42051
                info.arg1 = info.text
121 Lombra-42051
                UIDropDownMenu_AddButton(info)
122 Lombra-42051
        end
123 Lombra-42051
end
124 Lombra-42051
 
125 Lombra-42051
local auraTrackerAuraType = templates:CreateDropDownMenu("CritlineAuraTrackerAuraType", auraTracker)
126 Lombra-42051
auraTrackerAuraType:SetPoint("TOPLEFT", auraTrackerScope, "BOTTOMLEFT")
127 Lombra-42051
auraTrackerAuraType:SetFrameWidth(96)
128 Lombra-42051
auraTrackerAuraType:JustifyText("LEFT")
129 Lombra-42051
auraTrackerAuraType:SetText(L["Aura type"])
130 Lombra-42051
 
131 Lombra-42051
do
132 Lombra-42051
        local function onClick(self)
133 Lombra-42051
                filters[self.value] = self.checked
134 Lombra-42051
                CritlineAuraTrackerScrollFrame:Update()
135 Lombra-42051
        end
136 Lombra-42051
 
137 Lombra-42051
        local menuList = {
138 Lombra-42051
                {
139 Lombra-42051
                        text = L["Buffs"],
140 Lombra-42051
                        value = "BUFF",
141 Lombra-42051
                },
142 Lombra-42051
                {
143 Lombra-42051
                        text = L["Debuffs"],
144 Lombra-42051
                        value = "DEBUFF",
145 Lombra-42051
                },
146 Lombra-42051
        }
147 Lombra-42051
 
148 Lombra-42051
        auraTrackerAuraType.initialize = function(self)
149 Lombra-42051
                for i, v in ipairs(menuList) do
150 Lombra-42051
                        local info = UIDropDownMenu_CreateInfo()
151 Lombra-42051
                        info.text = v.text
152 Lombra-42051
                        info.value = v.value
153 Lombra-42051
                        info.func = onClick
154 Lombra-42051
                        info.checked = filters[v.value]
155 Lombra-42051
                        info.isNotRadio = true
156 Lombra-42051
                        info.keepShownOnClick = true
157 Lombra-42051
                        UIDropDownMenu_AddButton(info)
158 Lombra-42051
                end
159 Lombra-42051
        end
160 Lombra-42051
end
161 Lombra-42051
 
162 Lombra-42051
local filterOptions = templates:CreateDropDownMenu("CritlineAuraTrackerFilterOptions", auraTracker)
163 Lombra-42051
filterOptions:SetPoint("TOPRIGHT", auraTrackerScope, "BOTTOMRIGHT")
164 Lombra-42051
filterOptions:SetFrameWidth(96)
165 Lombra-42051
filterOptions:JustifyText("LEFT")
166 Lombra-42051
filterOptions:SetText(FILTERS)
167 Lombra-42051
 
168 Lombra-42051
do
169 Lombra-42051
        local function onClick(self, key)
170 Lombra-42051
                filters[key] = self.value
171 Lombra-42051
                self.owner:Refresh()
172 Lombra-42051
                self.owner:SetText(FILTERS)
173 Lombra-42051
                currentFilter = filters.targetAffiliation[auraTrackerScope:GetSelectedValue()]
174 Lombra-42051
                CritlineAuraTrackerScrollFrame:Update()
175 Lombra-42051
        end
176 Lombra-42051
 
177 Lombra-42051
        local function checked(self)
178 Lombra-42051
                return filters[self.arg1] == self.value
179 Lombra-42051
        end
180 Lombra-42051
 
181 Lombra-42051
        local menuList = {
182 Lombra-42051
                {
183 Lombra-42051
                        text = L["Show auras cast on me"],
184 Lombra-42051
                        value = playerAuras,
185 Lombra-42051
                        arg1 = "targetAffiliation",
186 Lombra-42051
                },
187 Lombra-42051
                {
188 Lombra-42051
                        text = L["Show auras cast on hostile NPCs"],
189 Lombra-42051
                        value = enemyAuras,
190 Lombra-42051
                        arg1 = "targetAffiliation",
191 Lombra-42051
                },
192 Lombra-42051
                {
193 Lombra-42051
                        text = L["Show auras cast by NPCs"],
194 Lombra-42051
                        value = "npc",
195 Lombra-42051
                        arg1 = "sourceType",
196 Lombra-42051
                },
197 Lombra-42051
                {
198 Lombra-42051
                        text = L["Show auras cast by players"],
199 Lombra-42051
                        value = "pvp",
200 Lombra-42051
                        arg1 = "sourceType",
201 Lombra-42051
                },
202 Lombra-42051
                {
203 Lombra-42051
                        text = L["Sort by aura name"],
204 Lombra-42051
                        value = auraSort,
205 Lombra-42051
                        arg1 = "sort",
206 Lombra-42051
                },
207 Lombra-42051
                {
208 Lombra-42051
                        text = L["Sort by source name"],
209 Lombra-42051
                        value = sourceSort,
210 Lombra-42051
                        arg1 = "sort",
211 Lombra-42051
                },
212 Lombra-42051
        }
213 Lombra-42051
 
214 Lombra-42051
        filterOptions.initialize = function(self)
215 Lombra-42051
                for i, v in ipairs(menuList) do
216 Lombra-42051
                        local info = UIDropDownMenu_CreateInfo()
217 Lombra-42051
                        info.text = v.text
218 Lombra-42051
                        info.value = v.value
219 Lombra-42051
                        info.func = onClick
220 Lombra-42051
                        info.checked = checked
221 Lombra-42051
                        info.owner = self
222 Lombra-42051
                        info.keepShownOnClick = true
223 Lombra-42051
                        info.arg1 = v.arg1
224 Lombra-42051
                        UIDropDownMenu_AddButton(info)
225 Lombra-42051
                end
226 Lombra-42051
        end
227 Lombra-42051
end
228 Lombra-42051
 
229 Lombra-42051
local search = templates:CreateEditBox(auraTracker)
230 Lombra-42051
search:SetPoint("TOPLEFT", auraTrackerAuraType, "BOTTOMLEFT", 18, -8)
231 Lombra-42051
search:SetPoint("TOPRIGHT", filterOptions, "BOTTOMRIGHT", -18, -8)
232 Lombra-42051
search:SetWidth(192)
233 Lombra-42051
search:SetScript("OnTextChanged", function() CritlineAuraTrackerScrollFrame:Update() end)
234 Lombra-42051
search:SetScript("OnEscapePressed", search.ClearFocus)
235 Lombra-42051
 
236 Lombra-42051
local label = search:CreateFontString(nil, nil, "GameFontNormalSmall")
237 Lombra-42051
label:SetPoint("BOTTOMLEFT", search, "TOPLEFT")
238 Lombra-42051
label:SetText(L["Text filter"])
239 Lombra-42051
 
240 Lombra-42051
local NUM_BUTTONS = 6
241 Lombra-42051
local BUTTON_HEIGHT = 36
242 Lombra-42051
 
243 Lombra-42051
local scrollFrame = CreateFrame("ScrollFrame", "CritlineAuraTrackerScrollFrame", auraTracker, "FauxScrollFrameTemplate")
244 Lombra-42051
scrollFrame:SetHeight(NUM_BUTTONS * BUTTON_HEIGHT)
245 Lombra-42051
scrollFrame:SetPoint("TOP", search, "BOTTOM", 0, -8)
246 Lombra-42051
scrollFrame:SetPoint("LEFT", 32, 0)
247 Lombra-42051
scrollFrame:SetPoint("RIGHT", -32, 0)
248 Lombra-42051
scrollFrame:SetScript("OnVerticalScroll", function(self, offset) FauxScrollFrame_OnVerticalScroll(self, offset, BUTTON_HEIGHT, self.Update) end)
249 Lombra-42051
 
250 Lombra-42051
local sortedAuras = {}
251 Lombra-42051
 
252 Lombra-42051
function scrollFrame:Update()
253 Lombra-42051
        if not auraTracker:IsShown() then
254 Lombra-42051
                self.doUpdate = true
255 Lombra-42051
                return
256 Lombra-42051
        end
257 Lombra-42051
 
258 Lombra-42051
        self.doUpdate = nil
259 Lombra-42051
 
260 Lombra-42051
        wipe(sortedAuras)
261 Lombra-42051
 
262 Lombra-42051
        local n = 0
263 Lombra-42051
        local search = search:GetText():lower()
264 Lombra-42051
        for spellID, v in pairs(currentFilter) do
265 Lombra-42051
                if filters[v.type] and (v.sourceType == filters.sourceType or not v.sourceType) and (v.spellName:lower():find(search, nil, true) or v.sourceName:lower():find(search, nil, true)) then
266 Lombra-42051
                        n = n + 1
267 Lombra-42051
                        sortedAuras[n] = spellID
268 Lombra-42051
                end
269 Lombra-42051
        end
270 Lombra-42051
 
271 Lombra-42051
        sort(sortedAuras, filters.sort)
272 Lombra-42051
 
273 Lombra-42051
        FauxScrollFrame_Update(self, n, NUM_BUTTONS, BUTTON_HEIGHT)
274 Lombra-42051
 
275 Lombra-42051
        local offset = FauxScrollFrame_GetOffset(self)
276 Lombra-42051
        local buttons = self.buttons
277 Lombra-42051
        for line = 1, NUM_BUTTONS do
278 Lombra-42051
                local button = buttons[line]
279 Lombra-42051
                local lineplusoffset = line + offset
280 Lombra-42051
                if lineplusoffset <= n then
281 Lombra-42051
                        local spellID = sortedAuras[lineplusoffset]
282 Lombra-42051
                        button:SetFormattedText("%s (%d)", currentFilter[spellID].spellName, spellID)
283 Lombra-42051
                        button.source:SetText(currentFilter[spellID].source)
284 Lombra-42051
                        button.icon:SetTexture(addon:GetSpellTexture(spellID))
285 Lombra-42051
                        button.spellID = spellID
286 Lombra-42051
                        -- local disabled = filters:IsFilteredAura(spellID)
287 Lombra-42051
                        -- button.icon:SetDesaturated(disabled)
288 Lombra-42051
                        -- button.text:SetFontObject(disabled and "GameFontDisable" or "GameFontNormal")
289 Lombra-42051
                        button:Show()
290 Lombra-42051
                else
291 Lombra-42051
                        button:Hide()
292 Lombra-42051
                end
293 Lombra-42051
        end
294 Lombra-42051
end
295 Lombra-42051
 
296 Lombra-42051
auraTracker:SetScript("OnShow", function(self)
297 Lombra-42051
        if scrollFrame.doUpdate then
298 Lombra-42051
                scrollFrame:Update()
299 Lombra-42051
        end
300 Lombra-42051
end)
301 Lombra-42051
 
302 Lombra-42051
local auraTrackerButtons = {}
303 Lombra-42051
scrollFrame.buttons = auraTrackerButtons
304 Lombra-42051
 
305 Lombra-42051
-- local function onClick(self)
306 Lombra-42051
        -- local disabled = filters:IsFilteredAura(self.spellID)
307 Lombra-42051
        -- if disabled then
308 Lombra-42051
                -- if specialAuras[self.spellID] then
309 Lombra-42051
                        -- addon:Message("Cannot delete integrated auras.")
310 Lombra-42051
                        -- return
311 Lombra-42051
                -- else
312 Lombra-42051
                        -- local t = filters.db.global.auras
313 Lombra-42051
                        -- for i = 1, #t do
314 Lombra-42051
                                -- if t[i] == self.spellID then
315 Lombra-42051
                                        -- tremove(t, i)
316 Lombra-42051
                                        -- addon:Message(format("Removed aura (%s) from filter.", GetSpellInfo(self.spellID)))
317 Lombra-42051
                                        -- break
318 Lombra-42051
                                -- end
319 Lombra-42051
                        -- end
320 Lombra-42051
                -- end
321 Lombra-42051
        -- else
322 Lombra-42051
                -- filters:AddAura(self.spellID)
323 Lombra-42051
        -- end
324 Lombra-42051
        -- disabled = not disabled
325 Lombra-42051
        -- self.icon:SetDesaturated(disabled)
326 Lombra-42051
        -- self.text:SetFontObject(disabled and "GameFontDisable" or "GameFontNormal")
327 Lombra-42051
-- end
328 Lombra-42051
 
329 Lombra-42051
local function onEnter(self)
330 Lombra-42051
        GameTooltip:SetOwner(self, "ANCHOR_LEFT")
331 Lombra-42051
        GameTooltip:SetSpellByID(self.spellID)
332 Lombra-42051
        GameTooltip:AddLine(" ")
333 Lombra-42051
        GameTooltip:AddLine(format(L["Spell ID: |cffffffff%d|r"], self.spellID))
334 Lombra-42051
        GameTooltip:Show()
335 Lombra-42051
end
336 Lombra-42051
 
337 Lombra-42051
for i = 1, NUM_BUTTONS do
338 Lombra-42051
        local btn = CreateFrame("Button", nil, auraTracker)
339 Lombra-42051
        btn:SetHeight(BUTTON_HEIGHT)
340 Lombra-42051
        if i == 1 then
341 Lombra-42051
                btn:SetPoint("TOP", scrollFrame)
342 Lombra-42051
        else
343 Lombra-42051
                btn:SetPoint("TOP", auraTrackerButtons[i - 1], "BOTTOM")
344 Lombra-42051
        end
345 Lombra-42051
        btn:SetPoint("LEFT", scrollFrame)
346 Lombra-42051
        btn:SetPoint("RIGHT", scrollFrame)
347 Lombra-42051
        btn:SetPushedTextOffset(0, 0)
348 Lombra-42051
        -- btn:SetScript("OnClick", onClick)
349 Lombra-42051
        btn:SetScript("OnEnter", onEnter)
350 Lombra-42051
        btn:SetScript("OnLeave", GameTooltip_Hide)
351 Lombra-42051
 
352 Lombra-42051
        if i % 2 == 0 then
353 Lombra-42051
                local bg = btn:CreateTexture(nil, "BACKGROUND")
354 Lombra-42051
                bg:SetAllPoints()
355 Lombra-42051
                bg:SetTexture(1, 1, 1, 0.1)
356 Lombra-42051
        end
357 Lombra-42051
 
358 Lombra-42051
        local icon = btn:CreateTexture()
359 Lombra-42051
        icon:SetSize(32, 32)
360 Lombra-42051
        icon:SetPoint("LEFT")
361 Lombra-42051
        btn.icon = icon
362 Lombra-42051
 
363 Lombra-42051
        local text = btn:CreateFontString(nil, nil, "GameFontNormal")
364 Lombra-42051
        text:SetPoint("TOPLEFT", icon, "TOPRIGHT", 4, -4)
365 Lombra-42051
        text:SetPoint("RIGHT")
366 Lombra-42051
        text:SetJustifyH("LEFT")
367 Lombra-42051
        btn:SetFontString(text)
368 Lombra-42051
        btn.text = text
369 Lombra-42051
 
370 Lombra-42051
        local source = btn:CreateFontString(nil, nil, "GameFontHighlightSmall")
371 Lombra-42051
        source:SetPoint("BOTTOMLEFT", icon, "BOTTOMRIGHT", 4, 4)
372 Lombra-42051
        source:SetPoint("RIGHT")
373 Lombra-42051
        source:SetJustifyH("LEFT")
374 Lombra-42051
        btn.source = source
375 Lombra-42051
 
376 Lombra-42051
        auraTrackerButtons[i] = btn
377 Lombra-42051
end
378 Lombra-42051
 
379 Lombra-42051
 
380 Lombra-42051
function auraTracker:COMBAT_LOG_EVENT_UNFILTERED(timestamp, eventType, hideCaster, sourceGUID, sourceName, sourceFlags, destGUID, destName, destFlags, spellID, spellName, spellSchool, auraType)
381 Lombra-42051
        if eventType == "SPELL_AURA_APPLIED" or eventType == "SPELL_AURA_REFRESH" then
382 Lombra-42051
                local auraTable
383 Lombra-42051
                if CombatLog_Object_IsA(destFlags, COMBATLOG_FILTER_ME) or addon:IsMyPet(destFlags, destGUID) then
384 Lombra-42051
                        -- register our own and our pet's auras
385 Lombra-42051
                        auraTable = playerAuras
386 26 Lombra-42051
                elseif not self:IsPvPTarget(destGUID) and band(destFlags, COMBATLOG_OBJECT_REACTION_FRIENDLY) == 0 then
387 25 Lombra-42051
                        -- and also those of non friendly NPCs
388 26 Lombra-42051
                        auraTable = enemyAuras
389 25 Lombra-42051
                end
390 Lombra-42051
 
391 Lombra-42051
                if auraTable then
392 Lombra-42051
                        self:RegisterAura(auraTable, sourceName, sourceGUID, spellID, spellName, auraType)
393 Lombra-42051
                end
394 Lombra-42051
        end
395 Lombra-42051
end
396 Lombra-42051
 
397 Lombra-42051
 
398 Lombra-42051
function auraTracker:PLAYER_LOGIN()
399 Lombra-42051
        self:ScanAuras()
400 Lombra-42051
end
401 Lombra-42051
 
402 Lombra-42051
 
403 Lombra-42051
function auraTracker:UNIT_NAME_UPDATE()
404 Lombra-42051
        self:ScanAuras()
405 Lombra-42051
        self:UnregisterEvent("UNIT_NAME_UPDATE")
406 Lombra-42051
end
407 Lombra-42051
 
408 Lombra-42051
 
409 Lombra-42051
-- reset current fight auras upon entering combat
410 Lombra-42051
function auraTracker:PLAYER_REGEN_DISABLED()
411 Lombra-42051
        wipe(playerAuras.lastFight)
412 Lombra-42051
        wipe(enemyAuras.lastFight)
413 Lombra-42051
        scrollFrame:Update()
414 Lombra-42051
end
415 Lombra-42051
 
416 Lombra-42051
 
417 Lombra-42051
function auraTracker:PLAYER_ENTERING_WORLD()
418 Lombra-42051
        -- wipe instance buff data when entering a new instance
419 Lombra-42051
        local instanceName = GetInstanceInfo()
420 Lombra-42051
        if IsInInstance() and instanceName ~= currentInstance then
421 Lombra-42051
                wipe(playerAuras.instance)
422 Lombra-42051
                wipe(enemyAuras.instance)
423 Lombra-42051
                currentInstance = instanceName
424 Lombra-42051
                if auraTrackerScope:GetSelectedValue() == "instance" then
425 Lombra-42051
                        auraTrackerScope:SetText(format(L["Current instance (%s)"], currentInstance))
426 Lombra-42051
                end
427 Lombra-42051
                scrollFrame:Update()
428 Lombra-42051
        end
429 Lombra-42051
end
430 Lombra-42051
 
431 Lombra-42051
 
432 Lombra-42051
local auraTypes = {
433 Lombra-42051
        BUFF = "HELPFUL",
434 Lombra-42051
        DEBUFF = "HARMFUL",
435 Lombra-42051
}
436 Lombra-42051
 
437 Lombra-42051
function auraTracker:ScanAuras()
438 Lombra-42051
        local auras = {}
439 Lombra-42051
        for auraType, filter in pairs(auraTypes) do
440 Lombra-42051
                for i = 1, 40 do
441 Lombra-42051
                        local spellName, _, _, _, _, _, _, source, _, _, spellID = UnitAura("player", i, filter)
442 Lombra-42051
                        if not spellID then break end
443 Lombra-42051
                        self:RegisterAura(playerAuras, source and UnitName(source), source and UnitGUID(source), spellID, spellName, auraType)
444 Lombra-42051
                end
445 Lombra-42051
        end
446 Lombra-42051
        scrollFrame:Update()
447 Lombra-42051
end
448 Lombra-42051
 
449 Lombra-42051
 
450 Lombra-42051
function auraTracker:RegisterAura(auraTable, sourceName, sourceGUID, spellID, spellName, auraType)
451 Lombra-42051
        local session = auraTable.session
452 Lombra-42051
        if session[spellID] or IsSpellKnown(spellID) then
453 Lombra-42051
                return
454 Lombra-42051
        end
455 Lombra-42051
 
456 Lombra-42051
        local source = L["n/a"]
457 Lombra-42051
        local sourceType
458 Lombra-42051
 
459 Lombra-42051
        if sourceGUID then
460 26 Lombra-42051
                if self:IsPvPTarget(sourceGUID) then
461 25 Lombra-42051
                        -- this is a player or a player's permanent pet
462 Lombra-42051
                        source = PVP
463 Lombra-42051
                        sourceType = "pvp"
464 Lombra-42051
                else
465 Lombra-42051
                        source = tonumber(sourceGUID:sub(7, 10), 16)
466 Lombra-42051
                        sourceType = "npc"
467 Lombra-42051
                end
468 Lombra-42051
        end
469 Lombra-42051
 
470 Lombra-42051
        local aura = {
471 Lombra-42051
                source = sourceName and format("%s (%s)", sourceName, source) or source,
472 Lombra-42051
                sourceName = sourceName or "",
473 Lombra-42051
                spellName = spellName,
474 Lombra-42051
                sourceType = sourceType,
475 Lombra-42051
                type = auraType,
476 Lombra-42051
        }
477 Lombra-42051
        auraTable.lastFight[spellID] = aura
478 Lombra-42051
        if IsInInstance() then
479 Lombra-42051
                auraTable.instance[spellID] = aura
480 Lombra-42051
        end
481 Lombra-42051
        session[spellID] = aura
482 Lombra-42051
        scrollFrame:Update()
483 26 Lombra-42051
end
484 Lombra-42051
 
485 Lombra-42051
 
486 Lombra-42051
function auraTracker:IsPvPTarget(guid)
487 Lombra-42051
        local unitType = band(guid:sub(1, 5), 0x007)
488 Lombra-42051
        return unitType == 0 or unitType == 4
489 25 Lombra-42051
end