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

http://github.com/Asphyxia/Tukui · Lua · 69 lines · 52 code · 17 blank · 0 comment · 13 complexity · b649eb1c3db92d24460d69e102c146d0 MD5 · raw file

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