/Tukui/modules/unitframes/core/oUF/elements/healprediction.lua

http://github.com/Asphyxia/Tukui · Lua · 84 lines · 70 code · 14 blank · 0 comment · 15 complexity · 5365934c049d6be6765fa28d8726ea13 MD5 · raw file

  1. local _, ns = ...
  2. local oUF = ns.oUF
  3. local function Update(self, event, unit)
  4. if(self.unit ~= unit) then return end
  5. local hp = self.HealPrediction
  6. if(hp.PreUpdate) then hp:PreUpdate(unit) end
  7. local myIncomingHeal = UnitGetIncomingHeals(unit, 'player') or 0
  8. local allIncomingHeal = UnitGetIncomingHeals(unit) or 0
  9. local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)
  10. if(health + allIncomingHeal > maxHealth * hp.maxOverflow) then
  11. allIncomingHeal = maxHealth * hp.maxOverflow - health
  12. end
  13. if(allIncomingHeal < myIncomingHeal) then
  14. myIncomingHeal = allIncomingHeal
  15. allIncomingHeal = 0
  16. else
  17. allIncomingHeal = allIncomingHeal - myIncomingHeal
  18. end
  19. if(hp.myBar) then
  20. hp.myBar:SetMinMaxValues(0, maxHealth)
  21. hp.myBar:SetValue(myIncomingHeal)
  22. hp.myBar:Show()
  23. end
  24. if(hp.otherBar) then
  25. hp.otherBar:SetMinMaxValues(0, maxHealth)
  26. hp.otherBar:SetValue(allIncomingHeal)
  27. hp.otherBar:Show()
  28. end
  29. if(hp.PostUpdate) then
  30. return hp:PostUpdate(unit)
  31. end
  32. end
  33. local function Path(self, ...)
  34. return (self.HealPrediction.Override or Update) (self, ...)
  35. end
  36. local ForceUpdate = function(element)
  37. return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
  38. end
  39. local function Enable(self)
  40. local hp = self.HealPrediction
  41. if(hp) then
  42. hp.__owner = self
  43. hp.ForceUpdate = ForceUpdate
  44. self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
  45. self:RegisterEvent('UNIT_MAXHEALTH', Path)
  46. self:RegisterEvent('UNIT_HEALTH', Path)
  47. if(not hp.maxOverflow) then
  48. hp.maxOverflow = 1.05
  49. end
  50. if(hp.myBar and not hp.myBar:GetStatusBarTexture()) then
  51. hp.myBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
  52. end
  53. if(hp.otherBar and not hp.otherBar:GetStatusBarTexture()) then
  54. hp.otherBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
  55. end
  56. return true
  57. end
  58. end
  59. local function Disable(self)
  60. local hp = self.HealPrediction
  61. if(hp) then
  62. self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
  63. self:UnregisterEvent('UNIT_MAXHEALTH', Path)
  64. self:UnregisterEvent('UNIT_HEALTH', Path)
  65. end
  66. end
  67. oUF:AddElement('HealPrediction', Path, Enable, Disable)