local class = select(2, UnitClass("player"))
if class ~= "WARRIOR" and class ~= "DRUID" and class ~= "PALADIN" and class ~= "DEATHKNIGHT" and class ~= "MONK" then
return
end
local parent, ns = ...
local oUF = ns.oUF or oUF
if not oUF then return end
local _
local vengeance = (GetSpellInfo(84839))
local numFormat = function(v)
if v > 1E10 then
return (floor(v/1E9)).."b"
elseif v > 1E9 then
return (floor((v/1E9)*10)/10).."b"
elseif v > 1E7 then
return (floor(v/1E6)).."m"
elseif v > 1E6 then
return (floor((v/1E6)*10)/10).."m"
elseif v > 1E4 then
return (floor(v/1E3)).."k"
elseif v > 1E3 then
return (floor((v/1E3)*10)/10).."k"
else
return v
end
end
local Update = function(self, event, unit)
if(self.unit ~= unit) then return end
local element = self.Vengeance
local bar = self.VengeancePowerBar
if not bar:IsShown() then return end
local _, _, _, _, _, _, _, _, _, _, _, _, _, val1 = UnitBuff(unit, vengeance, nil)
local stat, _, posBuff, _ = UnitStat("player", 3)
local basehealth = UnitHealthMax("player")-(posBuff*UnitHPPerStamina("player"))
local max = basehealth/10 + stat
element:SetMinMaxValues(0, math.max(val1,max))
element:SetValue(val1)
if element.text then
if element.text.Override then
element.text:TextOverride(val1)
else
element.text:SetText(numFormat(val1))
end
end
end
local Visibility = function(self, event, unit)
local element = self.Vengeance
local bar = self.VengeancePowerBar
if UnitHasVehicleUI("player")
or ((HasVehicleActionBar() and UnitVehicleSkin("player") and UnitVehicleSkin("player") ~= "")
or (HasOverrideActionBar() and GetOverrideBarSkin() and GetOverrideBarSkin() ~= ""))
then
bar:Hide()
elseif(class == "WARRIOR" and GetSpecialization() == 2) then
bar:Show()
element.ForceUpdate(element)
elseif(class == "PALADIN" and GetSpecialization() == 1) then
bar:Show()
element.ForceUpdate(element)
elseif(class == "DEATHKNIGHT" and GetSpecialization() == 1) then
bar:Show()
element.ForceUpdate(element)
elseif(class == "DRUID" and GetSpecialization() == 1) then
bar:Show()
element.ForceUpdate(element)
elseif(class == "MONK" and GetSpecialization() == 1) then
bar:Show()
element.ForceUpdate(element)
else
bar:Hide()
end
end
local Path = function(self, ...)
return (self.Vengeance.Override or Update) (self, ...)
end
local ForceUpdate = function(element)
return Path(element.__owner, 'ForceUpdate', element.__owner.unit)
end
local Enable = function(self, unit)
local element = self.Vengeance
if(element and unit == "player") then
element.__owner = self
element.ForceUpdate = ForceUpdate
self:RegisterEvent('UNIT_ATTACK_POWER', Path, true)
self:RegisterEvent('PLAYER_TALENT_UPDATE', Visibility, true)
self:RegisterEvent("SPELLS_CHANGED", Visibility, true)
self:RegisterEvent("UPDATE_OVERRIDE_ACTIONBAR", Visibility, true)
local helper = CreateFrame("Frame") --this is needed...adding player_login to the visivility events doesn't do anything
helper:RegisterEvent("PLAYER_LOGIN")
helper:SetScript("OnEvent", function() Visibility(self) end)
return true
end
end
local Disable = function(self)
local element = self.Vengeance
if(element) then
self:UnregisterEvent('UNIT_ATTACK_POWER', Path)
self:UnregisterEvent('PLAYER_TALENT_UPDATE', Visibility)
self:UnregisterEvent('SPELLS_CHANGED', Visibility)
self:UnregisterEvent('UPDATE_OVERRIDE_ACTIONBAR', Visibility)
end
end
oUF:AddElement('Vengeance', Path, Enable, Disable)