Quantcast

Add tracking for Savage Defense charges and cooldown

Adrian L Lange [09-10-12 - 05:50]
Add tracking for Savage Defense charges and cooldown
Filename
oUF_P3lim.lua
diff --git a/oUF_P3lim.lua b/oUF_P3lim.lua
index d21493a..b8f2ff4 100644
--- a/oUF_P3lim.lua
+++ b/oUF_P3lim.lua
@@ -18,6 +18,48 @@ local function SpawnMenu(self)
 	end
 end

+local function OnUpdateSavage(self, elapsed)
+	if(self.elapsed) then
+		self.elapsed = self.elapsed + elapsed
+
+		if(elapsed > 9) then
+			self.elapsed = nil
+			self:SetValue(9)
+		else
+			self:SetValue(self.elapsed)
+		end
+	end
+end
+
+local function UpdateSavage(self, event)
+	local Savage = self.Savage
+	if(event == 'SPELL_UPDATE_CHARGES') then
+		local charges, total, start = GetSpellCharges(62606)
+		if(charges ~= total) then
+			local elapsed
+
+			local next = Savage[charges + 1]
+			if(next) then
+				elapsed = next.elapsed
+				next.elapsed = nil
+				next:SetValue(0)
+			end
+
+			Savage[charges].elapsed = elapsed or start - GetTime()
+		end
+	else
+		local show = (event == 'PLAYER_REGEN_DISABLED' and GetSpecialization() == 3)
+		for index = 0, 2 do
+			local bar = Savage[index]
+			if(show) then
+				bar:Show()
+			else
+				bar:Hide()
+			end
+		end
+	end
+end
+
 local function PostUpdatePower(element, unit, min, max)
 	element:GetParent().Health:SetHeight(max ~= 0 and 20 or 22)
 end
@@ -122,6 +164,34 @@ local UnitSpecific = {
 			ExperienceBG:SetTexture(1/3, 1/3, 1/3)
 		end

+		if(select(3, UnitClass('player')) == 11) then
+			local Savage = {}
+			for index = 0, 2 do
+				local Bar = CreateFrame('StatusBar', nil, self.Health)
+				Bar:SetSize(8, 8)
+				Bar:SetBackdrop(BACKDROP)
+				Bar:SetBackdropColor(0, 0, 0)
+				Bar:SetStatusBarTexture(TEXTURE)
+				Bar:SetStatusBarColor(3/5, 1/5, 1/5)
+				Bar:SetOrientation('VERTICAL')
+				Bar:SetMinMaxValues(0, 9)
+				Bar:SetValue(9)
+				Bar:SetScript('OnUpdate', OnUpdateSavage)
+				Bar:Hide()
+
+				Savage[index] = Bar
+			end
+
+			self.Savage = Savage
+			Savage[1]:SetPoint('CENTER')
+			Savage[0]:SetPoint('LEFT', Savage[1], -20, 0)
+			Savage[2]:SetPoint('RIGHT', Savage[1], 20, 0)
+
+			self:RegisterEvent('SPELL_UPDATE_CHARGES', UpdateSavage)
+			self:RegisterEvent('PLAYER_REGEN_ENABLED', UpdateSavage)
+			self:RegisterEvent('PLAYER_REGEN_DISABLED', UpdateSavage)
+		end
+
 		self.Debuffs.size = 22
 		self.Debuffs:SetSize(230, 22)
 		self.Buffs.CustomFilter = FilterPlayerBuffs