Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 85 lines (67 sloc) 2.202 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
local _, ns = ...
local oUF = ns.oUF

local function Update(self, event, unit)
if(self.unit ~= unit) then return end

local hp = self.HealPrediction
if(hp.PreUpdate) then hp:PreUpdate(unit) end

local myIncomingHeal = UnitGetIncomingHeals(unit, 'player') or 0
local allIncomingHeal = UnitGetIncomingHeals(unit) or 0
local health, maxHealth = UnitHealth(unit), UnitHealthMax(unit)

if(health + allIncomingHeal > maxHealth * hp.maxOverflow) then
allIncomingHeal = maxHealth * hp.maxOverflow - health
end

if(allIncomingHeal < myIncomingHeal) then
myIncomingHeal = allIncomingHeal
allIncomingHeal = 0
else
allIncomingHeal = allIncomingHeal - myIncomingHeal
end

if(hp.myBar) then
hp.myBar:SetMinMaxValues(0, maxHealth)
hp.myBar:SetValue(myIncomingHeal)
hp.myBar:Show()
end

if(hp.otherBar) then
hp.otherBar:SetMinMaxValues(0, maxHealth)
hp.otherBar:SetValue(allIncomingHeal)
hp.otherBar:Show()
end

if(hp.PostUpdate) then
return hp:PostUpdate(unit)
end
end

local function Path(self, ...)
return (self.HealPrediction.Override or Update) (self, ...)
end

local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end

local function Enable(self)
local hp = self.HealPrediction
if(hp) then
hp.__owner = self
hp.ForceUpdate = ForceUpdate

self:RegisterEvent('UNIT_HEAL_PREDICTION', Path)
self:RegisterEvent('UNIT_MAXHEALTH', Path)
self:RegisterEvent('UNIT_HEALTH', Path)

if(not hp.maxOverflow) then
hp.maxOverflow = 1.05
end

if(hp.myBar and hp.myBar:IsObjectType'StatusBar' and not hp.myBar:GetStatusBarTexture()) then
hp.myBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end
if(hp.otherBar and hp.otherBar:IsObjectType'StatusBar' and not hp.otherBar:GetStatusBarTexture()) then
hp.otherBar:SetStatusBarTexture([[Interface\TargetingFrame\UI-StatusBar]])
end

return true
end
end

local function Disable(self)
local hp = self.HealPrediction
if(hp) then
self:UnregisterEvent('UNIT_HEAL_PREDICTION', Path)
self:UnregisterEvent('UNIT_MAXHEALTH', Path)
self:UnregisterEvent('UNIT_HEALTH', Path)
end
end

oUF:AddElement('HealPrediction', Path, Enable, Disable)
Something went wrong with that request. Please try again.