PageRenderTime 182ms CodeModel.GetById 75ms app.highlight 4ms RepoModel.GetById 97ms app.codeStats 1ms

/Tukui/modules/unitframes/plugins/oUF_WeakenedSoul/oUF_WeakenedSoul.lua

http://github.com/Asphyxia/Tukui
Lua | 69 lines | 52 code | 17 blank | 0 comment | 10 complexity | b649eb1c3db92d24460d69e102c146d0 MD5 | raw file
 1local T, C, L = unpack(select(2, ...)) -- Import: T - functions, constants, variables; C - config; L - locales
 2if select(2, UnitClass('player')) ~= "PRIEST" then return end
 3
 4local _, ns = ...
 5local oUF = ns.oUF or oUF
 6assert(oUF, 'oUF_WeakenedSoul was unable to locate oUF install')
 7
 8local function GetDebuffInfo(unit)
 9	if not UnitCanAssist('player', unit) then return end
10
11	local i = 1
12	repeat
13		local _, _, _, _, _, _, _, _, _, _, spellId = UnitAura(unit, i, 'HARMFUL')
14
15		if spellId == 6788 then
16			return true
17		end
18
19		i = i + 1
20	until not spellId
21end
22
23local function UpdateBar(self, event, unit)
24	local duration = self.dur
25	local timeLeft = self.exp-GetTime()
26
27	self:SetValue((timeLeft * 100) / duration)
28end
29
30local function Update(self, event, unit)
31	if self.unit ~= unit then return end
32
33	local ws = self.WeakenedSoul
34
35	if ws.PreUpdate then ws:PreUpdate(unit) end
36
37	if GetDebuffInfo(unit) then
38		local _, _, _, _, _, duration, expirationTime = UnitDebuff(unit, GetSpellInfo(6788))
39		ws.dur = duration
40		ws.exp = expirationTime		
41		ws:Show()
42		ws:SetScript("OnUpdate", UpdateBar)
43	else
44		ws:Hide()
45		ws:SetScript("OnUpdate", nil)
46	end
47
48	if ws.PostUpdate then ws:PostUpdate(unit) end
49end
50
51local function Enable(self)
52	local ws = self.WeakenedSoul
53	if ws then
54		self:RegisterEvent("UNIT_AURA", Update)
55		ws:SetMinMaxValues(0, 100)
56		
57		ws.unit = self.unit
58
59		return true
60	end
61end
62
63local function Disable(self)
64	if self.WeakenedSoul then
65		self:UnregisterEvent('UNIT_AURA', Update)
66	end
67end
68
69oUF:AddElement('WeakenedSoul', Update, Enable, Disable)